time for a snapshot
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
export type Vec = { x: number; y: number };
|
||||
|
||||
/** Build a vector from two numbers. */
|
||||
export function vec(x: number, y: number): Vec {
|
||||
return { x, y };
|
||||
}
|
||||
|
||||
/** a + b (component-wise) */
|
||||
export function add(a: Vec, b: Vec): Vec {
|
||||
return {
|
||||
x: a.x + b.x,
|
||||
y: a.y + b.y,
|
||||
};
|
||||
}
|
||||
|
||||
/** a - b (component-wise) */
|
||||
export function sub(a: Vec, b: Vec): Vec {
|
||||
return {
|
||||
x: a.x - b.x,
|
||||
y: a.y - b.y,
|
||||
};
|
||||
}
|
||||
|
||||
/** a scaled by the scalar s */
|
||||
export function scale(a: Vec, s: number): Vec {
|
||||
return {
|
||||
x: a.x * s,
|
||||
y: a.y * s,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user