kittycad-modeling-cmds 0.2.191

Commands in the KittyCAD Modeling API
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
use bon::Builder;
use enum_iterator::Sequence;
use parse_display_derive::{Display, FromStr};
pub use point::{Point2d, Point3d, Point4d, Quaternion};
use schemars::{schema::SchemaObject, JsonSchema};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[cfg(feature = "cxx")]
use crate::impl_extern_type;
use crate::{def_enum::negative_one, length_unit::LengthUnit, output::ExtrusionFaceInfo, units::UnitAngle};

mod point;

/// What kind of cut to do
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub enum CutType {
    /// Round off an edge.
    #[default]
    Fillet,
    /// Cut away an edge.
    Chamfer,
}

/// What to reflect mirrored geometry across
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub enum MirrorAcross {
    /// Reflect across an edge
    /// If used with a 3D mirror, the edge will define the normal of the mirror plane.
    Edge {
        /// Edge ID.
        id: Uuid,
    },
    /// Reflect across an axis (that goes through a point)
    /// If used with a 3D mirror, the axis will define the normal of the mirror plane.
    Axis {
        /// Axis to use as mirror.
        axis: Point3d<f64>,
        /// Point through which the mirror axis passes.
        point: Point3d<LengthUnit>,
    },
    /// Reflect across a plane (which gives two axes)
    /// Cannot be used with 2D mirrors.
    Plane {
        /// Plane ID.
        id: Uuid,
    },
}

/// What kind of cut to perform when cutting an edge.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum CutTypeV2 {
    /// Round off an edge.
    Fillet {
        /// The radius of the fillet.
        radius: LengthUnit,
        /// The second length affects the edge length of the second face of the cut. This will
        /// cause the fillet to take on the shape of a conic section, instead of an arc.
        second_length: Option<LengthUnit>,
    },
    /// Cut away an edge.
    Chamfer {
        /// The distance from the edge to cut on each face.
        distance: LengthUnit,
        /// The second distance affects the edge length of the second face of the cut.
        second_distance: Option<LengthUnit>,
        /// The angle of the chamfer, default is 45deg.
        angle: Option<Angle>,
        /// If true, the second distance or angle is applied to the other face of the cut.
        swap: bool,
    },
    /// A custom cut profile.
    Custom {
        /// The path that will be used for the custom profile.
        path: Uuid,
    },
}

/// A rotation defined by an axis, origin of rotation, and an angle.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct Rotation {
    /// Rotation axis.
    /// Defaults to (0, 0, 1) (i.e. the Z axis).
    pub axis: Point3d<f64>,
    /// Rotate this far about the rotation axis.
    /// Defaults to zero (i.e. no rotation).
    pub angle: Angle,
    /// Origin of the rotation. If one isn't provided, the object will rotate about its own bounding box center.
    pub origin: OriginType,
}

impl Default for Rotation {
    /// z-axis, 0 degree angle, and local origin.
    fn default() -> Self {
        Self {
            axis: z_axis(),
            angle: Angle::default(),
            origin: OriginType::Local,
        }
    }
}

/// Ways to transform each solid being replicated in a repeating pattern.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct Transform {
    /// Translate the replica this far along each dimension.
    /// Defaults to zero vector (i.e. same position as the original).
    #[serde(default)]
    #[builder(default)]
    pub translate: Point3d<LengthUnit>,
    /// Scale the replica's size along each axis.
    /// Defaults to (1, 1, 1) (i.e. the same size as the original).
    #[serde(default = "same_scale")]
    #[builder(default = same_scale())]
    pub scale: Point3d<f64>,
    /// Rotate the replica about the specified rotation axis and origin.
    /// Defaults to no rotation.
    #[serde(default)]
    #[builder(default)]
    pub rotation: Rotation,
    /// Whether to replicate the original solid in this instance.
    #[serde(default = "bool_true")]
    #[builder(default = bool_true())]
    pub replicate: bool,
}

impl Default for Transform {
    fn default() -> Self {
        Self {
            scale: same_scale(),
            replicate: true,
            translate: Default::default(),
            rotation: Rotation::default(),
        }
    }
}

/// Options for annotations
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationOptions {
    /// Text displayed on the annotation
    pub text: Option<AnnotationTextOptions>,
    /// How to style the start and end of the line
    pub line_ends: Option<AnnotationLineEndOptions>,
    /// Width of the annotation's line
    pub line_width: Option<f32>,
    /// Color to render the annotation
    pub color: Option<Color>,
    /// Position to put the annotation
    pub position: Option<Point3d<f32>>,
    /// Set as an MBD measured basic dimension annotation
    pub dimension: Option<AnnotationBasicDimension>,
    /// Set as an MBD Feature control annotation
    pub feature_control: Option<AnnotationFeatureControl>,
    /// Set as a feature tag annotation
    pub feature_tag: Option<AnnotationFeatureTag>,
}

/// Options for annotation text
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationLineEndOptions {
    /// How to style the start of the annotation line.
    pub start: AnnotationLineEnd,
    /// How to style the end of the annotation line.
    pub end: AnnotationLineEnd,
}

/// Options for annotation text
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationTextOptions {
    /// Alignment along the X axis
    pub x: AnnotationTextAlignmentX,
    /// Alignment along the Y axis
    pub y: AnnotationTextAlignmentY,
    /// Text displayed on the annotation
    pub text: String,
    /// Text font's point size
    pub point_size: u32,
}

