27 lines
821 B
TypeScript
27 lines
821 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { closestOnSegment, dot } from '../../src/core/util/vec';
|
|
|
|
describe('closestOnSegment', () => {
|
|
const a = { x: 0, y: 0 };
|
|
const b = { x: 10, y: 0 };
|
|
|
|
it('drops the point onto the segment', () => {
|
|
expect(closestOnSegment({ x: 4, y: 7 }, a, b)).toEqual({ x: 4, y: 0 });
|
|
});
|
|
|
|
it('stops at the ends instead of running along the line', () => {
|
|
expect(closestOnSegment({ x: -5, y: 3 }, a, b)).toEqual(a);
|
|
expect(closestOnSegment({ x: 25, y: 3 }, a, b)).toEqual(b);
|
|
});
|
|
|
|
it('takes a segment of no length as its one point', () => {
|
|
expect(closestOnSegment({ x: 3, y: 4 }, b, b)).toEqual(b);
|
|
});
|
|
});
|
|
|
|
describe('dot', () => {
|
|
it('is zero for perpendicular vectors', () => {
|
|
expect(dot({ x: 2, y: 3 }, { x: -3, y: 2 })).toBe(0);
|
|
});
|
|
});
|