Skip to content

Commit be2f7fd

Browse files
committed
API work for Translate By Feature.
Part of KittyCAD/modeling-app#9097
1 parent f4d8956 commit be2f7fd

File tree

2 files changed

+128
-5
lines changed

2 files changed

+128
-5
lines changed

modeling-cmds/openapi/api.json

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7376,13 +7376,17 @@
73767376
"translate": {
73777377
"description": "Translate the replica this far along each dimension. Defaults to zero vector (i.e. same position as the original).",
73787378
"default": {
7379-
"x": 0.0,
7380-
"y": 0.0,
7381-
"z": 0.0
7379+
"point3d": {
7380+
"point": {
7381+
"x": 0.0,
7382+
"y": 0.0,
7383+
"z": 0.0
7384+
}
7385+
}
73827386
},
73837387
"allOf": [
73847388
{
7385-
"$ref": "#/components/schemas/Point3d"
7389+
"$ref": "#/components/schemas/TranslateBy"
73867390
}
73877391
]
73887392
}
@@ -7464,6 +7468,83 @@
74647468
"set"
74657469
]
74667470
},
7471+
"TranslateBy": {
7472+
"description": "How to translate in space.",
7473+
"oneOf": [
7474+
{
7475+
"description": "Translate this much in each dimension.",
7476+
"type": "object",
7477+
"properties": {
7478+
"point3d": {
7479+
"type": "object",
7480+
"properties": {
7481+
"point": {
7482+
"description": "Which vector to translate along.",
7483+
"allOf": [
7484+
{
7485+
"$ref": "#/components/schemas/Point3d"
7486+
}
7487+
]
7488+
}
7489+
},
7490+
"required": [
7491+
"point"
7492+
]
7493+
}
7494+
},
7495+
"required": [
7496+
"point3d"
7497+
],
7498+
"additionalProperties": false
7499+
},
7500+
{
7501+
"description": "Translate along this edge or path segment.\n\nIf the edge is a circle, translates along the normal vector of this circle, going through the circle's center.\n\nIf the edge is linear, translates along that line's vector.",
7502+
"type": "object",
7503+
"properties": {
7504+
"edge": {
7505+
"type": "object",
7506+
"properties": {
7507+
"id": {
7508+
"description": "Which edge to translate along.",
7509+
"type": "string",
7510+
"format": "uuid"
7511+
}
7512+
},
7513+
"required": [
7514+
"id"
7515+
]
7516+
}
7517+
},
7518+
"required": [
7519+
"edge"
7520+
],
7521+
"additionalProperties": false
7522+
},
7523+
{
7524+
"description": "Translate along this face or sketch.\n\nIf the sketch is circular, translate along the normal vector of the face/sketch, through its center.\n\nIf the face is circular (i.e. the end of a cone or cylinder), this works the same as translating along a circular sketch.",
7525+
"type": "object",
7526+
"properties": {
7527+
"face": {
7528+
"type": "object",
7529+
"properties": {
7530+
"id": {
7531+
"description": "Which face to translate along.",
7532+
"type": "string",
7533+
"format": "uuid"
7534+
}
7535+
},
7536+
"required": [
7537+
"id"
7538+
]
7539+
}
7540+
},
7541+
"required": [
7542+
"face"
7543+
],
7544+
"additionalProperties": false
7545+
}
7546+
]
7547+
},
74677548
"UnitAngle": {
74687549
"description": "The valid types of angle formats.",
74697550
"oneOf": [

modeling-cmds/src/shared.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,48 @@ impl Default for Rotation {
8383
}
8484
}
8585

86+
/// How to translate in space.
87+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
88+
#[serde(rename_all = "snake_case")]
89+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
90+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
91+
pub enum TranslateBy {
92+
/// Translate this much in each dimension.
93+
Point3d {
94+
/// Which vector to translate along.
95+
point: Point3d<LengthUnit>,
96+
},
97+
/// Translate along this edge or path segment.
98+
///
99+
/// If the edge is a circle, translates along the
100+
/// normal vector of this circle, going through the circle's center.
101+
///
102+
/// If the edge is linear, translates along that line's vector.
103+
Edge {
104+
/// Which edge to translate along.
105+
id: Uuid,
106+
},
107+
/// Translate along this face or sketch.
108+
///
109+
/// If the sketch is circular, translate along
110+
/// the normal vector of the face/sketch, through its center.
111+
///
112+
/// If the face is circular (i.e. the end of a cone or cylinder),
113+
/// this works the same as translating along a circular sketch.
114+
Face {
115+
/// Which face to translate along.
116+
id: Uuid,
117+
},
118+
}
119+
120+
impl Default for TranslateBy {
121+
fn default() -> Self {
122+
Self::Point3d {
123+
point: Default::default(),
124+
}
125+
}
126+
}
127+
86128
/// Ways to transform each solid being replicated in a repeating pattern.
87129
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
88130
#[serde(rename_all = "snake_case")]
@@ -92,7 +134,7 @@ pub struct Transform {
92134
/// Translate the replica this far along each dimension.
93135
/// Defaults to zero vector (i.e. same position as the original).
94136
#[serde(default)]
95-
pub translate: Point3d<LengthUnit>,
137+
pub translate: TranslateBy,
96138
/// Scale the replica's size along each axis.
97139
/// Defaults to (1, 1, 1) (i.e. the same size as the original).
98140
#[serde(default = "same_scale")]

0 commit comments

Comments
 (0)