vanilladocs
vanillapunch.com
API / base/transformmatrix

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

짝Counterpart: vanilla.js TransformMatrix소스source

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.
예제Example옮기고 키운 뒤 점 변환과 역변환Translate and scale, then transform a point and invert
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));
정적staticpub const fn identity() -> TransformMatrix#0.3.2 부터since 0.3.2소스source

단위 행렬.

Identity matrix.

반환ReturnsTransformMatrix a = d = 1, 나머지가 0 인 행렬.A matrix with a = d = 1 and the rest 0.

필드fieldpub a: f64#0.3.2 부터since 0.3.2소스source

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

필드fieldpub b: f64#0.3.2 부터since 0.3.2소스source

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

필드fieldpub c: f64#0.3.2 부터since 0.3.2소스source

y 축 벡터의 x.

x of the y axis vector.

반환Returnsf64

짝Counterpart: vanilla.js TransformMatrix.c

필드fieldpub d: f64#0.3.2 부터since 0.3.2소스source

y 축 벡터의 y.

y of the y axis vector.

반환Returnsf64

짝Counterpart: vanilla.js TransformMatrix.d

필드fieldpub e: f64#0.3.2 부터since 0.3.2소스source

이동 x.

Translation x.

반환Returnsf64

짝Counterpart: vanilla.js TransformMatrix.e

필드fieldpub f: f64#0.3.2 부터since 0.3.2소스source

이동 y.

Translation y.

반환Returnsf64

짝Counterpart: vanilla.js TransformMatrix.f

메서드methodpub fn set_identity(&mut self)#0.3.2 부터since 0.3.2소스source

단위 행렬로 초기화.

Resets to the identity matrix.

짝Counterpart: vanilla.js TransformMatrix.setIdentity

메서드methodpub fn set_transform(&mut self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64)#0.3.2 부터since 0.3.2소스source

값 직접 설정.

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

메서드methodpub fn copy_from(&mut self, other: &TransformMatrix)#0.4.0 부터since 0.4.0소스source

다른 행렬 값 복사.

Copies the values of another matrix.

other&TransformMatrix
복사해 올 행렬.Matrix to copy from.

짝Counterpart: vanilla.js TransformMatrix.copyFrom

메서드methodpub fn translate(&mut self, x: f64, y: f64)#0.3.2 부터since 0.3.2소스source

이동 누적. (오른쪽에 곱한다)

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

메서드methodpub fn rotate(&mut self, radian: f64)#0.3.2 부터since 0.3.2소스source

회전 누적. (라디안, 오른쪽에 곱한다)

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

예제Example90 도 돌리면 +X 가 +Y 로 간다Rotating 90 degrees moves +X to +Y
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);
메서드methodpub fn scale(&mut self, x: f64, y: f64)#0.3.2 부터since 0.3.2소스source

크기 누적. (오른쪽에 곱한다)

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

메서드methodpub fn multiply(&self, other: &TransformMatrix) -> TransformMatrix#0.3.2 부터since 0.3.2소스source

행렬 곱. (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

예제Example부모 변환에 자식 변환 곱하기Multiply a child transform onto a parent transform
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));
메서드methodpub fn invert(&self) -> Option<TransformMatrix>#0.3.2 부터since 0.3.2소스source

역행렬. (행렬식이 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

예제Example한 축 배율이 0 이면 뒤집을 수 없다Cannot be inverted if one axis scale is 0
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());
메서드methodpub fn transform_point(&self, x: f64, y: f64) -> Vector2#0.3.2 부터since 0.3.2소스source

점 변환.

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

메서드methodpub fn get_maximum_scale(&self) -> f64#0.3.2 부터since 0.3.2소스source

두 축 가운데 큰 쪽의 크기 배율.

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

메서드methodpub fn write_to_float32_array(&self, array: &mut [f32; 9])#0.4.0 부터since 0.4.0소스source

셰이더 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

예제Example이동 행렬을 mat3 배열로A translation matrix into a mat3 array
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]);