/// Parameters for defining an MBD Geometric control frame
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationMbdControlFrame {
    ///Geometric symbol, the type of geometric control specified
    pub symbol: MbdSymbol,
    /// Diameter symbol (if required) whether the geometric control requires a cylindrical or diameter tolerance
    pub diameter_symbol: Option<MbdSymbol>,
    /// Tolerance value - the total tolerance of the geometric control.  The unit is based on the drawing standard.
    pub tolerance: f64,
    /// Feature of size or tolerance modifiers
    pub modifier: Option<MbdSymbol>,
    /// Primary datum
    pub primary_datum: Option<char>,
    /// Secondary datum
    pub secondary_datum: Option<char>,
    /// Tertiary datum
    pub tertiary_datum: Option<char>,
}

/// Parameters for defining an MBD basic dimension
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationMbdBasicDimension {
    /// Type of symbol to use for this dimension (if required)
    pub symbol: Option<MbdSymbol>,
    /// The explicitly defined dimension.  Only required if the measurement is not automatically calculated.
    pub dimension: Option<f64>,
    /// The tolerance of the dimension
    pub tolerance: f64,
}

/// Parameters for defining an MBD Basic Dimension Annotation state which is measured between two positions in 3D
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationBasicDimension {
    /// Entity to measure the dimension from
    pub from_entity_id: Uuid,

    /// Normalized position within the entity to position the dimension from
    pub from_entity_pos: Point2d<f64>,

    /// Entity to measure the dimension to
    pub to_entity_id: Uuid,

    /// Normalized position within the entity to position the dimension to
    pub to_entity_pos: Point2d<f64>,

    /// Basic dimension parameters (symbol and tolerance)
    pub dimension: AnnotationMbdBasicDimension,

    /// Orientation plane.  The annotation will lie in this plane which is positioned about the leader position as its origin.
    pub plane_id: Uuid,

    /// 2D Position offset of the annotation within the plane.
    pub offset: Point2d<f64>,

    /// Number of decimal places to use when displaying tolerance and dimension values
    pub precision: u32,

    /// The scale of the font label in 3D space
    pub font_scale: f32,

    /// The point size of the fonts used to generate the annotation label.  Very large values can negatively affect performance.
    pub font_point_size: u32,

    /// The scale of the dimension arrows. Defaults to 1.
    #[serde(default = "one")]
    pub arrow_scale: f32,
}

/// Parameters for defining an MBD Feature Control Annotation state
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationFeatureControl {
    /// Entity to place the annotation leader from
    pub entity_id: Uuid,

    /// Normalized position within the entity to position the annotation leader from
    pub entity_pos: Point2d<f64>,

    /// Type of leader to use
    pub leader_type: AnnotationLineEnd,

    /// Basic dimensions
    pub dimension: Option<AnnotationMbdBasicDimension>,

    /// MBD Control frame for geometric control
    pub control_frame: Option<AnnotationMbdControlFrame>,

    /// Set if this annotation is defining a datum
    pub defined_datum: Option<char>,

    /// Prefix text which will appear before the basic dimension
    pub prefix: Option<String>,

    /// Suffix text which will appear after the basic dimension
    pub suffix: Option<String>,

    /// Orientation plane.  The annotation will lie in this plane which is positioned about the leader position as its origin.
    pub plane_id: Uuid,

    /// 2D Position offset of the annotation within the plane.
    pub offset: Point2d<f64>,

    /// Number of decimal places to use when displaying tolerance and dimension values
    pub precision: u32,

    /// The scale of the font label in 3D space
    pub font_scale: f32,

    /// The point size of the fonts used to generate the annotation label.  Very large values can negatively affect performance.
    pub font_point_size: u32,

    /// The scale of the leader (dot or arrow). Defaults to 1.
    #[serde(default = "one")]
    pub leader_scale: f32,
}

/// Parameters for defining an MBD Feature Tag Annotation state
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct AnnotationFeatureTag {
    /// Entity to place the annotation leader from
    pub entity_id: Uuid,

    /// Normalized position within the entity to position the annotation leader from
    pub entity_pos: Point2d<f64>,

    /// Type of leader to use
    pub leader_type: AnnotationLineEnd,

    /// Tag key
    pub key: String,

    /// Tag value
    pub value: String,

    /// Whether or not to display the key on the annotation label
    pub show_key: bool,

    /// Orientation plane.  The annotation will lie in this plane which is positioned about the leader position as its origin.
    pub plane_id: Uuid,

    /// 2D Position offset of the annotation within the plane.
    pub offset: Point2d<f64>,

    /// The scale of the font label in 3D space
    pub font_scale: f32,

    /// The point size of the fonts used to generate the annotation label.  Very large values can negatively affect performance.
    pub font_point_size: u32,

    /// The scale of the leader (dot or arrow). Defaults to 1.
    #[serde(default = "one")]
    pub leader_scale: f32,
}

/// The type of distance
/// Distances can vary depending on
/// the objects used as input.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case", tag = "type")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum DistanceType {
    /// Euclidean Distance.
    Euclidean {},
    /// The distance between objects along the specified axis
    OnAxis {
        /// Global axis
        axis: GlobalAxis,
    },
}

/// The type of origin
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case", tag = "type")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum OriginType {
    /// Local Origin (center of object bounding box).
    #[default]
    Local,
    /// Global Origin (0, 0, 0).
    Global,
    /// Custom Origin (user specified point).
    Custom {
        /// Custom origin point.
        origin: Point3d<f64>,
    },
}

/// An RGBA color
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct Color {
    /// Red
    pub r: f32,
    /// Green
    pub g: f32,
    /// Blue
    pub b: f32,
    /// Alpha
    pub a: f32,
}

impl Color {
    /// Assign the red, green, blue and alpha (transparency) channels.
    pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
        Self { r, g, b, a }
    }
}

