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
use enum_iterator::Sequence;
use parse_display_derive::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg(feature = "cxx")]
use crate::impl_extern_type;
use crate::{length_unit::LengthUnit, units::UnitAngle};
/// What kind of cut to do
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum CutType {
/// Round off an edge.
#[default]
Fillet,
/// Cut away an edge.
Chamfer,
}
/// A rotation defined by an axis, origin of rotation, and an angle.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
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, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub struct Transform {
/// Translate the replica this far along each dimension.
/// Defaults to zero vector (i.e. same position as the original).
#[serde(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")]
pub scale: Point3d<f64>,
/// Rotate the replica about the specified rotation axis and origin.
/// Defaults to no rotation.
#[serde(default)]
pub rotation: Rotation,
/// Whether to replicate the original solid in this instance.
#[serde(default = "bool_true")]
pub replicate: bool,
}
/// Options for annotations
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
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>>,
}
/// Options for annotation text
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
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, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
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,
}
/// The type of distance
/// Distances can vary depending on
/// the objects used as input.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case", tag = "type")]
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, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case", tag = "type")]
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, Serialize, Deserialize, JsonSchema)]
pub struct Color {
/// Red
pub r: f32,
/// Green
pub g: f32,
/// Blue
pub b: f32,
/// Alpha
pub a: f32,
}
/// Horizontal Text alignment
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
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")]
pub enum AnnotationTextAlignmentY {
Bottom,
Center,
Top,
}
/// A point in 3D space
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Default)]
#[serde(rename = "Point3d")]
#[serde(rename_all = "snake_case")]
pub struct Point3d<T = f32> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
#[allow(missing_docs)]
pub z: T,
}
impl<T> Point3d<T> {
/// Add the given `z` component to a 2D point to produce a 3D point.
pub fn from_2d(Point2d { x, y }: Point2d<T>, z: T) -> Self {
Self { x, y, z }
}
/// Takes some closure, and calls it on each component of this point.
/// # Examples
/// ```
/// use kittycad_modeling_cmds::shared::Point3d;
/// let p0 = Point3d{x: 1.0, y: 1.0, z: 1.0};
/// assert_eq!(p0.map(|n| n*2.0), Point3d{x: 2.0, y: 2.0, z:2.0});
/// ```
pub fn map<U, F>(self, mut f: F) -> Point3d<U>
where
F: FnMut(T) -> U,
{
let Self { x, y, z } = self;
Point3d {
x: f(x),
y: f(y),
z: f(z),
}
}
}
/// 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")]
pub enum AnnotationLineEnd {
None,
Arrow,
}
/// The type of annotation
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum AnnotationType {
/// 2D annotation type (screen or planar space)
T2D,
/// 3D annotation type
T3D,
}
/// The type of camera drag interaction.
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum CameraDragInteractionType {
/// Camera pan
Pan,
/// Camera rotate (revolve/orbit)
Rotate,
/// 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")]
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>,
},
}
/// A point in homogeneous (4D) space
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[serde(rename = "Point4d")]
#[serde(rename_all = "snake_case")]
pub struct Point4d<T = f32> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
#[allow(missing_docs)]
pub z: T,
#[allow(missing_docs)]
pub w: T,
}
impl<T> Point2d<T>
where
T: Copy,
{
/// Make a point where all components have the given value.
pub fn uniform(value: T) -> Self {
Self { x: value, y: value }
}
}
impl<T> Point3d<T>
where
T: Copy,
{
/// Make a point where all components have the given value.
pub fn uniform(value: T) -> Self {
Self {
x: value,
y: value,
z: value,
}
}
}
impl<T> Point4d<T> {
/// Takes some closure, and calls it on each component of this point.
/// # Examples
/// ```
/// use kittycad_modeling_cmds::shared::Point4d;
/// let p0 = Point4d{x: 1.0, y: 1.0, z: 1.0, w: 1.0};
/// assert_eq!(p0.map(|n| n*2.0), Point4d{x: 2.0, y: 2.0, z: 2.0, w: 2.0});
/// ```
pub fn map<U, F>(self, mut f: F) -> Point4d<U>
where
F: FnMut(T) -> U,
{
let Self { x, y, z, w } = self;
Point4d {
x: f(x),
y: f(y),
z: f(z),
w: f(w),
}
}
}
impl<T> Point4d<T>
where
T: Copy,
{
/// Make a point where all components have the given value.
pub fn uniform(value: T) -> Self {
Self {
x: value,
y: value,
z: value,
w: value,
}
}
/// Make a point where the X, Y and Z components have the same value,
/// but the W component has a different one.
pub fn uniform_3d(xyz: T, w: T) -> Self {
Self {
x: xyz,
y: xyz,
z: xyz,
w,
}
}
}
impl From<euler::Vec3> for Point3d<f32> {
fn from(v: euler::Vec3) -> Self {
Self { x: v.x, y: v.y, z: v.z }
}
}
impl<T> From<[T; 3]> for Point3d<T> {
fn from([x, y, z]: [T; 3]) -> Self {
Self { x, y, z }
}
}
impl<T: PartialEq> PartialEq for Point4d<T> {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y && self.z == other.z && self.w == other.w
}
}
/// A point in 2D space
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename = "Point2d")]
#[serde(rename_all = "snake_case")]
pub struct Point2d<T = f32> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
}
impl<T: PartialEq> PartialEq for Point2d<T> {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y
}
}
impl<T> From<[T; 2]> for Point2d<T> {
fn from([x, y]: [T; 2]) -> Self {
Self { x, y }
}
}
macro_rules! impl_arithmetic {
($typ:ident, $op:ident, $method:ident, $($i:ident),*) => {
impl<T> std::ops::$op<$typ<T>> for $typ<T>
where
T: std::ops::$op<Output = T>,
{
type Output = $typ<T>;
fn $method(self, rhs: $typ<T>) -> Self::Output {
Self {
$(
$i: self.$i.$method(rhs.$i),
)*
}
}
}
};
}
impl_arithmetic!(Point2d, Add, add, x, y);
impl_arithmetic!(Point3d, Add, add, x, y, z);
impl_arithmetic!(Point2d, Sub, sub, x, y);
impl_arithmetic!(Point3d, Sub, sub, x, y, z);
impl_arithmetic!(Point2d, Mul, mul, x, y);
impl_arithmetic!(Point3d, Mul, mul, x, y, z);
impl_arithmetic!(Point2d, Div, div, x, y);
impl_arithmetic!(Point3d, Div, div, x, y, z);
impl<T> Point2d<T> {
/// Add the given `z` component to a 2D point to produce a 3D point.
pub fn with_z(self, z: T) -> Point3d<T> {
let Self { x, y } = self;
Point3d { x, y, z }
}
/// Takes some closure, and calls it on each component of this point.
/// # Examples
/// ```
/// use kittycad_modeling_cmds::shared::Point2d;
/// let p0 = Point2d{x: 1.0, y: 1.0};
/// assert_eq!(p0.map(|n| n*2.0), Point2d{x: 2.0, y: 2.0});
/// ```
pub fn map<U, F>(self, mut f: F) -> Point2d<U>
where
F: FnMut(T) -> U,
{
let Self { x, y } = self;
Point2d { x: f(x), y: f(y) }
}
}
///A quaternion
pub type Quaternion = Point4d;
impl Default for Quaternion {
/// (0, 0, 0, 1)
fn default() -> Self {
Self {
x: 0.0,
y: 0.0,
z: 0.0,
w: 1.0,
}
}
}
/// An angle, with a specific unit.
#[derive(Clone, Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize)]
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,
}
}
}
impl Angle {
/// 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::from_degrees(0.0)
}
}
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")]
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")]
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")]
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")]
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")]
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")]
#[repr(u8)]
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")]
pub enum CurveType {
Line,
Arc,
Nurbs,
}
/// A file to be exported to the client.
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
pub struct ExportFile {
/// The name of the file.
pub name: String,
/// The contents of the file, base64 encoded.
pub contents: crate::base64::Base64Data,
}
/// 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")]
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 source file formats.
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
)]
#[serde(rename_all = "lowercase")]
#[display(style = "lowercase")]
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")]
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,
}
}
}
/// Camera settings including position, center, fov etc
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
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,
}
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::ViewIsometric {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
/// Defines a perspective view.
#[derive(Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, PartialOrd, Default)]
#[serde(rename_all = "snake_case")]
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>,
}
/// The global axes.
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
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")]
#[repr(u8)]
pub enum ExtrusionFaceCapType {
/// Uncapped.
None,
/// Capped on top.
Top,
/// Capped below.
Bottom,
}
/// 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")]
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"
EntityType = "Enums::_EntityType"
AnnotationType = "Enums::_AnnotationType"
AnnotationTextAlignmentX = "Enums::_AnnotationTextAlignmentX"
AnnotationTextAlignmentY = "Enums::_AnnotationTextAlignmentY"
AnnotationLineEnd = "Enums::_AnnotationLineEnd"
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> {
let p = 1.0;
Point3d { x: p, y: p, z: p }
}
fn z_axis() -> Point3d<f64> {
Point3d { x: 0.0, y: 0.0, z: 1.0 }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_math() {
let actual = Point2d { x: 1.0, y: 2.0 } + Point2d { x: 10.0, y: 20.0 };
let expected = Point2d { x: 11.0, y: 22.0 };
assert_eq!(actual, expected);
}
}