|
| 1 | +/** Use this to generate branded types. */ |
1 | 2 | type Brand<T, B extends string> = T & { readonly __brand: B } |
2 | 3 |
|
| 4 | +// --- |
| 5 | +// --- Coordinate types --- |
| 6 | +// --- |
| 7 | + |
| 8 | +/** A number that represents a relative coordinate within a pattern. */ |
3 | 9 | // ts-unused-exports:disable-next-line |
4 | 10 | export type RelativeNumber = Brand<number, 'RelativeNumber'> |
| 11 | + |
| 12 | +/** A number that represents an absolute coordinate in screen space. */ |
5 | 13 | // ts-unused-exports:disable-next-line |
6 | 14 | export type AbsoluteNumber = Brand<number, 'AbsoluteNumber'> |
| 15 | + |
| 16 | +/** A number that represents an absolute coordinate in viewport space. */ |
7 | 17 | export type ViewportNumber = Brand<number, 'ViewportNumber'> |
8 | 18 |
|
| 19 | +/** A number that represents a coordinate in a coordinate system. */ |
9 | 20 | export type PatternNumber = RelativeNumber | AbsoluteNumber | ViewportNumber |
10 | 21 |
|
11 | | -// Used as intermediate type when casting after doing calculations on coordinates. |
| 22 | +// --- |
| 23 | +// --- Point types --- |
| 24 | +// --- |
| 25 | + |
| 26 | +/** A pair of numbers. Typically used as an intermediate type when casting after doing calculations on coordinates. */ |
12 | 27 | export type NumberPair = [x: number, y: number] |
13 | 28 |
|
| 29 | +/** A coordinate pair. */ |
14 | 30 | export type Point<N extends PatternNumber> = [x: N, y: N] |
15 | 31 |
|
16 | | -// offset within pattern |
| 32 | +/** An offset within a pattern. */ |
17 | 33 | export type RelativePoint = Point<RelativeNumber> |
18 | 34 |
|
19 | | -// absolute point in screen space |
| 35 | +/** An absolute point in screen space. */ |
20 | 36 | export type AbsolutePoint = Point<AbsoluteNumber> |
21 | 37 |
|
22 | | -// absolute point in viewport space |
| 38 | +/** An absolute point in viewport space. */ |
23 | 39 | export type ViewportPoint = Point<ViewportNumber> |
24 | 40 |
|
25 | | -export type Size = [width: number, height: number] |
| 41 | +// --- |
| 42 | +// --- Pattern types --- |
| 43 | +// --- |
26 | 44 |
|
| 45 | +/** A pattern. Basically a rectangle, but it is defined with two points and can have a direction. */ |
27 | 46 | export type Pattern<N extends PatternNumber> = { |
28 | | - anchor: Point<N> // relative point representing base of new screen. |
29 | | - target: Point<N> // relative point representing other corner of new screen. can have negative coordinates. |
| 47 | + /** The anchor point of the pattern. If part of a {@link RelativePattern}, this is relative to the parent pattern. */ |
| 48 | + anchor: Point<N> |
| 49 | + /** The target point of the pattern. If part of a {@link RelativePattern}, this is relative to the parent pattern. */ |
| 50 | + target: Point<N> |
30 | 51 | } |
31 | 52 |
|
32 | | -// represents a pattern in relative coordinates. |
| 53 | +/** A pattern in relative coordinates. */ |
33 | 54 | export type RelativePattern = Pattern<RelativeNumber> |
34 | 55 |
|
35 | | -// represents a pattern in absolute coordinates. |
| 56 | +/** A pattern in absolute coordinates. */ |
36 | 57 | export type AbsolutePattern = Pattern<AbsoluteNumber> |
37 | 58 |
|
38 | | -// represents a pattern in viewport coordinates. |
| 59 | +/** A pattern in viewport coordinates. */ |
39 | 60 | export type ViewportPattern = Pattern<ViewportNumber> |
40 | 61 |
|
| 62 | +// --- |
| 63 | +// --- Size and boundaries types --- |
| 64 | +// --- |
| 65 | + |
| 66 | +/** A size, typically of the viewport in pixels. */ |
| 67 | +export type Size = [width: number, height: number] |
| 68 | + |
| 69 | +/** Defines a rectangle in a coordinate system. Unlike {@link Pattern}, this is only the boundary and does not define a direction. */ |
41 | 70 | export type Boundaries<N extends PatternNumber> = { |
42 | 71 | xMin: N |
43 | 72 | xMax: N |
44 | 73 | yMin: N |
45 | 74 | yMax: N |
46 | 75 | } |
47 | 76 |
|
| 77 | +// --- |
| 78 | +// --- State --- |
| 79 | +// --- |
| 80 | + |
| 81 | +/** This defines what is drawn on the screen. */ |
48 | 82 | export type State = { |
| 83 | + /** These are root-level patterns. */ |
49 | 84 | screens: AbsolutePattern[] |
| 85 | + |
| 86 | + /** These are nested patterns. They are applied recursively to root-level patterns.*/ |
50 | 87 | patterns: RelativePattern[] |
51 | 88 | } |
0 commit comments