-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimitives.go
More file actions
6455 lines (5663 loc) · 191 KB
/
primitives.go
File metadata and controls
6455 lines (5663 loc) · 191 KB
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package topo
/*
#include <stdlib.h>
#include <string.h>
#include "primitives_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 (
"errors"
"runtime"
"unsafe"
)
type SphereParams struct {
Radius float32
}
func (p *SphereParams) to_struct() C.sphere_params_t {
var c C.sphere_params_t
c.radius = C.double(p.Radius)
return c
}
func CreateSphere(params SphereParams) *Shape {
shp := C.create_sphere(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateSphereWithPlace(params SphereParams, center Point3) *Shape {
shp := C.create_sphere_with_place(params.to_struct(), center.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type RotationalEllipsoidParams struct {
PolarRadius float32
EquatorialRadius float32
Height float32
}
func (p *RotationalEllipsoidParams) to_struct() C.rotational_ellipsoid_params_t {
var c C.rotational_ellipsoid_params_t
c.polarRadius = C.double(p.PolarRadius)
c.equatorialRadius = C.double(p.EquatorialRadius)
c.height = C.double(p.Height)
return c
}
func CreateRotationalEllipsoid(params RotationalEllipsoidParams) *Shape {
shp := C.create_rotational_ellipsoid(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateRotationalEllipsoidWithPlace(params RotationalEllipsoidParams, center Point3, xDir Dir3) *Shape {
shp := C.create_rotational_ellipsoid_with_place(params.to_struct(), center.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type CuboidParams struct {
Length float32
Width float32
Height float32
}
func (p *CuboidParams) to_struct() C.cuboid_params_t {
var c C.cuboid_params_t
c.length = C.double(p.Length)
c.width = C.double(p.Width)
c.height = C.double(p.Height)
return c
}
func CreateCuboid(params CuboidParams) *Shape {
shp := C.create_cuboid(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateCuboidWithPlace(params CuboidParams, center Point3, xDir Dir3, zDir Dir3) *Shape {
shp := C.create_cuboid_with_place(params.to_struct(), center.val, xDir.val, zDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type DiamondFrustumParams struct {
TopDiag1 float32
TopDiag2 float32
BottomDiag1 float32
BottomDiag2 float32
Height float32
}
func (p *DiamondFrustumParams) to_struct() C.diamond_frustum_t {
var c C.diamond_frustum_t
c.topDiag1 = C.double(p.TopDiag1)
c.topDiag2 = C.double(p.TopDiag2)
c.bottomDiag1 = C.double(p.BottomDiag1)
c.bottomDiag2 = C.double(p.BottomDiag2)
c.height = C.double(p.Height)
return c
}
func CreateDiamondFrustum(params DiamondFrustumParams) *Shape {
shp := C.create_diamond_frustum(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateDiamondFrustumWithPlace(params DiamondFrustumParams, position Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_diamond_frustum_with_place(params.to_struct(), position.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type OffsetRectangularTableParams struct {
TopLength float32
TopWidth float32
BottomLength float32
BottomWidth float32
Height float32
XOffset float32
YOffset float32
}
func (p *OffsetRectangularTableParams) to_struct() C.offset_rectangular_table_params_t {
var c C.offset_rectangular_table_params_t
c.topLength = C.double(p.TopLength)
c.topWidth = C.double(p.TopWidth)
c.bottomLength = C.double(p.BottomLength)
c.bottomWidth = C.double(p.BottomWidth)
c.height = C.double(p.Height)
c.xOffset = C.double(p.XOffset)
c.yOffset = C.double(p.YOffset)
return c
}
func CreateOffsetRectangularTable(params OffsetRectangularTableParams) *Shape {
shp := C.create_offset_rectangular_table(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateOffsetRectangularTableWithPlace(params OffsetRectangularTableParams, position Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_offset_rectangular_table_with_place(params.to_struct(), position.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type SharpBentCylinderParams struct {
Radius float32
Length float32
BendAngle float32
}
func (p *SharpBentCylinderParams) to_struct() C.sharp_bent_cylinder_params_t {
var c C.sharp_bent_cylinder_params_t
c.radius = C.double(p.Radius)
c.length = C.double(p.Length)
c.bendAngle = C.double(p.BendAngle)
return c
}
func CreateSharpBentCylinder(params SharpBentCylinderParams) *Shape {
shp := C.create_sharp_bent_cylinder(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateSharpBentCylinderWithPlace(params SharpBentCylinderParams, position Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_sharp_bent_cylinder_with_place(params.to_struct(), position.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type TruncatedConeParams struct {
TopRadius float32
BottomRadius float32
Height float32
}
func (p *TruncatedConeParams) to_struct() C.truncated_cone_params_t {
var c C.truncated_cone_params_t
c.topRadius = C.double(p.TopRadius)
c.bottomRadius = C.double(p.BottomRadius)
c.height = C.double(p.Height)
return c
}
func CreateTruncatedCone(params TruncatedConeParams) *Shape {
shp := C.create_truncated_cone(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateTruncatedConeWithPlace(params TruncatedConeParams, basePoint Point3, axisDir Dir3) *Shape {
shp := C.create_truncated_cone_with_place(params.to_struct(), basePoint.val, axisDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type EccentricTruncatedConeParams struct {
TopRadius float32
BottomRadius float32
Height float32
TopXOffset float32
TopYOffset float32
}
func (p *EccentricTruncatedConeParams) to_struct() C.eccentric_truncated_cone_params_t {
var c C.eccentric_truncated_cone_params_t
c.topRadius = C.double(p.TopRadius)
c.bottomRadius = C.double(p.BottomRadius)
c.height = C.double(p.Height)
c.topXOffset = C.double(p.TopXOffset)
c.topYOffset = C.double(p.TopYOffset)
return c
}
func CreateEccentricTruncatedCone(params EccentricTruncatedConeParams) *Shape {
shp := C.create_eccentric_truncated_cone(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateEccentricTruncatedConeWithPlace(params EccentricTruncatedConeParams, basePoint Point3, axisDir Dir3) *Shape {
shp := C.create_eccentric_truncated_cone_with_place(params.to_struct(), basePoint.val, axisDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type RingParams struct {
RingRadius float32
TubeRadius float32
Angle float32
}
func (p *RingParams) to_struct() C.ring_params_t {
var c C.ring_params_t
c.ringRadius = C.double(p.RingRadius)
c.tubeRadius = C.double(p.TubeRadius)
c.angle = C.double(p.Angle)
return c
}
func CreateRing(params RingParams) *Shape {
shp := C.create_ring(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateRingWithPlace(params RingParams, center Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_ring_with_place(params.to_struct(), center.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type RectangularRingParams struct {
TubeRadius float32
FilletRadius float32
Length float32
Width float32
}
func (p *RectangularRingParams) to_struct() C.rectangular_ring_params_t {
var c C.rectangular_ring_params_t
c.tubeRadius = C.double(p.TubeRadius)
c.filletRadius = C.double(p.FilletRadius)
c.length = C.double(p.Length)
c.width = C.double(p.Width)
return c
}
func CreateRectangularRing(params RectangularRingParams) *Shape {
shp := C.create_rectangular_ring(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateRectangularRingWithPlace(params RectangularRingParams, center Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_rectangular_ring_with_place(params.to_struct(), center.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type EllipticRingParams struct {
TubeRadius float32
MajorRadius float32
MinorRadius float32
}
func (p *EllipticRingParams) to_struct() C.elliptic_ring_params_t {
var c C.elliptic_ring_params_t
c.tubeRadius = C.double(p.TubeRadius)
c.majorRadius = C.double(p.MajorRadius)
c.minorRadius = C.double(p.MinorRadius)
return c
}
func CreateEllipticRing(params EllipticRingParams) *Shape {
shp := C.create_elliptic_ring(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateEllipticRingWithPlace(params EllipticRingParams, center Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_elliptic_ring_with_place(params.to_struct(), center.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type CircularGasketParams struct {
OuterRadius float32
InnerRadius float32
Height float32
Angle float32
}
func (p *CircularGasketParams) to_struct() C.circular_gasket_params_t {
var c C.circular_gasket_params_t
c.outerRadius = C.double(p.OuterRadius)
c.innerRadius = C.double(p.InnerRadius)
c.height = C.double(p.Height)
c.angle = C.double(p.Angle)
return c
}
func CreateCircularGasket(params CircularGasketParams) *Shape {
shp := C.create_circular_gasket(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateCircularGasketWithPlace(params CircularGasketParams, center Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_circular_gasket_with_place(params.to_struct(), center.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type TableGasketParams struct {
TopRadius float32
OuterRadius float32
InnerRadius float32
Height float32
Angle float32
}
func (p *TableGasketParams) to_struct() C.table_gasket_params_t {
var c C.table_gasket_params_t
c.topRadius = C.double(p.TopRadius)
c.outerRadius = C.double(p.OuterRadius)
c.innerRadius = C.double(p.InnerRadius)
c.height = C.double(p.Height)
c.angle = C.double(p.Angle)
return c
}
func CreateTableGasket(params TableGasketParams) *Shape {
shp := C.create_table_gasket(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateTableGasketWithPlace(params TableGasketParams, center Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_table_gasket_with_place(params.to_struct(), center.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type SquareGasketParams struct {
OuterLength float32
OuterWidth float32
InnerLength float32
InnerWidth float32
Height float32
CornerType int32
CornerParam float32
}
func (p *SquareGasketParams) to_struct() C.square_gasket_params_t {
var c C.square_gasket_params_t
c.outerLength = C.double(p.OuterLength)
c.outerWidth = C.double(p.OuterWidth)
c.innerLength = C.double(p.InnerLength)
c.innerWidth = C.double(p.InnerWidth)
c.height = C.double(p.Height)
c.cornerType = C.int(p.CornerType)
c.cornerParam = C.double(p.CornerParam)
return c
}
func CreateSquareGasket(params SquareGasketParams) *Shape {
shp := C.create_square_gasket(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateSquareGasketWithPlace(params SquareGasketParams, center Point3, normal Dir3, xDir Dir3) *Shape {
shp := C.create_square_gasket_with_place(params.to_struct(), center.val, normal.val, xDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type StretchedBodyParams struct {
Points []Point3
Normal Dir3
Length float32
}
func (p *StretchedBodyParams) to_struct() C.stretched_body_params_t {
var c C.stretched_body_params_t
c.numPoints = C.int(len(p.Points))
c.normal = p.Normal.val
c.length = C.double(p.Length)
if len(p.Points) > 0 {
c.points = (*C.pnt3d_t)(C.malloc(C.size_t(len(p.Points)) * C.sizeof_pnt3d_t))
for i, pt := range p.Points {
*(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.points)) + uintptr(i)*C.sizeof_pnt3d_t)) = pt.val
}
}
return c
}
func CreateStretchedBody(params StretchedBodyParams) *Shape {
shp := C.create_stretched_body(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateStretchedBodyWithPlace(params StretchedBodyParams, basePoint Point3, axisDir Dir3) *Shape {
shp := C.create_stretched_body_with_place(params.to_struct(), basePoint.val, axisDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type PorcelainBushingParams struct {
Height float32
Radius float32
BigSkirtRadius float32
SmallSkirtRadius float32
Count int32
}
func (p *PorcelainBushingParams) to_struct() C.porcelain_bushing_params_t {
var c C.porcelain_bushing_params_t
c.height = C.double(p.Height)
c.radius = C.double(p.Radius)
c.bigSkirtRadius = C.double(p.BigSkirtRadius)
c.smallSkirtRadius = C.double(p.SmallSkirtRadius)
c.count = C.int(p.Count)
return c
}
func CreatePorcelainBushing(params PorcelainBushingParams) *Shape {
shp := C.create_porcelain_bushing(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreatePorcelainBushingWithPlace(params PorcelainBushingParams, basePoint Point3, axisDir Dir3) *Shape {
shp := C.create_porcelain_bushing_with_place(params.to_struct(), basePoint.val, axisDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type ConePorcelainBushingParams struct {
Height float32
BottomRadius float32
TopRadius float32
BottomSkirtRadius1 float32
BottomSkirtRadius2 float32
TopSkirtRadius1 float32
TopSkirtRadius2 float32
Count int32
}
func (p *ConePorcelainBushingParams) to_struct() C.cone_porcelain_bushing_params_t {
var c C.cone_porcelain_bushing_params_t
c.height = C.double(p.Height)
c.bottomRadius = C.double(p.BottomRadius)
c.topRadius = C.double(p.TopRadius)
c.bottomSkirtRadius1 = C.double(p.BottomSkirtRadius1)
c.bottomSkirtRadius2 = C.double(p.BottomSkirtRadius2)
c.topSkirtRadius1 = C.double(p.TopSkirtRadius1)
c.topSkirtRadius2 = C.double(p.TopSkirtRadius2)
c.count = C.int(p.Count)
return c
}
func CreateConePorcelainBushing(params ConePorcelainBushingParams) *Shape {
shp := C.create_cone_porcelain_bushing(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateConePorcelainBushingWithPlace(params ConePorcelainBushingParams, basePoint Point3, axisDir Dir3) *Shape {
shp := C.create_cone_porcelain_bushing_with_place(params.to_struct(), basePoint.val, axisDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type InsulatorStringParams struct {
Count int32
Spacing float32
InsulatorCount int32
Height float32
BigSkirtRadius float32
SmallSkirtRadius float32
Radius float32
FrontLength float32
BackLength float32
SplitCount int32
}
func (p *InsulatorStringParams) to_struct() C.insulator_string_params_t {
var c C.insulator_string_params_t
c.count = C.int(p.Count)
c.spacing = C.double(p.Spacing)
c.insulatorCount = C.int(p.InsulatorCount)
c.height = C.double(p.Height)
c.bigSkirtRadius = C.double(p.BigSkirtRadius)
c.smallSkirtRadius = C.double(p.SmallSkirtRadius)
c.radius = C.double(p.Radius)
c.frontLength = C.double(p.FrontLength)
c.backLength = C.double(p.BackLength)
c.splitCount = C.int(p.SplitCount)
return c
}
func CreateInsulatorString(params InsulatorStringParams) *Shape {
shp := C.create_insulator_string(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateInsulatorStringWithPlace(params InsulatorStringParams, position Point3, direction Dir3, upDirection Dir3) *Shape {
shp := C.create_insulator_string_with_place(params.to_struct(), position.val, direction.val, upDirection.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type VTypeInsulatorParams struct {
FrontSpacing float32
BackSpacing float32
InsulatorCount int32
Height float32
Radius float32
BigSkirtRadius float32
SmallSkirtRadius float32
FrontLength float32
BackLength float32
SplitCount int32
}
func (p *VTypeInsulatorParams) to_struct() C.vtype_insulator_params_t {
var c C.vtype_insulator_params_t
c.frontSpacing = C.double(p.FrontSpacing)
c.backSpacing = C.double(p.BackSpacing)
c.insulatorCount = C.int(p.InsulatorCount)
c.height = C.double(p.Height)
c.radius = C.double(p.Radius)
c.bigSkirtRadius = C.double(p.BigSkirtRadius)
c.smallSkirtRadius = C.double(p.SmallSkirtRadius)
c.frontLength = C.double(p.FrontLength)
c.backLength = C.double(p.BackLength)
c.splitCount = C.int(p.SplitCount)
return c
}
func CreateVTypeInsulator(params VTypeInsulatorParams) *Shape {
shp := C.create_vtype_insulator(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateVTypeInsulatorWithPlace(params VTypeInsulatorParams, position Point3, direction Dir3, upDirection Dir3) *Shape {
shp := C.create_vtype_insulator_with_place(params.to_struct(), position.val, direction.val, upDirection.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type TerminalBlockParams struct {
Length float32
Width float32
Thickness float32
ChamferLength float32
ColumnSpacing float32
RowSpacing float32
HoleRadius float32
ColumnCount int32
RowCount int32
BottomOffset float32
}
func (p *TerminalBlockParams) to_struct() C.terminal_block_params_t {
var c C.terminal_block_params_t
c.length = C.double(p.Length)
c.width = C.double(p.Width)
c.thickness = C.double(p.Thickness)
c.chamferLength = C.double(p.ChamferLength)
c.columnSpacing = C.double(p.ColumnSpacing)
c.rowSpacing = C.double(p.RowSpacing)
c.holeRadius = C.double(p.HoleRadius)
c.columnCount = C.int(p.ColumnCount)
c.rowCount = C.int(p.RowCount)
c.bottomOffset = C.double(p.BottomOffset)
return c
}
func CreateTerminalBlock(params TerminalBlockParams) *Shape {
shp := C.create_terminal_block(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateTerminalBlockWithPlace(params TerminalBlockParams, position Point3, lengthDir Dir3, widthDir Dir3) *Shape {
shp := C.create_terminal_block_with_place(params.to_struct(), position.val, lengthDir.val, widthDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type RectangularFixedPlateParams struct {
Length float32
Width float32
Thickness float32
ColumnSpacing float32
RowSpacing float32
ColumnCount int32
RowCount int32
HasMiddleHole bool
HoleDiameter float32
}
func (p *RectangularFixedPlateParams) to_struct() C.rectangular_fixed_plate_params_t {
var c C.rectangular_fixed_plate_params_t
c.length = C.double(p.Length)
c.width = C.double(p.Width)
c.thickness = C.double(p.Thickness)
c.columnSpacing = C.double(p.ColumnSpacing)
c.rowSpacing = C.double(p.RowSpacing)
c.columnCount = C.int(p.ColumnCount)
c.rowCount = C.int(p.RowCount)
c.hasMiddleHole = C.bool(p.HasMiddleHole)
c.holeDiameter = C.double(p.HoleDiameter)
return c
}
func CreateRectangularFixedPlate(params RectangularFixedPlateParams) *Shape {
shp := C.create_rectangular_fixed_plate(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateRectangularFixedPlateWithPlace(params RectangularFixedPlateParams, position Point3, lengthDir Dir3, widthDir Dir3) *Shape {
shp := C.create_rectangular_fixed_plate_with_place(params.to_struct(), position.val, lengthDir.val, widthDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type CircularFixedPlateParams struct {
Length float32
Width float32
Thickness float32
RingRadius float32
HoleCount int32
HasMiddleHole bool
HoleDiameter float32
}
func (p *CircularFixedPlateParams) to_struct() C.circular_fixed_plate_params_t {
var c C.circular_fixed_plate_params_t
c.length = C.double(p.Length)
c.width = C.double(p.Width)
c.thickness = C.double(p.Thickness)
c.ringRadius = C.double(p.RingRadius)
c.holeCount = C.int(p.HoleCount)
c.hasMiddleHole = C.bool(p.HasMiddleHole)
c.holeDiameter = C.double(p.HoleDiameter)
return c
}
func CreateCircularFixedPlate(params CircularFixedPlateParams) *Shape {
shp := C.create_circular_fixed_plate(params.to_struct())
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateCircularFixedPlateWithPlace(params CircularFixedPlateParams, position Point3, lengthDir Dir3, widthDir Dir3) *Shape {
shp := C.create_circular_fixed_plate_with_place(params.to_struct(), position.val, lengthDir.val, widthDir.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
type WireParams struct {
StartPoint Point3
EndPoint Point3
StartDir Dir3
EndDir Dir3
Sag float32
Diameter float32
FitPoints []Point3
}
func (p *WireParams) to_struct() C.wire_params_t {
var c C.wire_params_t
c.startPoint = p.StartPoint.val
c.endPoint = p.EndPoint.val
c.startDir = p.StartDir.val
c.endDir = p.EndDir.val
c.sag = C.double(p.Sag)
c.diameter = C.double(p.Diameter)
c.numFitPoints = C.int(len(p.FitPoints))
if len(p.FitPoints) > 0 {
c.fitPoints = (*C.pnt3d_t)(C.malloc(C.size_t(len(p.FitPoints)) * C.sizeof_pnt3d_t))
for i, pt := range p.FitPoints {
*(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.fitPoints)) + uintptr(i)*C.sizeof_pnt3d_t)) = pt.val
}
}
return c
}
func freeWireParams(c C.wire_params_t) {
if c.fitPoints != nil {
C.free(unsafe.Pointer(c.fitPoints))
}
}
func CreateWire(params WireParams) *Shape {
cParams := params.to_struct()
defer freeWireParams(cParams)
shp := C.create_wire(cParams)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateWireWithPlace(params WireParams, position Point3, direction Dir3, upDirection Dir3) *Shape {
cParams := params.to_struct()
defer freeWireParams(cParams)
shp := C.create_wire_with_place(cParams, position.val, direction.val, upDirection.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateWireCenterline(params WireParams) *Wire {
cParams := params.to_struct()
defer freeWireParams(cParams)
wire := C.create_wire_centerline(cParams)
w := &Wire{inner: &innerWire{val: wire}}
runtime.SetFinalizer(w.inner, (*innerWire).free)
return w
}
func SampleWirePoints(params WireParams, tessellation float64) []Point3 {
cParams := params.to_struct()
defer freeWireParams(cParams)
var outCount C.int
cPoints := C.sample_wire_points(cParams, C.double(tessellation), &outCount)
defer C.free(unsafe.Pointer(cPoints))
points := make([]Point3, outCount)
for i := 0; i < int(outCount); i++ {
points[i] = Point3{
val: *(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(cPoints)) + uintptr(i)*C.sizeof_pnt3d_t)),
}
}
return points
}
type CableParams struct {
StartPoint Point3
EndPoint Point3
InflectionPoints []Point3
Radii []float32
Diameter float32
}
func (p *CableParams) to_struct() C.cable_params_t {
var c C.cable_params_t
c.startPoint = p.StartPoint.val
c.endPoint = p.EndPoint.val
c.numInflectionPoints = C.int(len(p.InflectionPoints))
c.numRadii = C.int(len(p.Radii))
c.diameter = C.double(p.Diameter)
if len(p.InflectionPoints) > 0 {
c.inflectionPoints = (*C.pnt3d_t)(C.malloc(C.size_t(len(p.InflectionPoints)) * C.sizeof_pnt3d_t))
for i, pt := range p.InflectionPoints {
*(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.inflectionPoints)) + uintptr(i)*C.sizeof_pnt3d_t)) = pt.val
}
}
if len(p.Radii) > 0 {
c.radii = (*C.double)(C.malloc(C.size_t(len(p.Radii)) * C.sizeof_double))
for i, r := range p.Radii {
*(*C.double)(unsafe.Pointer(uintptr(unsafe.Pointer(c.radii)) + uintptr(i)*C.sizeof_double)) = C.double(r)
}
}
return c
}
func freeCableParams(c C.cable_params_t) {
if c.inflectionPoints != nil {
C.free(unsafe.Pointer(c.inflectionPoints))
}
if c.radii != nil {
C.free(unsafe.Pointer(c.radii))
}
}
func CreateCable(params CableParams) *Shape {
cParams := params.to_struct()
defer freeCableParams(cParams)
shp := C.create_cable(cParams)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateCableCenterline(params CableParams) *Wire {
cParams := params.to_struct()
defer freeCableParams(cParams)
wire := C.create_cable_centerline(cParams)
w := &Wire{inner: &innerWire{val: wire}}
runtime.SetFinalizer(w.inner, (*innerWire).free)
return w
}
func CreateCableWithPlace(params CableParams, position Point3, direction Dir3, upDirection Dir3) *Shape {
cParams := params.to_struct()
defer freeCableParams(cParams)
shp := C.create_cable_with_place(cParams, position.val, direction.val, upDirection.val)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func SampleCablePoints(params CableParams, tessellation float64) []Point3 {
cParams := params.to_struct()
defer freeCableParams(cParams)
var outCount C.int
cPoints := C.sample_cable_points(cParams, C.double(tessellation), &outCount)
defer C.free(unsafe.Pointer(cPoints))
points := make([]Point3, outCount)
for i := 0; i < int(outCount); i++ {
points[i] = Point3{
val: *(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(cPoints)) + uintptr(i)*C.sizeof_pnt3d_t)),
}
}
return points
}
type CurveType int
const (
CurveTypeLine CurveType = 0
CurveTypeArc CurveType = 1
CurveTypeBezier CurveType = 2
)
type CurveSegment struct {
ControlPoints []Point3
}
type CurveCableParams struct {
Segments []CurveSegment
CurveTypes []CurveType
Diameter float32
}
func (p *CurveCableParams) to_struct() C.curve_cable_params_t {
var c C.curve_cable_params_t
c.numSegments = C.int(len(p.Segments))
c.diameter = C.double(p.Diameter)
if len(p.Segments) > 0 {
// Allocate memory for segments
c.segments = (*C.curve_segment_t)(C.malloc(C.size_t(len(p.Segments)) * C.sizeof_curve_segment_t))
c.curveTypes = (*C.curve_type_t)(C.malloc(C.size_t(len(p.CurveTypes)) * C.sizeof_curve_type_t))
for i, seg := range p.Segments {
// Set curve type
*(*C.curve_type_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.curveTypes)) + uintptr(i)*C.sizeof_curve_type_t)) =
C.curve_type_t(p.CurveTypes[i])
// Set segment data
segmentPtr := (*C.curve_segment_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.segments)) + uintptr(i)*C.sizeof_curve_segment_t))
segmentPtr.numPoints = C.int(len(seg.ControlPoints))
if len(seg.ControlPoints) > 0 {
segmentPtr.controlPoints = (*C.pnt3d_t)(C.malloc(C.size_t(len(seg.ControlPoints)) * C.sizeof_pnt3d_t))
for j, pt := range seg.ControlPoints {
*(*C.pnt3d_t)(unsafe.Pointer(uintptr(unsafe.Pointer(segmentPtr.controlPoints)) + uintptr(j)*C.sizeof_pnt3d_t)) = pt.val
}
}
}
}
return c
}
func freeCurveCableParams(c C.curve_cable_params_t) {
if c.segments != nil {
for i := 0; i < int(c.numSegments); i++ {
seg := (*C.curve_segment_t)(unsafe.Pointer(uintptr(unsafe.Pointer(c.segments)) + uintptr(i)*C.sizeof_curve_segment_t))
if seg.controlPoints != nil {
C.free(unsafe.Pointer(seg.controlPoints))
}
}
C.free(unsafe.Pointer(c.segments))
}
if c.curveTypes != nil {
C.free(unsafe.Pointer(c.curveTypes))
}
}
func CreateCurveCable(params CurveCableParams) *Shape {
cParams := params.to_struct()
defer freeCurveCableParams(cParams)
shp := C.create_curve_cable(cParams)
s := &Shape{inner: &innerShape{val: shp}}
runtime.SetFinalizer(s.inner, (*innerShape).free)
return s
}
func CreateCurveCableCenterline(params CurveCableParams) *Wire {
cParams := params.to_struct()
defer freeCurveCableParams(cParams)
wire := C.create_curve_cable_centerline(cParams)
w := &Wire{inner: &innerWire{val: wire}}
runtime.SetFinalizer(w.inner, (*innerWire).free)
return w
}
func CreateCurveCableWithPlace(params CurveCableParams, position Point3, direction Dir3, upDirection Dir3) *Shape {