Skip to content

Commit

Permalink
Clean up matrix primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
yzrmn committed Dec 17, 2023
1 parent fbaf0aa commit bfcf4d7
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions packages/redgeometry/src/primitives/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export enum MatrixType {
NonAffine,
}

export type Matrix3Next = Matrix3x2 | Matrix3x3;
export type Matrix4Next = Matrix4x3 | Matrix4x4;
export type Matrix3 = Matrix3x2 | Matrix3x3;
export type Matrix4 = Matrix4x3 | Matrix4x4;

/**
* Represents a matrix for affine transformations in 2D:
Expand Down Expand Up @@ -686,20 +686,6 @@ export class Matrix3x3 {
return new Matrix3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
}

public getMaxScale(): number {
const el = this.elements;

// Compute elements of `S^2 = M * M^T`
const s11 = el[0] * el[0] + el[1] * el[1];
const s12 = el[0] * el[3] + el[1] * el[4];
const s22 = el[3] * el[3] + el[4] * el[4];

// The eigenvalue of `S^2` is the squared eigenvalue of the singular values of `M`
const eig = getMaxEigenvalueSym2x2(s11, s12, s22);

return Math.sqrt(eig);
}

/**
* ```
* | m11 m12 m13 | | x |
Expand Down Expand Up @@ -1992,8 +1978,8 @@ export class Matrix4x4 {
this.elements = [m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44];
}

public get type(): MatrixType.Affine {
return MatrixType.Affine;
public get type(): MatrixType.NonAffine {
return MatrixType.NonAffine;
}

/**
Expand Down Expand Up @@ -2227,23 +2213,6 @@ export class Matrix4x4 {
);
}

public getMaxScale(): number {
const el = this.elements;

// Compute elements of `S^2 = M * M^T`
const s11 = el[0] * el[0] + el[1] * el[1] + el[2] * el[2];
const s12 = el[0] * el[4] + el[1] * el[5] + el[2] * el[6];
const s13 = el[0] * el[8] + el[1] * el[9] + el[2] * el[10];
const s22 = el[4] * el[4] + el[5] * el[5] + el[6] * el[6];
const s23 = el[4] * el[8] + el[5] * el[9] + el[6] * el[10];
const s33 = el[8] * el[8] + el[9] * el[9] + el[10] * el[10];

// The eigenvalue of `S^2` is the squared eigenvalue of the singular values of `M`
const eig = getMaxEigenvalueSym3x3(s11, s12, s13, s22, s23, s33);

return Math.sqrt(eig);
}

/**
* ```
* | m11 m12 m13 m14 | | x |
Expand Down

0 comments on commit bfcf4d7

Please sign in to comment.