/// Horizontal Text alignment
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum AnnotationTextAlignmentX {
    Left,
    Center,
    Right,
}

/// Vertical Text alignment
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum AnnotationTextAlignmentY {
    Bottom,
    Center,
    Top,
}

/// Annotation line end type
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum AnnotationLineEnd {
    None,
    Arrow,
    Dot,
}

/// The type of annotation
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum AnnotationType {
    /// 2D annotation type (screen or planar space)
    T2D,
    /// 3D annotation type
    T3D,
}

/// MBD standard
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum MbdStandard {
    /// ASME Y14.5 GD&T
    AsmeY14_5,
}

//SEE MIKE BEFORE MAKING ANY CHANGES TO THIS ENUM
/// MBD symbol type
#[allow(missing_docs)]
#[derive(
    Default,
    Display,
    FromStr,
    Copy,
    Eq,
    PartialEq,
    Debug,
    JsonSchema,
    Deserialize,
    Serialize,
    Sequence,
    Clone,
    Ord,
    PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[repr(u16)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum MbdSymbol {
    #[default]
    None = 0,
    ArcLength = 174,
    Between = 175,
    Degrees = 176,
    PlusMinus = 177,
    Angularity = 178,
    Cylindricity = 179,
    Roundness = 180,
    Concentricity = 181,
    Straightness = 182,
    Parallelism = 183,
    Flatness = 184,
    ProfileOfLine = 185,
    SurfaceProfile = 186,
    Symmetry = 187,
    Perpendicularity = 188,
    Runout = 189,
    TotalRunout = 190,
    Position = 191,
    CenterLine = 192,
    PartingLine = 193,
    IsoEnvelope = 195,
    IsoEnvelopeNonY145M = 196,
    FreeState = 197,
    StatisticalTolerance = 198,
    ContinuousFeature = 199,
    Independency = 200,
    Depth = 201,
    Start = 202,
    LeastCondition = 203,
    MaxCondition = 204,
    ConicalTaper = 205,
    Projected = 206,
    Slope = 207,
    Micro = 208,
    TangentPlane = 210,
    Unilateral = 211,
    SquareFeature = 212,
    Countersink = 213,
    SpotFace = 214,
    Target = 215,
    Diameter = 216,
    Radius = 217,
    SphericalRadius = 218,
    SphericalDiameter = 219,
    ControlledRadius = 220,
    BoxStart = 123,
    BoxBar = 162,
    BoxBarBetween = 124,
    LetterBackwardUnderline = 95,
    PunctuationBackwardUnderline = 92,
    ModifierBackwardUnderline = 126,
    NumericBackwardUnderline = 96,
    BoxEnd = 125,
    DatumUp = 166,
    DatumLeft = 168,
    DatumRight = 167,
    DatumDown = 165,
    DatumTriangle = 295,
    HalfSpace = 236,
    QuarterSpace = 237,
    EighthSpace = 238,
    ModifierSpace = 239,
}

/// The type of camera drag interaction.
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum CameraDragInteractionType {
    /// Camera pan
    Pan,
    /// Camera rotate (spherical camera revolve/orbit)
    Rotate,
    /// Camera rotate (trackball with 3 degrees of freedom)
    RotateTrackball,
    /// Camera zoom (increase or decrease distance to reference point center)
    Zoom,
}

/// A segment of a path.
/// Paths are composed of many segments.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case", tag = "type")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum PathSegment {
    /// A straight line segment.
    /// Goes from the current path "pen" to the given endpoint.
    Line {
        /// End point of the line.
        end: Point3d<LengthUnit>,
        ///Whether or not this line is a relative offset
        relative: bool,
    },
    /// A circular arc segment.
    /// Arcs can be drawn clockwise when start > end.
    Arc {
        /// Center of the circle
        center: Point2d<LengthUnit>,
        /// Radius of the circle
        radius: LengthUnit,
        /// Start of the arc along circle's perimeter.
        start: Angle,
        /// End of the arc along circle's perimeter.
        end: Angle,
        ///Whether or not this arc is a relative offset
        relative: bool,
    },
    /// A cubic bezier curve segment.
    /// Start at the end of the current line, go through control point 1 and 2, then end at a
    /// given point.
    Bezier {
        /// First control point.
        control1: Point3d<LengthUnit>,
        /// Second control point.
        control2: Point3d<LengthUnit>,
        /// Final control point.
        end: Point3d<LengthUnit>,
        ///Whether or not this bezier is a relative offset
        relative: bool,
    },
    /// Adds a tangent arc from current pen position with the given radius and angle.
    TangentialArc {
        /// Radius of the arc.
        /// Not to be confused with Raiders of the Lost Ark.
        radius: LengthUnit,
        /// Offset of the arc. Negative values will arc clockwise.
        offset: Angle,
    },
    /// Adds a tangent arc from current pen position to the new position.
    /// Arcs will choose a clockwise or counter-clockwise direction based on the arc end position.
    TangentialArcTo {
        /// Where the arc should end.
        /// Must lie in the same plane as the current path pen position.
        /// Must not be colinear with current path pen position.
        to: Point3d<LengthUnit>,
        /// 0 will be interpreted as none/null.
        angle_snap_increment: Option<Angle>,
    },
    ///Adds an arc from the current position that goes through the given interior point and ends at the given end position
    ArcTo {
        /// Interior point of the arc.
        interior: Point3d<LengthUnit>,
        /// End point of the arc.
        end: Point3d<LengthUnit>,
        ///Whether or not interior and end are relative to the previous path position
        relative: bool,
    },
    ///Adds a circular involute from the current position that goes through the given end_radius
    ///and is rotated around the current point by angle.
    CircularInvolute {
        ///The involute is described between two circles, start_radius is the radius of the inner
        ///circle.
        start_radius: LengthUnit,
        ///The involute is described between two circles, end_radius is the radius of the outer
        ///circle.
        end_radius: LengthUnit,
        ///The angle to rotate the involute by. A value of zero will produce a curve with a tangent
        ///along the x-axis at the start point of the curve.
        angle: Angle,
        ///If reverse is true, the segment will start
        ///from the end of the involute, otherwise it will start from that start.
        reverse: bool,
    },
    ///Adds an elliptical arc segment.
    Ellipse {
        /// The center point of the ellipse.
        center: Point2d<LengthUnit>,
        /// Major axis of the ellipse.
        major_axis: Point2d<LengthUnit>,
        /// Minor radius of the ellipse.
        minor_radius: LengthUnit,
        /// Start of the path along the perimeter of the ellipse.
        start_angle: Angle,
        /// End of the path along the perimeter of the ellipse.
        end_angle: Angle,
    },
    ///Adds a generic conic section specified by the end point, interior point and tangents at the
    ///start and end of the section.
    ConicTo {
        /// Interior point that lies on the conic.
        interior: Point2d<LengthUnit>,
        /// End point of the conic.
        end: Point2d<LengthUnit>,
        /// Tangent at the start of the conic.
        start_tangent: Point2d<LengthUnit>,
        /// Tangent at the end of the conic.
        end_tangent: Point2d<LengthUnit>,
        /// Whether or not the interior and end points are relative to the previous path position.
        relative: bool,
    },
}

/// An angle, with a specific unit.
#[derive(Clone, Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct Angle {
    /// What unit is the measurement?
    pub unit: UnitAngle,
    /// The size of the angle, measured in the chosen unit.
    pub value: f64,
}

impl Angle {
    /// Converts a given angle to degrees.
    pub fn to_degrees(self) -> f64 {
        match self.unit {
            UnitAngle::Degrees => self.value,
            UnitAngle::Radians => self.value.to_degrees(),
        }
    }
    /// Converts a given angle to radians.
    pub fn to_radians(self) -> f64 {
        match self.unit {
            UnitAngle::Degrees => self.value.to_radians(),
            UnitAngle::Radians => self.value,
        }
    }
    /// Create an angle in degrees.
    pub const fn from_degrees(value: f64) -> Self {
        Self {
            unit: UnitAngle::Degrees,
            value,
        }
    }
    /// Create an angle in radians.
    pub const fn from_radians(value: f64) -> Self {
        Self {
            unit: UnitAngle::Radians,
            value,
        }
    }
    /// 360 degrees.
    pub const fn turn() -> Self {
        Self::from_degrees(360.0)
    }
    /// 180 degrees.
    pub const fn half_circle() -> Self {
        Self::from_degrees(180.0)
    }
    /// 90 degrees.
    pub const fn quarter_circle() -> Self {
        Self::from_degrees(90.0)
    }
    /// 0 degrees.
    pub const fn zero() -> Self {
        Self::from_degrees(0.0)
    }
}

/// 0 degrees.
impl Default for Angle {
    /// 0 degrees.
    fn default() -> Self {
        Self::zero()
    }
}

impl PartialOrd for Angle {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        match (self.unit, other.unit) {
            // Avoid unnecessary floating point operations.
            (UnitAngle::Degrees, UnitAngle::Degrees) => self.value.partial_cmp(&other.value),
            (UnitAngle::Radians, UnitAngle::Radians) => self.value.partial_cmp(&other.value),
            _ => self.to_degrees().partial_cmp(&other.to_degrees()),
        }
    }
}

impl std::ops::Add for Angle {
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        Self {
            unit: UnitAngle::Degrees,
            value: self.to_degrees() + rhs.to_degrees(),
        }
    }
}

impl std::ops::AddAssign for Angle {
    fn add_assign(&mut self, rhs: Self) {
        match self.unit {
            UnitAngle::Degrees => {
                self.value += rhs.to_degrees();
            }
            UnitAngle::Radians => {
                self.value += rhs.to_radians();
            }
        }
    }
}

/// The type of scene selection change
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum SceneSelectionType {
    /// Replaces the selection
    Replace,
    /// Adds to the selection
    Add,
    /// Removes from the selection
    Remove,
}

/// The type of scene's active tool
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum SceneToolType {
    CameraRevolve,
    Select,
    Move,
    SketchLine,
    SketchTangentialArc,
    SketchCurve,
    SketchCurveMod,
}

/// The path component constraint bounds type
#[allow(missing_docs)]
#[derive(
    Display,
    FromStr,
    Copy,
    Eq,
    PartialEq,
    Debug,
    JsonSchema,
    Deserialize,
    Serialize,
    Sequence,
    Clone,
    Ord,
    PartialOrd,
    Default,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum PathComponentConstraintBound {
    #[default]
    Unconstrained,
    PartiallyConstrained,
    FullyConstrained,
}

/// The path component constraint type
#[allow(missing_docs)]
#[derive(
    Display,
    FromStr,
    Copy,
    Eq,
    PartialEq,
    Debug,
    JsonSchema,
    Deserialize,
    Serialize,
    Sequence,
    Clone,
    Ord,
    PartialOrd,
    Default,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum PathComponentConstraintType {
    #[default]
    Unconstrained,
    Vertical,
    Horizontal,
    EqualLength,
    Parallel,
    AngleBetween,
}

/// The path component command type (within a Path)
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum PathCommand {
    MoveTo,
    LineTo,
    BezCurveTo,
    NurbsCurveTo,
    AddArc,
}

/// The type of entity
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[repr(u8)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum EntityType {
    Entity,
    Object,
    Path,
    Curve,
    Solid2D,
    Solid3D,
    Edge,
    Face,
    Plane,
    Vertex,
}

/// The type of Curve (embedded within path)
#[allow(missing_docs)]
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum CurveType {
    Line,
    Arc,
    Nurbs,
}

/// A file to be exported to the client.
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Builder)]
#[cfg_attr(feature = "python", pyo3::pyclass, pyo3_stub_gen::derive::gen_stub_pyclass)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct ExportFile {
    /// The name of the file.
    pub name: String,
    /// The contents of the file, base64 encoded.
    pub contents: crate::base64::Base64Data,
}

#[cfg(feature = "python")]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
#[pyo3::pymethods]
impl ExportFile {
    #[getter]
    fn contents(&self) -> Vec<u8> {
        self.contents.0.clone()
    }

    #[getter]
    fn name(&self) -> String {
        self.name.clone()
    }
}

/// The valid types of output file formats.
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
)]
#[serde(rename_all = "lowercase")]
#[display(style = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(feature = "python", pyo3::pyclass, pyo3_stub_gen::derive::gen_stub_pyclass_enum)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum FileExportFormat {
    /// Autodesk Filmbox (FBX) format. <https://en.wikipedia.org/wiki/FBX>
    Fbx,
    /// Binary glTF 2.0.
    ///
    /// This is a single binary with .glb extension.
    ///
    /// This is better if you want a compressed format as opposed to the human readable
    /// glTF that lacks compression.
    Glb,
    /// glTF 2.0.
    /// Embedded glTF 2.0 (pretty printed).
    ///
    /// Single JSON file with .gltf extension binary data encoded as
    /// base64 data URIs.
    ///
    /// The JSON contents are pretty printed.
    ///
    /// It is human readable, single file, and you can view the
    /// diff easily in a git commit.
    Gltf,
    /// The OBJ file format. <https://en.wikipedia.org/wiki/Wavefront_.obj_file>
    /// It may or may not have an an attached material (mtl // mtllib) within the file,
    /// but we interact with it as if it does not.
    Obj,
    /// The PLY file format. <https://en.wikipedia.org/wiki/PLY_(file_format)>
    Ply,
    /// The STEP file format. <https://en.wikipedia.org/wiki/ISO_10303-21>
    Step,
    /// The STL file format. <https://en.wikipedia.org/wiki/STL_(file_format)>
    Stl,
}

/// The valid types of 2D output file formats.
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
)]
#[serde(rename_all = "lowercase")]
#[display(style = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum FileExportFormat2d {
    /// AutoCAD drawing interchange format.
    Dxf,
}

/// The valid types of source file formats.
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
)]
#[serde(rename_all = "lowercase")]
#[display(style = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum FileImportFormat {
    /// Autodesk Filmbox (FBX) format. <https://en.wikipedia.org/wiki/FBX>
    Fbx,
    /// glTF 2.0.
    Gltf,
    /// The OBJ file format. <https://en.wikipedia.org/wiki/Wavefront_.obj_file>
    /// It may or may not have an an attached material (mtl // mtllib) within the file,
    /// but we interact with it as if it does not.
    Obj,
    /// The PLY file format. <https://en.wikipedia.org/wiki/PLY_(file_format)>
    Ply,
    /// SolidWorks part (SLDPRT) format.
    Sldprt,
    /// The STEP file format. <https://en.wikipedia.org/wiki/ISO_10303-21>
    Step,
    /// The STL file format. <https://en.wikipedia.org/wiki/STL_(file_format)>
    Stl,
}

/// The type of error sent by the KittyCAD graphics engine.
#[derive(Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum EngineErrorCode {
    /// User requested something geometrically or graphically impossible.
    /// Don't retry this request, as it's inherently impossible. Instead, read the error message
    /// and change your request.
    BadRequest = 1,
    /// Graphics engine failed to complete request, consider retrying
    InternalEngine,
}

impl From<EngineErrorCode> for http::StatusCode {
    fn from(e: EngineErrorCode) -> Self {
        match e {
            EngineErrorCode::BadRequest => Self::BAD_REQUEST,
            EngineErrorCode::InternalEngine => Self::INTERNAL_SERVER_ERROR,
        }
    }
}

/// What kind of blend to do
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub enum BlendType {
    /// Use the tangent of the surfaces to calculate the blend.
    #[default]
    Tangent,
}

/// Body type determining if the operation will create a manifold (solid) body or a non-manifold collection of surfaces.
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum BodyType {
    ///Defines a body that is manifold.
    #[default]
    Solid,
    ///Defines a body that is non-manifold (an open collection of connected surfaces).
    Surface,
}

/// Extrusion method determining if the extrusion will be part of the existing object or an
/// entirely new object.
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum ExtrudeMethod {
    /// Create a new object that is not connected to the object it is extruded from. This will
    /// result in two objects after the operation.
    New,
    /// This extrusion will be part of object it is extruded from. This will result in one object
    /// after the operation.
    #[default]
    Merge,
}

/// Type of reference geometry to extrude to.
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum ExtrudeReference {
    /// Extrudes along the normal of the top face until it is as close to the entity as possible.
    /// An entity can be a solid, a path, a face, etc.
    EntityReference {
        /// The UUID of the entity to extrude to.
        entity_id: Uuid,
    },
    /// Extrudes until the top face is as close as possible to this given axis.
    Axis {
        /// The axis to extrude to.
        axis: Point3d<f64>,
        /// Point the axis goes through.
        /// Defaults to (0, 0, 0).
        #[serde(default)]
        point: Point3d<LengthUnit>,
    },
    /// Extrudes until the top face is as close as possible to this given point.
    Point {
        /// The point to extrude to.
        point: Point3d<LengthUnit>,
    },
}

