mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Prefer arrow functions (#2344)
This commit is contained in:
parent
e05acd6fd9
commit
a20f3240fd
19 changed files with 304 additions and 336 deletions
|
@ -15,48 +15,38 @@ import { Line, Point } from "./ga";
|
|||
*/
|
||||
|
||||
// Returns line with direction (x, y) through origin
|
||||
export function vector(x: number, y: number): Line {
|
||||
return GA.normalized([0, 0, -y, x, 0, 0, 0, 0]);
|
||||
}
|
||||
export const vector = (x: number, y: number): Line =>
|
||||
GA.normalized([0, 0, -y, x, 0, 0, 0, 0]);
|
||||
|
||||
// For equation ax + by + c = 0.
|
||||
export function equation(a: number, b: number, c: number): Line {
|
||||
return GA.normalized([0, c, a, b, 0, 0, 0, 0]);
|
||||
}
|
||||
export const equation = (a: number, b: number, c: number): Line =>
|
||||
GA.normalized([0, c, a, b, 0, 0, 0, 0]);
|
||||
|
||||
export function through(from: Point, to: Point): Line {
|
||||
return GA.normalized(GA.join(to, from));
|
||||
}
|
||||
export const through = (from: Point, to: Point): Line =>
|
||||
GA.normalized(GA.join(to, from));
|
||||
|
||||
export function orthogonal(line: Line, point: Point): Line {
|
||||
return GA.dot(line, point);
|
||||
}
|
||||
export const orthogonal = (line: Line, point: Point): Line =>
|
||||
GA.dot(line, point);
|
||||
|
||||
// Returns a line perpendicular to the line through `against` and `intersection`
|
||||
// going through `intersection`.
|
||||
export function orthogonalThrough(against: Point, intersection: Point): Line {
|
||||
return orthogonal(through(against, intersection), intersection);
|
||||
}
|
||||
export const orthogonalThrough = (against: Point, intersection: Point): Line =>
|
||||
orthogonal(through(against, intersection), intersection);
|
||||
|
||||
export function parallel(line: Line, distance: number): Line {
|
||||
export const parallel = (line: Line, distance: number): Line => {
|
||||
const result = line.slice();
|
||||
result[1] -= distance;
|
||||
return (result as unknown) as Line;
|
||||
}
|
||||
};
|
||||
|
||||
export function parallelThrough(line: Line, point: Point): Line {
|
||||
return orthogonal(orthogonal(point, line), point);
|
||||
}
|
||||
export const parallelThrough = (line: Line, point: Point): Line =>
|
||||
orthogonal(orthogonal(point, line), point);
|
||||
|
||||
export function distance(line1: Line, line2: Line): number {
|
||||
return GA.inorm(GA.meet(line1, line2));
|
||||
}
|
||||
export const distance = (line1: Line, line2: Line): number =>
|
||||
GA.inorm(GA.meet(line1, line2));
|
||||
|
||||
export function angle(line1: Line, line2: Line): number {
|
||||
return Math.acos(GA.dot(line1, line2)[0]);
|
||||
}
|
||||
export const angle = (line1: Line, line2: Line): number =>
|
||||
Math.acos(GA.dot(line1, line2)[0]);
|
||||
|
||||
// The orientation of the line
|
||||
export function sign(line: Line): number {
|
||||
return Math.sign(line[1]);
|
||||
}
|
||||
export const sign = (line: Line): number => Math.sign(line[1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue