Skip to content

Commit 9e38fe4

Browse files
committed
Add comments to types.ts
1 parent b480595 commit 9e38fe4

1 file changed

Lines changed: 47 additions & 10 deletions

File tree

src/types.ts

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,88 @@
1+
/** Use this to generate branded types. */
12
type Brand<T, B extends string> = T & { readonly __brand: B }
23

4+
// ---
5+
// --- Coordinate types ---
6+
// ---
7+
8+
/** A number that represents a relative coordinate within a pattern. */
39
// ts-unused-exports:disable-next-line
410
export type RelativeNumber = Brand<number, 'RelativeNumber'>
11+
12+
/** A number that represents an absolute coordinate in screen space. */
513
// ts-unused-exports:disable-next-line
614
export type AbsoluteNumber = Brand<number, 'AbsoluteNumber'>
15+
16+
/** A number that represents an absolute coordinate in viewport space. */
717
export type ViewportNumber = Brand<number, 'ViewportNumber'>
818

19+
/** A number that represents a coordinate in a coordinate system. */
920
export type PatternNumber = RelativeNumber | AbsoluteNumber | ViewportNumber
1021

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. */
1227
export type NumberPair = [x: number, y: number]
1328

29+
/** A coordinate pair. */
1430
export type Point<N extends PatternNumber> = [x: N, y: N]
1531

16-
// offset within pattern
32+
/** An offset within a pattern. */
1733
export type RelativePoint = Point<RelativeNumber>
1834

19-
// absolute point in screen space
35+
/** An absolute point in screen space. */
2036
export type AbsolutePoint = Point<AbsoluteNumber>
2137

22-
// absolute point in viewport space
38+
/** An absolute point in viewport space. */
2339
export type ViewportPoint = Point<ViewportNumber>
2440

25-
export type Size = [width: number, height: number]
41+
// ---
42+
// --- Pattern types ---
43+
// ---
2644

45+
/** A pattern. Basically a rectangle, but it is defined with two points and can have a direction. */
2746
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>
3051
}
3152

32-
// represents a pattern in relative coordinates.
53+
/** A pattern in relative coordinates. */
3354
export type RelativePattern = Pattern<RelativeNumber>
3455

35-
// represents a pattern in absolute coordinates.
56+
/** A pattern in absolute coordinates. */
3657
export type AbsolutePattern = Pattern<AbsoluteNumber>
3758

38-
// represents a pattern in viewport coordinates.
59+
/** A pattern in viewport coordinates. */
3960
export type ViewportPattern = Pattern<ViewportNumber>
4061

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. */
4170
export type Boundaries<N extends PatternNumber> = {
4271
xMin: N
4372
xMax: N
4473
yMin: N
4574
yMax: N
4675
}
4776

77+
// ---
78+
// --- State ---
79+
// ---
80+
81+
/** This defines what is drawn on the screen. */
4882
export type State = {
83+
/** These are root-level patterns. */
4984
screens: AbsolutePattern[]
85+
86+
/** These are nested patterns. They are applied recursively to root-level patterns.*/
5087
patterns: RelativePattern[]
5188
}

0 commit comments

Comments
 (0)