mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Attempt at optimizing focus point calc
This commit is contained in:
parent
5cbd6e63a0
commit
34ec751501
3 changed files with 63 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
|||
import type { GenericPoint, Vector } from "./types";
|
||||
import type { GenericPoint, Radians, Vector } from "./types";
|
||||
|
||||
/**
|
||||
* Create a vector from the x and y coordiante elements.
|
||||
|
@ -139,3 +139,16 @@ export const vectorNormalize = (v: Vector): Vector => {
|
|||
|
||||
return vector(v[0] / m, v[1] / m);
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotate a vector by the given radians
|
||||
* @param v Target vector
|
||||
* @param a Angle to rotate in radians
|
||||
* @returns The rotated vector
|
||||
*/
|
||||
export const vectorRotate = (v: Vector, a: Radians): Vector => {
|
||||
const cos = Math.cos(a);
|
||||
const sin = Math.sin(a);
|
||||
|
||||
return vector(v[0] * cos - v[1] * sin, v[0] * sin + v[1] * cos);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue