| 1 | module main |
| 2 | |
| 3 | import math.vec |
| 4 | |
| 5 | pub struct Bezier { |
| 6 | pub mut: |
| 7 | points [4]vec.Vec2[f32] |
| 8 | } |
| 9 | |
| 10 | pub fn (b Bezier) h3() vec.Vec2[f32] { |
| 11 | return b.points[2] |
| 12 | } |
| 13 | |
| 14 | pub fn (b Bezier) h4() vec.Vec2[f32] { |
| 15 | return b.points[3] |
| 16 | } |
| 17 | |
| 18 | pub fn (b Bezier) end() vec.Vec2[f32] { |
| 19 | return b.h4() |
| 20 | } |
| 21 | |
| 22 | pub struct Path { |
| 23 | pub mut: |
| 24 | segments [1024]Bezier |
| 25 | len int // should be read-only |
| 26 | } |
| 27 | |
| 28 | pub fn (mut p Path) add(b Bezier) { |
| 29 | assert p.len + 1 < 1024 |
| 30 | p.segments[p.len] = b |
| 31 | p.len++ |
| 32 | } |
| 33 | |
| 34 | fn test_main() { |
| 35 | b1 := Bezier{ |
| 36 | points: [vec.Vec2[f32]{100, 100}, vec.Vec2[f32]{120, 80}, |
| 37 | vec.Vec2[f32]{200, 70}, vec.Vec2[f32]{400, 200}]! |
| 38 | } |
| 39 | b2 := Bezier{ |
| 40 | points: [b1.end(), b1.h3() + vec.Vec2[f32]{0, 2 * 80}, vec.Vec2[f32]{200, 70}, |
| 41 | b1.end() + vec.Vec2[f32]{400, 200}]! |
| 42 | } |
| 43 | |
| 44 | mut path := Path{} |
| 45 | |
| 46 | path.add(b1) |
| 47 | path.add(b2) |
| 48 | |
| 49 | assert sizeof(path) == $if new_int ? && x64 { |
| 50 | 32776 |
| 51 | } $else { |
| 52 | 32772 |
| 53 | } |
| 54 | } |
| 55 | |