-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex.go
336 lines (273 loc) · 9.6 KB
/
vertex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package topo
/*
#include <stdlib.h>
#include "topo_c_api.h"
#cgo CFLAGS: -I ./libs
#cgo linux CXXFLAGS: -I ./libs -std=gnu++14
#cgo darwin,amd64 CXXFLAGS: -I ./libs -std=gnu++14
#cgo darwin,arm64 CXXFLAGS: -I ./libs -std=gnu++14
#cgo windows CXXFLAGS: -I ./libs -std=gnu++14
*/
import "C"
import (
"runtime"
"unsafe"
)
type Vertex struct {
inner *innerVertex
}
type innerVertex struct {
val C.struct__topo_vertex_t
}
func (s *Vertex) IsNull() bool {
return bool(C.topo_shape_is_null(s.inner.val.shp))
}
func (s *Vertex) IsValid() bool {
return bool(C.topo_shape_is_valid(s.inner.val.shp))
}
func (s *Vertex) Equals(e *Shape) bool {
return bool(C.topo_shape_equals(s.inner.val.shp, e.inner.val))
}
func (s *Vertex) Type() int {
return int(C.topo_shape_type(s.inner.val.shp))
}
func (s *Vertex) BBox() BBox {
return BBox{val: C.topo_shape_bounding_box(s.inner.val.shp)}
}
func (s *Vertex) Hash() int {
return int(C.topo_shape_hash_code(s.inner.val.shp))
}
func (s *Vertex) Transform(t Trsf) int {
return int(C.topo_shape_transform(s.inner.val.shp, t.val))
}
func (s *Vertex) Translate(v Vector3) int {
return int(C.topo_shape_translate(s.inner.val.shp, v.val))
}
func (s *Vertex) RotateFromPoint(angle float64, p1, p2 Point3) int {
return int(C.topo_shape_rotate_from_two_point(s.inner.val.shp, C.double(angle), p1.val, p2.val))
}
func (s *Vertex) RotateFromAxis1(angle float64, a Axis1) int {
return int(C.topo_shape_rotate_from_axis1(s.inner.val.shp, C.double(angle), a.val))
}
func (s *Vertex) RotateFromQuaternion(q Quaternion) int {
return int(C.topo_shape_rotate_from_quaternion(s.inner.val.shp, q.val))
}
func (s *Vertex) Scale(angle float64, a Point3) int {
return int(C.topo_shape_scale(s.inner.val.shp, C.double(angle), a.val))
}
func (s *Vertex) MirrorFromPointNorm(pnt, ner Point3) int {
return int(C.topo_shape_mirror_from_point_norm(s.inner.val.shp, pnt.val, ner.val))
}
func (s *Vertex) MirrorFromAxis1(a Axis1) int {
return int(C.topo_shape_mirror_from_axis1(s.inner.val.shp, a.val))
}
func (s *Vertex) MirrorFromAxis2(a Axis2) int {
return int(C.topo_shape_mirror_from_axis2(s.inner.val.shp, a.val))
}
func (s *Vertex) Transformed(t Trsf) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_transformed(s.inner.val.shp, t.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) Translated(v Vector3) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_translated(s.inner.val.shp, v.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) RotatedFromPoint(angle float64, p1, p2 Point3) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_rotated_from_two_point(s.inner.val.shp, C.double(angle), p1.val, p2.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) RotatedFromAxis1(angle float64, a Axis1) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_rotated_from_axis1(s.inner.val.shp, C.double(angle), a.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) RotatedFromQuaternion(q Quaternion) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_rotated_from_quaternion(s.inner.val.shp, q.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) Scaled(angle float64, a Point3) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_scaled(s.inner.val.shp, C.double(angle), a.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) MirroredFromPointNorm(pnt, ner Point3) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_mirrored_from_point_norm(s.inner.val.shp, pnt.val, ner.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) MirroredFromAxis1(a Axis1) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_mirrored_from_axis1(s.inner.val.shp, a.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) MirroredFromAxis2(a Axis2) *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_mirrored_from_axis2(s.inner.val.shp, a.val)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) GetOrientation() int {
return int(C.topo_shape_get_orientation(s.inner.val.shp))
}
func (s *Vertex) SetOrientation(t int) {
C.topo_shape_set_orientation(s.inner.val.shp, C.int(t))
}
func (s *Vertex) GetLocation() *TopoLocation {
p := &TopoLocation{inner: &innerTopoLocation{val: C.topo_shape_get_location(s.inner.val.shp)}}
runtime.SetFinalizer(p.inner, (*innerTopoLocation).free)
return p
}
func (s *Vertex) SetLocation(t *TopoLocation) {
C.topo_shape_set_location(s.inner.val.shp, t.inner.val)
}
func (s *Vertex) FixShape() bool {
return bool(C.topo_shape_fix_shape(s.inner.val.shp))
}
func (s *Vertex) Copy() *Vertex {
var val C.struct__topo_vertex_t
val.shp = C.topo_shape_copy(s.inner.val.shp)
vx := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(vx.inner, (*innerVertex).free)
return vx
}
func (s *Vertex) Mesh(m *MeshReceiver, tolerance, deflection, angle float64) {
C.topo_shape_mesh(s.inner.val.shp, m.inner.val, C.double(tolerance), C.double(deflection), C.double(angle), C.bool(false))
}
func (s *Vertex) MeshWithTexture(m *MeshReceiver, tolerance, deflection, angle float64) {
m.hasTexCoords = true
C.topo_shape_mesh(s.inner.val.shp, m.inner.val, C.double(tolerance), C.double(deflection), C.double(angle), C.bool(true))
}
func (s *Vertex) SetSurfaceColour(c Color) {
C.topo_shape_set_surface_colour(s.inner.val.shp, c.val)
}
func (s *Vertex) SetCurveColour(c Color) {
C.topo_shape_set_curve_colour(s.inner.val.shp, c.val)
}
func (s *Vertex) SetLabel(l string) {
str := C.CString(l)
defer C.free(unsafe.Pointer(str))
C.topo_shape_set_label(s.inner.val.shp, str)
}
func (s *Vertex) SetUVOrigin(u, v float64) {
C.topo_shape_set_u_origin(s.inner.val.shp, C.double(u))
C.topo_shape_set_v_origin(s.inner.val.shp, C.double(v))
}
func (s *Vertex) SetUVRepeat(u, v float64) {
C.topo_shape_set_u_repeat(s.inner.val.shp, C.double(u))
C.topo_shape_set_v_repeat(s.inner.val.shp, C.double(v))
}
func (s *Vertex) SetScaleU(u float64) {
C.topo_shape_set_scale_u(s.inner.val.shp, C.double(u))
}
func (s *Vertex) SetScaleV(v float64) {
C.topo_shape_set_scale_v(s.inner.val.shp, C.double(v))
}
func (s *Vertex) SetAutoScaleSizeOnU(u float64) {
C.topo_shape_set_auto_scale_size_on_u(s.inner.val.shp, C.double(u))
}
func (s *Vertex) SetAutoScaleSizeOnV(v float64) {
C.topo_shape_set_auto_scale_size_on_v(s.inner.val.shp, C.double(v))
}
func (s *Vertex) SetTextureMapType(t int) {
C.topo_shape_set_txture_map_type(s.inner.val.shp, C.int(t))
}
func (s *Vertex) SetRotationAngle(a float64) {
C.topo_shape_set_rotation_angle(s.inner.val.shp, C.double(a))
}
func (s *Vertex) GetSurfaceColour() Color {
return Color{val: C.topo_shape_get_surface_colour(s.inner.val.shp)}
}
func (s *Vertex) GetCurveColour() Color {
return Color{val: C.topo_shape_get_surface_colour(s.inner.val.shp)}
}
func (s *Vertex) GetLabel() string {
return C.GoString(C.topo_shape_get_label(s.inner.val.shp))
}
func (s *Vertex) GetUVOrigin() (u, v float64) {
u = float64(C.topo_shape_get_u_origin(s.inner.val.shp))
v = float64(C.topo_shape_get_v_origin(s.inner.val.shp))
return
}
func (s *Vertex) GetUVRepeat() (u, v float64) {
u = float64(C.topo_shape_get_u_repeat(s.inner.val.shp))
v = float64(C.topo_shape_get_v_repeat(s.inner.val.shp))
return
}
func (s *Vertex) GetUVScale() (u, v float64) {
u = float64(C.topo_shape_get_scale_u(s.inner.val.shp))
v = float64(C.topo_shape_get_scale_v(s.inner.val.shp))
return
}
func (s *Vertex) GetUVAutoScaleSize() (u, v float64) {
u = float64(C.topo_shape_get_auto_scale_size_on_u(s.inner.val.shp))
v = float64(C.topo_shape_get_auto_scale_size_on_v(s.inner.val.shp))
return
}
func (s *Vertex) GetTxtureMapType() int {
return int(C.topo_shape_get_txture_map_type(s.inner.val.shp))
}
func (s *Vertex) GetRotationAngle() float64 {
return float64(C.topo_shape_get_rotation_angle(s.inner.val.shp))
}
func (t *Vertex) GetPoint() Point3 {
return Point3{val: C.topo_vertex_get_point(t.inner.val)}
}
func (t *Vertex) ToShape() *Shape {
sp := &Shape{inner: &innerShape{val: C.topo_shape_share(t.inner.val.shp)}}
runtime.SetFinalizer(sp.inner, (*innerShape).free)
return sp
}
func (t *innerVertex) free() {
C.topo_vertex_free(t.val)
}
func NewVertex(x, y, z float64) *Vertex {
p := &Vertex{inner: &innerVertex{val: C.topo_vertex_new(C.double(x), C.double(y), C.double(z))}}
runtime.SetFinalizer(p.inner, (*innerVertex).free)
return p
}
type VertexIterator struct {
inner *innerVertexIterator
}
type innerVertexIterator struct {
val *C.struct__topo_vertex_iterator_t
}
func TopoMakeVertexIterator(p Shape) *VertexIterator {
wr := &VertexIterator{inner: &innerVertexIterator{val: C.topo_vertex_iterator_make(p.inner.val)}}
runtime.SetFinalizer(wr.inner, (*innerVertexIterator).free)
return wr
}
func (t *innerVertexIterator) free() {
C.topo_vertex_iterator_free(t.val)
}
func (t *VertexIterator) Next() *Vertex {
v := C.topo_vertex_iterator_next(t.inner.val)
if v != nil {
var val C.struct__topo_vertex_t
val.shp = v
p := &Vertex{inner: &innerVertex{val: val}}
runtime.SetFinalizer(p.inner, (*innerVertex).free)
return p
}
return nil
}