base/transformmatrix
2D 아핀 변환 행렬. (Canvas2D 의 a, b, c, d, e, f 와 같은 배치) | a c e | | b d f | | 0 0 1 |
- 원본 base/transformmatrix.js. 원본의 a ~ f 읽기 프로퍼티는 공개 필드로, clone 은 복사(Copy)로 갈음한다.
- invert 와 identity 는 러스트 판에서 먼저 만들었다.
2D affine transform matrix. (the same layout as Canvas2D's a, b, c, d, e, f) | a c e | | b d f | | 0 0 1 |
- The original base/transformmatrix.js. The original's a ~ f read properties are public fields, and clone is replaced by copying (Copy).
- invert and identity were made first in the Rust version.
TransformMatrixstruct traits Clone, Copy, Debug, PartialEq, Default
2D 아핀 변환 행렬. (a ~ f 를 공개 필드로 둔 Copy 값, 기본값은 단위 행렬)
- translate, rotate, scale 은 자신을 바꾸고 오른쪽에 곱한다. multiply 는 새 행렬을 돌려준다.
2D affine transform matrix. (a Copy value with a ~ f as public fields, defaults to the identity matrix)
- translate, rotate and scale change the matrix itself and multiply on the right. multiply returns a new matrix.
use vanilla::{TransformMatrix, Vector2};
let mut transform = TransformMatrix::identity();
transform.translate(100.0, 50.0);
transform.scale(2.0, 2.0);
let point = transform.transform_point(10.0, 5.0);
assert_eq!(point, Vector2::create(120.0, 60.0));
let inverse = transform.invert().unwrap();
assert_eq!(inverse.transform_point(120.0, 60.0), Vector2::create(10.0, 5.0));단위 행렬.
Identity matrix.
반환ReturnsTransformMatrix a = d = 1, 나머지가 0 인 행렬.A matrix with a = d = 1 and the rest 0.
x 축 벡터의 x. (새 x = a * x + c * y + e)
x of the x axis vector. (new x = a * x + c * y + e)
반환Returnsf64
짝Counterpart: vanilla.js TransformMatrix.a
x 축 벡터의 y. (새 y = b * x + d * y + f)
y of the x axis vector. (new y = b * x + d * y + f)
반환Returnsf64
짝Counterpart: vanilla.js TransformMatrix.b
단위 행렬로 초기화.
Resets to the identity matrix.
짝Counterpart: vanilla.js TransformMatrix.setIdentity
값 직접 설정.
Sets the values directly.
- af64
- x 축 벡터의 x.x of the x axis vector.
- bf64
- x 축 벡터의 y.y of the x axis vector.
- cf64
- y 축 벡터의 x.x of the y axis vector.
- df64
- y 축 벡터의 y.y of the y axis vector.
- ef64
- 이동 x.Translation x.
- ff64
- 이동 y.Translation y.
짝Counterpart: vanilla.js TransformMatrix.setTransform
다른 행렬 값 복사.
Copies the values of another matrix.
- other&TransformMatrix
- 복사해 올 행렬.Matrix to copy from.
짝Counterpart: vanilla.js TransformMatrix.copyFrom
이동 누적. (오른쪽에 곱한다)
Accumulates a translation. (multiplies on the right)
- xf64
- x 이동량. (지금 변환의 로컬 좌표)x translation. (in the current transform's local coordinates)
- yf64
- y 이동량. (지금 변환의 로컬 좌표)y translation. (in the current transform's local coordinates)
짝Counterpart: vanilla.js TransformMatrix.translate
회전 누적. (라디안, 오른쪽에 곱한다)
Accumulates a rotation. (radians, multiplies on the right)
- radianf64
- 회전 각. (라디안, 양수면 +X 를 +Y 쪽으로 돌린다, 0 이면 아무것도 하지 않는다)Rotation angle. (radians, positive turns +X toward +Y, does nothing if 0)
짝Counterpart: vanilla.js TransformMatrix.rotate
use vanilla::{math, TransformMatrix};
let mut transform = TransformMatrix::identity();
transform.rotate(math::PI * 0.5);
let point = transform.transform_point(1.0, 0.0);
assert!(point.x.abs() < 1e-6);
assert!((point.y - 1.0).abs() < 1e-6);크기 누적. (오른쪽에 곱한다)
Accumulates a scale. (multiplies on the right)
- xf64
- x 배율. (1 이면 그대로)x scale. (1 leaves it unchanged)
- yf64
- y 배율. (1 이면 그대로)y scale. (1 leaves it unchanged)
짝Counterpart: vanilla.js TransformMatrix.scale
행렬 곱. (self * other)
Matrix product. (self * other)
- other&TransformMatrix
- 오른쪽에 곱할 행렬. (점에는 other 가 먼저 걸린다)Matrix to multiply on the right. (other applies to points first)
반환ReturnsTransformMatrix self x other 인 새 행렬. (자신은 바뀌지 않는다)A new matrix equal to self x other. (self is not changed)
짝Counterpart: vanilla.js TransformMatrix.multiply
use vanilla::{TransformMatrix, Vector2};
let mut parent = TransformMatrix::identity();
parent.translate(100.0, 0.0);
let mut child = TransformMatrix::identity();
child.scale(2.0, 2.0);
let world = parent.multiply(&child);
assert_eq!(world.transform_point(10.0, 10.0), Vector2::create(120.0, 20.0));역행렬. (행렬식이 0 이면 None)
Inverse matrix. (None if the determinant is 0)
반환ReturnsOption<TransformMatrix> 역행렬. 행렬식(a * d - b * c)이 0 이면 None.The inverse matrix. None if the determinant (a * d - b * c) is 0.
짝Counterpart: vanilla.js TransformMatrix.invert
use vanilla::TransformMatrix;
let mut flat = TransformMatrix::identity();
flat.scale(0.0, 1.0);
assert!(flat.invert().is_none());
assert!(TransformMatrix::identity().invert().is_some());점 변환.
Transforms a point.
- xf64
- 점의 x.x of the point.
- yf64
- 점의 y.y of the point.
반환ReturnsVector2 변환한 점. (a * x + c * y + e, b * x + d * y + f)The transformed point. (a * x + c * y + e, b * x + d * y + f)
짝Counterpart: vanilla.js TransformMatrix.transformPoint
두 축 가운데 큰 쪽의 크기 배율.
Scale factor of the larger of the two axes.
반환Returnsf64 x 축 벡터(a, b)와 y 축 벡터(c, d)의 길이 가운데 큰 값.The larger of the lengths of the x axis vector (a, b) and the y axis vector (c, d).
짝Counterpart: vanilla.js TransformMatrix.getMaximumScale
셰이더 mat3 (열 우선) 배열로 기록. (원본 writeToFloat32Array)
Writes to a shader mat3 (column-major) array. (the original writeToFloat32Array)
- array&mut [f32; 9]
- 옮겨 쓸 배열. (열 우선 9 개: a, b, 0, c, d, 0, e, f, 1)Array to copy into. (9 column-major values: a, b, 0, c, d, 0, e, f, 1)
짝Counterpart: vanilla.js TransformMatrix.writeToFloat32Array
use vanilla::TransformMatrix;
let mut transform = TransformMatrix::identity();
transform.translate(3.0, 4.0);
let mut array = [0.0f32; 9];
transform.write_to_float32_array(&mut array);
assert_eq!(array, [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 3.0, 4.0, 1.0]);