Skip to content

Commit

Permalink
Fix parameter order and improve naming consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
yzrmn committed Dec 31, 2023
1 parent 69ba292 commit 75d7095
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions packages/redgeometry/src/core/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class Path2 implements PathSink2 {
let sin = Math.sin(startAngle);
let cos = Math.cos(startAngle);

const mat = Matrix3x2.fromRotation(sin, cos);
const mat = Matrix3x2.fromRotation(cos, sin);

mat.scalePre(rx, ry);
mat.translatePre(pc.x, pc.y);
Expand Down Expand Up @@ -572,7 +572,7 @@ export class Path2 implements PathSink2 {
let cos = Math.cos(xAxisRotation);

// Inverse rotation to align the ellipse
const mat = Matrix3x2.fromRotation(-sin, cos);
const mat = Matrix3x2.fromRotation(cos, -sin);

// Vector from center (transformed midpoint)
let v = p0.sub(p1).mul(0.5);
Expand Down Expand Up @@ -626,10 +626,10 @@ export class Path2 implements PathSink2 {
let v2 = pp1.sub(pc);

// Set up the final transformation matrix
mat.rotateSet(v1.y, v1.x);
mat.rotateSet(v1.x, v1.y);
mat.translatePre(pc.x, pc.y);
mat.scalePre(sx, sy);
mat.rotatePre(sin, cos);
mat.rotatePre(cos, sin);

// We have `sin = v1.cross(v2) / (v1.length * v2.length)`
// with the length of `v1` and `v2` both 1 (unit vectors)
Expand Down
6 changes: 3 additions & 3 deletions packages/redgeometry/src/primitives/quaternion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ export class Quaternion {
}
}

public static fromRotationXAngle(angle: number): Quaternion {
public static fromRotationAngleX(angle: number): Quaternion {
const sin = Math.sin(0.5 * angle);
const cos = Math.cos(0.5 * angle);
return new Quaternion(cos, sin, 0, 0);
}

public static fromRotationYAngle(angle: number): Quaternion {
public static fromRotationAngleY(angle: number): Quaternion {
const sin = Math.sin(0.5 * angle);
const cos = Math.cos(0.5 * angle);
return new Quaternion(cos, 0, sin, 0);
}

public static fromRotationZAngle(angle: number): Quaternion {
public static fromRotationAngleZ(angle: number): Quaternion {
const sin = Math.sin(0.5 * angle);
const cos = Math.cos(0.5 * angle);
return new Quaternion(cos, 0, 0, sin);
Expand Down
12 changes: 6 additions & 6 deletions packages/redgeometry/tests/primitives/matrix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test("Matrix4x3 - mapVector", () => {
});

test("Matrix4x3 - rotate (x)", () => {
const q = Quaternion.fromRotationXAngle(1);
const q = Quaternion.fromRotationAngleX(1);
const mat1 = Matrix4x3.fromRotation(q.a, q.b, q.c, q.d);
const mat2 = Matrix4x3.createIdentity();
const mat3 = Matrix4x3.createIdentity();
Expand All @@ -182,7 +182,7 @@ test("Matrix4x3 - rotate (x)", () => {
});

test("Matrix4x3 - rotate (y)", () => {
const q = Quaternion.fromRotationYAngle(1);
const q = Quaternion.fromRotationAngleY(1);
const mat1 = Matrix4x3.fromRotation(q.a, q.b, q.c, q.d);
const mat2 = Matrix4x3.createIdentity();
const mat3 = Matrix4x3.createIdentity();
Expand All @@ -198,7 +198,7 @@ test("Matrix4x3 - rotate (y)", () => {
});

test("Matrix4x3 - rotate (z)", () => {
const q = Quaternion.fromRotationZAngle(1);
const q = Quaternion.fromRotationAngleZ(1);
const mat1 = Matrix4x3.fromRotation(q.a, q.b, q.c, q.d);
const mat2 = Matrix4x3.createIdentity();
const mat3 = Matrix4x3.createIdentity();
Expand Down Expand Up @@ -262,7 +262,7 @@ test("Matrix4x4 - mapVector", () => {
});

test("Matrix4x4 - rotate (x)", () => {
const q = Quaternion.fromRotationXAngle(1);
const q = Quaternion.fromRotationAngleX(1);
const mat1 = Matrix4x4.fromRotation(q.a, q.b, q.c, q.d);
const mat2 = Matrix4x4.createIdentity();
const mat3 = Matrix4x4.createIdentity();
Expand All @@ -278,7 +278,7 @@ test("Matrix4x4 - rotate (x)", () => {
});

test("Matrix4x4 - rotate (y)", () => {
const q = Quaternion.fromRotationYAngle(1);
const q = Quaternion.fromRotationAngleY(1);
const mat1 = Matrix4x4.fromRotation(q.a, q.b, q.c, q.d);
const mat2 = Matrix4x4.createIdentity();
const mat3 = Matrix4x4.createIdentity();
Expand All @@ -294,7 +294,7 @@ test("Matrix4x4 - rotate (y)", () => {
});

test("Matrix4x4 - rotate (z)", () => {
const q = Quaternion.fromRotationZAngle(1);
const q = Quaternion.fromRotationAngleZ(1);
const mat1 = Matrix4x4.fromRotation(q.a, q.b, q.c, q.d);
const mat2 = Matrix4x4.createIdentity();
const mat3 = Matrix4x4.createIdentity();
Expand Down
18 changes: 9 additions & 9 deletions packages/redgeometry/tests/primitives/quaternion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from "vitest";
import { Quaternion, RotationOrder } from "../../src/primitives/quaternion.js";

test("Quaternion - fromXAngle", () => {
const q = Quaternion.fromRotationXAngle(1);
const q = Quaternion.fromRotationAngleX(1);

const q1 = Quaternion.fromRotationEuler(1, 0, 0, RotationOrder.XYZ);
const q2 = Quaternion.fromRotationEuler(1, 0, 0, RotationOrder.XZY);
Expand All @@ -20,7 +20,7 @@ test("Quaternion - fromXAngle", () => {
});

test("Quaternion - fromYAngle", () => {
const q = Quaternion.fromRotationYAngle(1);
const q = Quaternion.fromRotationAngleY(1);

const q1 = Quaternion.fromRotationEuler(0, 1, 0, RotationOrder.XYZ);
const q2 = Quaternion.fromRotationEuler(0, 1, 0, RotationOrder.XZY);
Expand All @@ -39,7 +39,7 @@ test("Quaternion - fromYAngle", () => {
});

test("Quaternion - fromZAngle", () => {
const q = Quaternion.fromRotationZAngle(1);
const q = Quaternion.fromRotationAngleZ(1);

const q1 = Quaternion.fromRotationEuler(0, 0, 1, RotationOrder.XYZ);
const q2 = Quaternion.fromRotationEuler(0, 0, 1, RotationOrder.XZY);
Expand Down Expand Up @@ -68,12 +68,12 @@ test("Quaternion - fromEulerAngles", () => {
const qe1 = Quaternion.fromRotationEuler(ax, ay, az, RotationOrder.ZXY);
const qf1 = Quaternion.fromRotationEuler(ax, ay, az, RotationOrder.ZYX);

const qa2 = Quaternion.fromRotationXAngle(ax).rotateY(ay).rotateZ(az);
const qb2 = Quaternion.fromRotationXAngle(ax).rotateZ(az).rotateY(ay);
const qc2 = Quaternion.fromRotationYAngle(ay).rotateX(ax).rotateZ(az);
const qd2 = Quaternion.fromRotationYAngle(ay).rotateZ(az).rotateX(ax);
const qe2 = Quaternion.fromRotationZAngle(az).rotateX(ax).rotateY(ay);
const qf2 = Quaternion.fromRotationZAngle(az).rotateY(ay).rotateX(ax);
const qa2 = Quaternion.fromRotationAngleX(ax).rotateY(ay).rotateZ(az);
const qb2 = Quaternion.fromRotationAngleX(ax).rotateZ(az).rotateY(ay);
const qc2 = Quaternion.fromRotationAngleY(ay).rotateX(ax).rotateZ(az);
const qd2 = Quaternion.fromRotationAngleY(ay).rotateZ(az).rotateX(ax);
const qe2 = Quaternion.fromRotationAngleZ(az).rotateX(ax).rotateY(ay);
const qf2 = Quaternion.fromRotationAngleZ(az).rotateY(ay).rotateX(ax);

expectToBeCloseToQuaternion(qa1, qa2);
expectToBeCloseToQuaternion(qb1, qb2);
Expand Down

0 comments on commit 75d7095

Please sign in to comment.