/// IDs for the extruded faces.
#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema, Clone, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct ExtrudedFaceInfo {
    /// The face made from the original 2D shape being extruded.
    /// If the solid is extruded from a shape which already has an ID
    /// (e.g. extruding something which was sketched on a face), this
    /// doesn't need to be sent.
    pub bottom: Option<Uuid>,
    /// Top face of the extrusion (parallel and further away from the original 2D shape being extruded).
    pub top: Uuid,
    /// Any intermediate sides between the top and bottom.
    pub sides: Vec<SideFace>,
}

/// IDs for a side face, extruded from the path of some sketch/2D shape.
#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema, Clone, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct SideFace {
    /// ID of the path this face is being extruded from.
    pub path_id: Uuid,
    /// Desired ID for the resulting face.
    pub face_id: Uuid,
}

/// Camera settings including position, center, fov etc
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct CameraSettings {
    ///Camera position (vantage)
    pub pos: Point3d,

    ///Camera's look-at center (center-pos gives viewing vector)
    pub center: Point3d,

    ///Camera's world-space up vector
    pub up: Point3d,

    ///The Camera's orientation (in the form of a quaternion)
    pub orientation: Quaternion,

    ///Camera's field-of-view angle (if ortho is false)
    pub fov_y: Option<f32>,

    ///The camera's ortho scale (derived from viewing distance if ortho is true)
    pub ortho_scale: Option<f32>,

    ///Whether or not the camera is in ortho mode
    pub ortho: bool,
}

#[allow(missing_docs)]
#[repr(u8)]
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum WorldCoordinateSystem {
    #[default]
    RightHandedUpZ,
    RightHandedUpY,
}

#[allow(missing_docs)]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct CameraViewState {
    pub pivot_rotation: Quaternion,
    pub pivot_position: Point3d,
    pub eye_offset: f32,
    pub fov_y: f32,
    pub ortho_scale_factor: f32,
    pub is_ortho: bool,
    pub ortho_scale_enabled: bool,
    pub world_coord_system: WorldCoordinateSystem,
}

impl Default for CameraViewState {
    fn default() -> Self {
        CameraViewState {
            pivot_rotation: Default::default(),
            pivot_position: Default::default(),
            eye_offset: 10.0,
            fov_y: 45.0,
            ortho_scale_factor: 1.6,
            is_ortho: false,
            ortho_scale_enabled: true,
            world_coord_system: Default::default(),
        }
    }
}

#[cfg(feature = "cxx")]
impl_extern_type! {
    [Trivial]
    CameraViewState = "Endpoints::CameraViewState"
}

impl From<CameraSettings> for crate::output::DefaultCameraZoom {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}
impl From<CameraSettings> for crate::output::CameraDragMove {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}
impl From<CameraSettings> for crate::output::CameraDragEnd {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}
impl From<CameraSettings> for crate::output::DefaultCameraGetSettings {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}
impl From<CameraSettings> for crate::output::ZoomToFit {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}
impl From<CameraSettings> for crate::output::OrientToFace {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}
impl From<CameraSettings> for crate::output::ViewIsometric {
    fn from(settings: CameraSettings) -> Self {
        Self { settings }
    }
}

/// Defines a perspective view.
#[derive(Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, PartialOrd, Default, Builder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct PerspectiveCameraParameters {
    /// Camera frustum vertical field of view.
    pub fov_y: Option<f32>,
    /// Camera frustum near plane.
    pub z_near: Option<f32>,
    /// Camera frustum far plane.
    pub z_far: Option<f32>,
}

/// A type of camera movement applied after certain camera operations
#[derive(
    Default,
    Display,
    FromStr,
    Copy,
    Eq,
    PartialEq,
    Debug,
    JsonSchema,
    Deserialize,
    Serialize,
    Sequence,
    Clone,
    Ord,
    PartialOrd,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum CameraMovement {
    /// Adjusts the camera position during the camera operation
    #[default]
    Vantage,
    /// Keeps the camera position in place
    None,
}

/// The global axes.
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum GlobalAxis {
    /// The X axis
    X,
    /// The Y axis
    Y,
    /// The Z axis
    Z,
}

/// Possible types of faces which can be extruded from a 3D solid.
#[derive(
    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[repr(u8)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum ExtrusionFaceCapType {
    /// Uncapped.
    None,
    /// Capped on top.
    Top,
    /// Capped below.
    Bottom,
    /// Capped on both ends.
    Both,
}

/// Post effect type
#[allow(missing_docs)]
#[derive(
    Display,
    FromStr,
    Copy,
    Eq,
    PartialEq,
    Debug,
    JsonSchema,
    Deserialize,
    Serialize,
    Sequence,
    Clone,
    Ord,
    PartialOrd,
    Default,
)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum PostEffectType {
    Phosphor,
    Ssao,
    #[default]
    NoEffect,
}

