-
Notifications
You must be signed in to change notification settings - Fork 6
/
Parameterized2DShape.ts
44 lines (35 loc) · 1.38 KB
/
Parameterized2DShape.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Point2, Vec2 } from '../Vec2';
import Abstract2DShape from './Abstract2DShape';
import LineSegment2 from './LineSegment2';
/**
* A 2-dimensional path with parameter interval $t \in [0, 1]$.
*
* **Note:** Avoid extending this class outside of `js-draw` --- new abstract methods
* may be added between minor versions.
*/
export abstract class Parameterized2DShape extends Abstract2DShape {
/** Returns this at a given parameter. $t \in [0, 1]$ */
abstract at(t: number): Point2;
/** Computes the unit normal vector at $t$. */
abstract normalAt(t: number): Vec2;
abstract tangentAt(t: number): Vec2;
/**
* Divides this shape into two separate shapes at parameter value $t$.
*/
abstract splitAt(t: number): [ Parameterized2DShape ] | [ Parameterized2DShape, Parameterized2DShape ];
/**
* Returns the nearest point on `this` to `point` and the `parameterValue` at which
* that point occurs.
*/
abstract nearestPointTo(point: Point2): { point: Point2, parameterValue: number };
/**
* Returns the **parameter values** at which `lineSegment` intersects this shape.
*
* See also {@link intersectsLineSegment}
*/
public abstract argIntersectsLineSegment(lineSegment: LineSegment2): number[];
public override intersectsLineSegment(line: LineSegment2): Point2[] {
return this.argIntersectsLineSegment(line).map(t => this.at(t));
}
}
export default Parameterized2DShape;