feat(types): IVec2 + Rect 2D value types (#1)
Phase 1 of the fuller type-system proposal: two by-value spatial types that lower to packed integers (no heap, copy like scalars). - IVec2 — integer 2D vector, a pair of int packed into one i64, for tile and grid coordinates: make/zero/x/y/add/sub/scale/dot, the grid distance manhattan, equal, and to_vector (widen into the fixed-point Vector). - Rect — axis-aligned rectangle, four Q16.16 fixed components packed into one i128, for HUD boxes and hitboxes: make/x/y/w/h, the derived right/bottom/center, and the contains (point) / intersects (overlap) tests. Both are exact and deterministic, bit-identical on every platform. Vector and Color already cover phase 1's other 2D primitives. Wired end to end: emit_core llty (IVec2->i64, Rect->i128), emit_call dispatch, the FRAGS list + reseeded seed, a selfhost test (types2d), per-symbol docs + type pages + inventory, and the vocabulary/editor sync (header, JetBrains, TextMate, LSP). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
3df6640fa5
commit
2c9f9ac549
40 changed files with 26731 additions and 24058 deletions
7
docs/language/rect/_section.md
Normal file
7
docs/language/rect/_section.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
id: rect
|
||||
title: Rect
|
||||
order: 9
|
||||
---
|
||||
|
||||
Axis-aligned rectangles for HUD layout boxes, hitboxes, and camera regions. A <code>Rect</code> is four Q16.16 <code>fixed</code> components — position <code>(x, y)</code> (its top-left corner) and size <code>(w, h)</code> — packed into a single value that is copied by value and never allocates. It offers fast point-in-rect and rectangle-overlap tests. Every operation is deterministic fixed-point, bit-identical on every platform. Arguments are positional.
|
||||
22
docs/language/rect/rect-bottom.md
Normal file
22
docs/language/rect/rect-bottom.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-bottom
|
||||
name: Rect.bottom
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.bottom
|
||||
sig: Rect.bottom(r) -> fixed
|
||||
tip: The bottom edge, y + h.
|
||||
order: 6
|
||||
ns: Rect
|
||||
member: bottom
|
||||
---
|
||||
|
||||
Returns the bottom edge, <code>y + h</code> — the y coordinate just below the rectangle.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let base = Rect.bottom(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-center.md
Normal file
22
docs/language/rect/rect-center.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-center
|
||||
name: Rect.center
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.center
|
||||
sig: Rect.center(r) -> Vector
|
||||
tip: The center point as a Vector.
|
||||
order: 7
|
||||
ns: Rect
|
||||
member: center
|
||||
---
|
||||
|
||||
Returns the center point <code>(x + w/2, y + h/2)</code> as a <code>Vector</code> — the anchor you want when placing a label or spawning at the middle of a box.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let mid = Rect.center(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-contains.md
Normal file
22
docs/language/rect/rect-contains.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-contains
|
||||
name: Rect.contains
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.contains
|
||||
sig: Rect.contains(r, px, py) -> bool
|
||||
tip: True when the point is inside.
|
||||
order: 8
|
||||
ns: Rect
|
||||
member: contains
|
||||
---
|
||||
|
||||
Tests whether the point <code>(px, py)</code> falls inside the rectangle. The left and top edges are inclusive; the right and bottom edges are exclusive, so adjacent rectangles tile without overlap. The classic use is a mouse-in-button hit test.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
if Rect.contains(button, mx, my) { press() }
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-h.md
Normal file
22
docs/language/rect/rect-h.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-h
|
||||
name: Rect.h
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.h
|
||||
sig: Rect.h(r) -> fixed
|
||||
tip: The height.
|
||||
order: 4
|
||||
ns: Rect
|
||||
member: h
|
||||
---
|
||||
|
||||
Reads the height of the rectangle.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let height = Rect.h(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-intersects.md
Normal file
22
docs/language/rect/rect-intersects.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-intersects
|
||||
name: Rect.intersects
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.intersects
|
||||
sig: Rect.intersects(a, b) -> bool
|
||||
tip: True when two rectangles overlap.
|
||||
order: 9
|
||||
ns: Rect
|
||||
member: intersects
|
||||
---
|
||||
|
||||
Tests whether two rectangles overlap (axis-aligned bounding-box test). Touching edges do not count as overlapping. This is the cheap broad-phase check before any finer collision work.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
if Rect.intersects(player, hazard) { hurt() }
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-make.md
Normal file
22
docs/language/rect/rect-make.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-make
|
||||
name: Rect.make
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.make
|
||||
sig: Rect.make(x, y, w, h) -> Rect
|
||||
tip: Build a rectangle from a corner and a size.
|
||||
order: 0
|
||||
ns: Rect
|
||||
member: make
|
||||
---
|
||||
|
||||
Builds a <code>Rect</code> from its top-left corner <code>(x, y)</code> and size <code>(w, h)</code>, all <code>fixed</code>. Read the parts back with <code>Rect.x</code> / <code>Rect.y</code> / <code>Rect.w</code> / <code>Rect.h</code>.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let hud = Rect.make(8.0, 8.0, 96.0, 16.0)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-right.md
Normal file
22
docs/language/rect/rect-right.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-right
|
||||
name: Rect.right
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.right
|
||||
sig: Rect.right(r) -> fixed
|
||||
tip: The right edge, x + w.
|
||||
order: 5
|
||||
ns: Rect
|
||||
member: right
|
||||
---
|
||||
|
||||
Returns the right edge, <code>x + w</code> — the x coordinate just past the rectangle. Handy for anchoring something to a box's right side.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let edge = Rect.right(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-w.md
Normal file
22
docs/language/rect/rect-w.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-w
|
||||
name: Rect.w
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.w
|
||||
sig: Rect.w(r) -> fixed
|
||||
tip: The width.
|
||||
order: 3
|
||||
ns: Rect
|
||||
member: w
|
||||
---
|
||||
|
||||
Reads the width of the rectangle.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let width = Rect.w(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-x.md
Normal file
22
docs/language/rect/rect-x.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-x
|
||||
name: Rect.x
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.x
|
||||
sig: Rect.x(r) -> fixed
|
||||
tip: The left edge (x position).
|
||||
order: 1
|
||||
ns: Rect
|
||||
member: x
|
||||
---
|
||||
|
||||
Reads the left edge — the <code>x</code> position of the rectangle's top-left corner.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let left = Rect.x(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/rect/rect-y.md
Normal file
22
docs/language/rect/rect-y.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: rect-y
|
||||
name: Rect.y
|
||||
category: rect
|
||||
kind: namespace-method
|
||||
tokens: Rect.y
|
||||
sig: Rect.y(r) -> fixed
|
||||
tip: The top edge (y position).
|
||||
order: 2
|
||||
ns: Rect
|
||||
member: y
|
||||
---
|
||||
|
||||
Reads the top edge — the <code>y</code> position of the rectangle's top-left corner.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let top = Rect.y(hud)
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue