mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
chore: Unify math types, utils and functions (#8389)
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
parent
e3d1dee9d0
commit
f4dd23fc31
98 changed files with 4291 additions and 3661 deletions
41
packages/math/ga/gatransforms.ts
Normal file
41
packages/math/ga/gatransforms.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import * as GA from "./ga";
|
||||
import type { Line, Direction, Point, Transform } from "./ga";
|
||||
import * as GADirection from "./gadirections";
|
||||
|
||||
/**
|
||||
* TODO: docs
|
||||
*/
|
||||
|
||||
export const rotation = (pivot: Point, angle: number): Transform =>
|
||||
GA.add(GA.mul(pivot, Math.sin(angle / 2)), Math.cos(angle / 2));
|
||||
|
||||
export const translation = (direction: Direction): Transform => [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-(0.5 * direction[5]),
|
||||
0.5 * direction[4],
|
||||
0,
|
||||
0,
|
||||
];
|
||||
|
||||
export const translationOrthogonal = (
|
||||
direction: Direction,
|
||||
distance: number,
|
||||
): Transform => {
|
||||
const scale = 0.5 * distance;
|
||||
return [1, 0, 0, 0, scale * direction[4], scale * direction[5], 0, 0];
|
||||
};
|
||||
|
||||
export const translationAlong = (line: Line, distance: number): Transform =>
|
||||
GA.add(GA.mul(GADirection.orthogonalToLine(line), 0.5 * distance), 1);
|
||||
|
||||
export const compose = (motor1: Transform, motor2: Transform): Transform =>
|
||||
GA.mul(motor2, motor1);
|
||||
|
||||
export const apply = (
|
||||
motor: Transform,
|
||||
nvector: Point | Direction | Line,
|
||||
): Point | Direction | Line =>
|
||||
GA.normalized(GA.mul(GA.mul(motor, nvector), GA.reverse(motor)));
|
Loading…
Add table
Add a link
Reference in a new issue