| 1 | struct Vec { |
| 2 | mut: |
| 3 | x f64 |
| 4 | y f64 |
| 5 | z f64 |
| 6 | } |
| 7 | |
| 8 | struct Plane { |
| 9 | position Vec |
| 10 | normal Vec |
| 11 | } |
| 12 | |
| 13 | struct Sphere { |
| 14 | position Vec |
| 15 | radius f64 |
| 16 | } |
| 17 | |
| 18 | interface Object { |
| 19 | position Vec |
| 20 | } |
| 21 | |
| 22 | fn test_append_struct_to_interface_array() { |
| 23 | mut scene := []Object{} |
| 24 | |
| 25 | scene << Plane{ |
| 26 | position: Vec{0, -10, 0} |
| 27 | normal: Vec{0, -1, 0} |
| 28 | } |
| 29 | scene << Sphere{ |
| 30 | position: Vec{0, 0, -20} |
| 31 | radius: 7 |
| 32 | } |
| 33 | |
| 34 | println(scene) |
| 35 | |
| 36 | assert scene.len == 2 |
| 37 | assert scene[0].position.x == 0 |
| 38 | assert scene[0].position.y == -10 |
| 39 | assert scene[0].position.z == 0 |
| 40 | assert scene[1].position.x == 0 |
| 41 | assert scene[1].position.y == 0 |
| 42 | assert scene[1].position.z == -20 |
| 43 | } |
| 44 | |