// Enum: Connect Rust Enums to Cpp
// add our native c++ names for our cxx::ExternType implementation
#[cfg(feature = "cxx")]
impl_extern_type! {
    [Trivial]
    // File
    FileImportFormat = "Enums::_FileImportFormat"
    FileExportFormat = "Enums::_FileExportFormat"
    // Camera
    CameraDragInteractionType = "Enums::_CameraDragInteractionType"
    // Scene
    SceneSelectionType = "Enums::_SceneSelectionType"
    SceneToolType = "Enums::_SceneToolType"
    BlendType = "Enums::_BlendType"
    BodyType = "Enums::_BodyType"
    EntityType = "Enums::_EntityType"
    AnnotationType = "Enums::_AnnotationType"
    AnnotationTextAlignmentX = "Enums::_AnnotationTextAlignmentX"
    AnnotationTextAlignmentY = "Enums::_AnnotationTextAlignmentY"
    AnnotationLineEnd = "Enums::_AnnotationLineEnd"
    MbdStandard = "Enums::_MBDStandard"
    MbdSymbol = "Enums::_MBDSymbol"

    CurveType = "Enums::_CurveType"
    PathCommand = "Enums::_PathCommand"
    PathComponentConstraintBound = "Enums::_PathComponentConstraintBound"
    PathComponentConstraintType = "Enums::_PathComponentConstraintType"
    ExtrusionFaceCapType  = "Enums::_ExtrusionFaceCapType"

    // Utils
    EngineErrorCode = "Enums::_ErrorCode"
    GlobalAxis = "Enums::_GlobalAxis"
    OriginType = "Enums::_OriginType"

    // Graphics engine
    PostEffectType = "Enums::_PostEffectType"
}

fn bool_true() -> bool {
    true
}
fn same_scale() -> Point3d<f64> {
    Point3d::uniform(1.0)
}

fn z_axis() -> Point3d<f64> {
    Point3d { x: 0.0, y: 0.0, z: 1.0 }
}

impl ExtrudedFaceInfo {
    /// Converts from the representation used in the Extrude modeling command,
    /// to a flat representation.
    pub fn list_faces(self) -> Vec<ExtrusionFaceInfo> {
        let mut face_infos: Vec<_> = self
            .sides
            .into_iter()
            .map(|side| ExtrusionFaceInfo {
                curve_id: Some(side.path_id),
                face_id: Some(side.face_id),
                cap: ExtrusionFaceCapType::None,
            })
            .collect();
        face_infos.push(ExtrusionFaceInfo {
            curve_id: None,
            face_id: Some(self.top),
            cap: ExtrusionFaceCapType::Top,
        });
        if let Some(bottom) = self.bottom {
            face_infos.push(ExtrusionFaceInfo {
                curve_id: None,
                face_id: Some(bottom),
                cap: ExtrusionFaceCapType::Bottom,
            });
        }
        face_infos
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_angle_comparison() {
        let a = Angle::from_degrees(90.0);
        assert!(a < Angle::from_degrees(91.0));
        assert!(a > Angle::from_degrees(89.0));
        assert!(a <= Angle::from_degrees(90.0));
        assert!(a >= Angle::from_degrees(90.0));
        let b = Angle::from_radians(std::f64::consts::FRAC_PI_4);
        assert!(b < Angle::from_radians(std::f64::consts::FRAC_PI_2));
        assert!(b > Angle::from_radians(std::f64::consts::FRAC_PI_8));
        assert!(b <= Angle::from_radians(std::f64::consts::FRAC_PI_4));
        assert!(b >= Angle::from_radians(std::f64::consts::FRAC_PI_4));
        // Mixed units.
        assert!(a > b);
        assert!(a >= b);
        assert!(b < a);
        assert!(b <= a);
        let c = Angle::from_radians(std::f64::consts::FRAC_PI_2 * 3.0);
        assert!(a < c);
        assert!(a <= c);
        assert!(c > a);
        assert!(c >= a);
    }
}

/// How a property of an object should be transformed.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema, Builder)]
#[schemars(rename = "TransformByFor{T}")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct TransformBy<T> {
    /// The scale, or rotation, or translation.
    pub property: T,
    /// If true, overwrite the previous value with this.
    /// If false, the previous value will be modified.
    /// E.g. when translating, `set=true` will set a new location,
    /// and `set=false` will translate the current location by the given X/Y/Z.
    pub set: bool,
    /// What to use as the origin for the transformation.
    #[serde(default)]
    #[builder(default)]
    pub origin: OriginType,
}

impl<T> TransformBy<T> {
    /// Get the origin of this transformation.
    /// Reads from the `origin` field if it's set, otherwise
    /// falls back to the `is_local` field.
    pub fn get_origin(&self) -> OriginType {
        self.origin
    }
}

/// Container that holds a translate, rotate and scale.
/// Defaults to no change, everything stays the same (i.e. the identity function).
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, Default, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct ComponentTransform {
    /// Translate component of the transform.
    pub translate: Option<TransformBy<Point3d<LengthUnit>>>,
    /// Rotate component of the transform.
    /// The rotation is specified as a roll, pitch, yaw.
    pub rotate_rpy: Option<TransformBy<Point3d<f64>>>,
    /// Rotate component of the transform.
    /// The rotation is specified as an axis and an angle (xyz are the components of the axis, w is
    /// the angle in degrees).
    pub rotate_angle_axis: Option<TransformBy<Point4d<f64>>>,
    /// Scale component of the transform.
    pub scale: Option<TransformBy<Point3d<f64>>>,
}

///If bidirectional or symmetric operations are needed this enum encapsulates the required
///information.
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum Opposite<T> {
    /// No opposite. The operation will only occur on one side.
    #[default]
    None,
    /// Operation will occur from both sides, with the same value.
    Symmetric,
    /// Operation will occur from both sides, with this value for the opposite.
    Other(T),
}

impl<T: JsonSchema> JsonSchema for Opposite<T> {
    fn schema_name() -> String {
        format!("OppositeFor{}", T::schema_name())
    }

    fn schema_id() -> std::borrow::Cow<'static, str> {
        std::borrow::Cow::Owned(format!("{}::Opposite<{}>", module_path!(), T::schema_id()))
    }

    fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
        SchemaObject {
            instance_type: Some(schemars::schema::InstanceType::String.into()),
            ..Default::default()
        }
        .into()
    }
}

/// What strategy (algorithm) should be used for cutting?
/// Defaults to Automatic.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum CutStrategy {
    /// Basic fillet cut. This has limitations, like the filletted edges
    /// can't touch each other. But it's very fast and simple.
    Basic,
    /// More complicated fillet cut. It works for more use-cases, like
    /// edges that touch each other. But it's slower than the Basic method.
    Csg,
    /// Tries the Basic method, and if that doesn't work, tries the CSG strategy.
    #[default]
    Automatic,
}

/// What is the given geometry relative to?
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum RelativeTo {
    /// Local/relative to a position centered within the plane being sketched on
    #[default]
    SketchPlane,
    /// Local/relative to the trajectory curve
    TrajectoryCurve,
}

/// The region a user clicked on.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct SelectedRegion {
    /// First segment to follow to find the region.
    pub segment: Uuid,
    /// Second segment to follow to find the region.
    /// Intersects the first segment.
    pub intersection_segment: Uuid,
    /// At which intersection between `segment` and `intersection_segment`
    /// should we stop following the `segment` and start following `intersection_segment`?
    /// Defaults to -1, which means the last intersection.
    #[serde(default = "negative_one")]
    pub intersection_index: i32,
    /// By default (when this is false), curve counterclockwise at intersections.
    /// If this is true, instead curve clockwise.
    #[serde(default)]
    pub curve_clockwise: bool,
}

impl Default for SelectedRegion {
    fn default() -> Self {
        Self {
            segment: Default::default(),
            intersection_segment: Default::default(),
            intersection_index: -1,
            curve_clockwise: Default::default(),
        }
    }
}

/// An edge id and an upper and lower percentage bound of the edge.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct FractionOfEdge {
    /// The id of the edge
    pub edge_id: Uuid,
    /// A value between [0.0, 1.0] (default 0.0) that is a percentage along the edge. This bound
    /// will control how much of the edge is used during the blend.
    /// If lower_bound is larger than upper_bound, the edge is effectively "flipped".
    #[serde(default)]
    #[builder(default)]
    #[schemars(range(min = 0, max = 1))]
    pub lower_bound: f32,
    /// A value between [0.0, 1.0] (default 1.0) that is a percentage along the edge. This bound
    /// will control how much of the edge is used during the blend.
    /// If lower_bound is larger than upper_bound, the edge is effectively "flipped".
    #[serde(default = "one")]
    #[builder(default = one())]
    #[schemars(range(min = 0, max = 1))]
    pub upper_bound: f32,
}

/// An object id, that corresponds to a surface body, and a list of edges of the surface.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct SurfaceEdgeReference {
    /// The id of the body.
    pub object_id: Uuid,
    /// A list of the edge ids that belong to the body.
    pub edges: Vec<FractionOfEdge>,
}

/// List of bodies that were created by an operation.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct BodiesCreated {
    /// All bodies created by this operation.
    pub bodies: Vec<BodyCreated>,
}

impl BodiesCreated {
    /// Are there any bodies in this list?
    pub fn is_empty(&self) -> bool {
        self.bodies.is_empty()
    }
}

/// List of bodies that were updated by an operation.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct BodiesUpdated {
    /// All bodies created by this operation.
    pub bodies: Vec<BodyUpdated>,
}

impl BodiesUpdated {
    /// Are there any bodies in this list?
    pub fn is_empty(&self) -> bool {
        self.bodies.is_empty()
    }
}

/// Details of a body that was created.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct BodyCreated {
    /// The body's ID.
    pub id: Uuid,
    /// Surfaces this body contains.
    pub surfaces: Vec<SurfaceCreated>,
}

/// Details of a body that was updated.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct BodyUpdated {
    /// The body's ID.
    pub id: Uuid,
    /// Surfaces added to this body.
    pub surfaces: Vec<SurfaceCreated>,
}

/// Details of a surface that was created under some body.
#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct SurfaceCreated {
    /// The surface's ID.
    pub id: Uuid,
    /// Which number face of the parent body is this?
    pub primitive_face_index: u32,
    /// Which segment IDs was this surface swept from?
    pub from_segments: Vec<Uuid>,
}

/// Region-creation algorithm version.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum RegionVersion {
    /// The original region creation method. This should NOT be used anymore,
    /// but is maintained to avoid breaking old models.
    #[default]
    V0,
    /// Fixes the bug in V0 where creating a region would shuffle the mapping
    /// from segment names/IDs to actual segment geometry.
    V1,
}

impl From<BodyCreated> for BodyUpdated {
    fn from(body: BodyCreated) -> Self {
        Self {
            id: body.id,
            surfaces: body.surfaces,
        }
    }
}

impl From<BodyUpdated> for BodyCreated {
    fn from(body: BodyUpdated) -> Self {
        Self {
            id: body.id,
            surfaces: body.surfaces,
        }
    }
}

impl From<BodiesCreated> for BodiesUpdated {
    fn from(bodies: BodiesCreated) -> Self {
        Self {
            bodies: bodies.bodies.into_iter().map(Into::into).collect(),
        }
    }
}

impl From<BodiesUpdated> for BodiesCreated {
    fn from(bodies: BodiesUpdated) -> Self {
        Self {
            bodies: bodies.bodies.into_iter().map(Into::into).collect(),
        }
    }
}

fn one() -> f32 {
    1.0
}