Compare commits
1 Commits
v1.0.3
...
jtran/offs
Author | SHA1 | Date | |
---|---|---|---|
39e838a015 |
@ -545,7 +545,7 @@ pub struct Plane {
|
||||
}
|
||||
|
||||
impl Plane {
|
||||
pub(crate) fn from_plane_data(value: crate::std::sketch::PlaneData, exec_state: &mut ExecState) -> Self {
|
||||
pub(crate) fn from_plane_data(value: &crate::std::sketch::PlaneData, exec_state: &mut ExecState) -> Self {
|
||||
let id = exec_state.id_generator.next_uuid();
|
||||
match value {
|
||||
crate::std::sketch::PlaneData::XY => Plane {
|
||||
@ -609,10 +609,10 @@ impl Plane {
|
||||
z_axis,
|
||||
} => Plane {
|
||||
id,
|
||||
origin: *origin,
|
||||
x_axis: *x_axis,
|
||||
y_axis: *y_axis,
|
||||
z_axis: *z_axis,
|
||||
origin: **origin,
|
||||
x_axis: **x_axis,
|
||||
y_axis: **y_axis,
|
||||
z_axis: **z_axis,
|
||||
value: PlaneType::Custom,
|
||||
meta: vec![],
|
||||
},
|
||||
@ -1074,6 +1074,26 @@ impl From<Point3d> for kittycad_modeling_cmds::shared::Point3d<LengthUnit> {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add<&Point3d> for Point3d {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: &Self) -> Self {
|
||||
Self {
|
||||
x: self.x + other.x,
|
||||
y: self.y + other.y,
|
||||
z: self.z + other.z,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign<&Point3d> for Point3d {
|
||||
fn add_assign(&mut self, other: &Self) {
|
||||
self.x += other.x;
|
||||
self.y += other.y;
|
||||
self.z += other.z;
|
||||
}
|
||||
}
|
||||
|
||||
/// Metadata.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Eq, Copy)]
|
||||
#[ts(export)]
|
||||
|
@ -8,7 +8,7 @@ use super::shapes::PolygonType;
|
||||
use crate::{
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::{
|
||||
ExecState, ExecutorContext, ExtrudeSurface, KclObjectFields, KclValue, Metadata, Sketch, SketchSet,
|
||||
ExecState, ExecutorContext, ExtrudeSurface, KclObjectFields, KclValue, Metadata, Point3d, Sketch, SketchSet,
|
||||
SketchSurface, Solid, SolidSet, TagIdentifier,
|
||||
},
|
||||
parsing::ast::types::TagNode,
|
||||
@ -1253,7 +1253,16 @@ impl<'a> FromKclValue<'a> for super::sketch::PlaneData {
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
// Case 2: custom plane
|
||||
// Case 2: face
|
||||
if let KclValue::Face(f) = arg {
|
||||
return Some(Self::Plane {
|
||||
origin: Box::new(Point3d::ZERO),
|
||||
x_axis: Box::new(f.x_axis),
|
||||
y_axis: Box::new(f.y_axis),
|
||||
z_axis: Box::new(f.z_axis),
|
||||
});
|
||||
}
|
||||
// Case 3: custom plane
|
||||
let obj = arg.as_object()?;
|
||||
let_field_of!(obj, plane, &KclObjectFields);
|
||||
let origin = plane.get("origin").and_then(FromKclValue::from_kcl_val).map(Box::new)?;
|
||||
|
@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
errors::KclError,
|
||||
execution::{ExecState, KclValue, Plane, PlaneType},
|
||||
execution::{ExecState, KclValue, Plane, PlaneType, Point3d},
|
||||
std::{sketch::PlaneData, Args},
|
||||
};
|
||||
|
||||
@ -52,8 +52,8 @@ impl From<StandardPlane> for PlaneData {
|
||||
|
||||
/// Offset a plane by a distance along its normal.
|
||||
pub async fn offset_plane(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let (std_plane, offset): (StandardPlane, f64) = args.get_data_and_float()?;
|
||||
let plane = inner_offset_plane(std_plane, offset, exec_state).await?;
|
||||
let (plane_data, offset): (PlaneData, f64) = args.get_data_and_float()?;
|
||||
let plane = inner_offset_plane(plane_data, offset, exec_state).await?;
|
||||
make_offset_plane_in_engine(&plane, exec_state, &args).await?;
|
||||
Ok(KclValue::Plane(Box::new(plane)))
|
||||
}
|
||||
@ -139,42 +139,62 @@ pub async fn offset_plane(exec_state: &mut ExecState, args: Args) -> Result<KclV
|
||||
/// |> line([0, 10], %)
|
||||
/// |> close(%)
|
||||
/// ```
|
||||
|
||||
///
|
||||
/// ```no_run
|
||||
/// sketch001 = startSketchOn('XZ')
|
||||
/// profile001 = startProfileAt([65.89, 24.98], sketch001)
|
||||
/// |> xLine(286.79, %)
|
||||
/// |> line([-165.36, 254.07], %, $seg01)
|
||||
/// |> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
/// |> close(%)
|
||||
/// extrude001 = extrude(200, profile001)
|
||||
/// sketch002 = startSketchOn(extrude001, seg01)
|
||||
/// profile002 = startProfileAt([-83.92, 60.12], sketch002)
|
||||
/// |> line([62.9, 113.51], %)
|
||||
/// |> line([69.02, -119.65], %)
|
||||
/// |> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
/// |> close(%)
|
||||
/// plane001 = offsetPlane(sketch002, 150)
|
||||
/// sketch003 = startSketchOn(plane001)
|
||||
/// profile003 = startProfileAt([-83.92, 60.12], sketch002)
|
||||
/// |> line([62.9, 113.51], %)
|
||||
/// |> line([69.02, -119.65], %)
|
||||
/// |> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
/// |> close(%)
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "offsetPlane",
|
||||
}]
|
||||
async fn inner_offset_plane(
|
||||
std_plane: StandardPlane,
|
||||
offset: f64,
|
||||
exec_state: &mut ExecState,
|
||||
) -> Result<Plane, KclError> {
|
||||
// Convert to the plane type.
|
||||
let plane_data: PlaneData = std_plane.into();
|
||||
async fn inner_offset_plane(plane_data: PlaneData, offset: f64, exec_state: &mut ExecState) -> Result<Plane, KclError> {
|
||||
// Convert to a plane.
|
||||
let mut plane = Plane::from_plane_data(plane_data, exec_state);
|
||||
let mut plane = Plane::from_plane_data(&plane_data, exec_state);
|
||||
// Though offset planes are derived from standard planes, they are not
|
||||
// standard planes themselves.
|
||||
plane.value = PlaneType::Custom;
|
||||
|
||||
match std_plane {
|
||||
StandardPlane::XY => {
|
||||
match plane_data {
|
||||
PlaneData::XY => {
|
||||
plane.origin.z += offset;
|
||||
}
|
||||
StandardPlane::XZ => {
|
||||
plane.origin.y -= offset;
|
||||
}
|
||||
StandardPlane::YZ => {
|
||||
plane.origin.x += offset;
|
||||
}
|
||||
StandardPlane::NegXY => {
|
||||
PlaneData::NegXY => {
|
||||
plane.origin.z -= offset;
|
||||
}
|
||||
StandardPlane::NegXZ => {
|
||||
PlaneData::XZ => {
|
||||
plane.origin.y -= offset;
|
||||
}
|
||||
PlaneData::NegXZ => {
|
||||
plane.origin.y += offset;
|
||||
}
|
||||
StandardPlane::NegYZ => {
|
||||
PlaneData::YZ => {
|
||||
plane.origin.x += offset;
|
||||
}
|
||||
PlaneData::NegYZ => {
|
||||
plane.origin.x -= offset;
|
||||
}
|
||||
PlaneData::Plane { z_axis, .. } => {
|
||||
let offset_vector = Point3d::new(z_axis.x * offset, z_axis.y * offset, z_axis.z * offset);
|
||||
plane.origin += &offset_vector;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(plane)
|
||||
|
@ -1112,7 +1112,7 @@ async fn make_sketch_plane_from_orientation(
|
||||
exec_state: &mut ExecState,
|
||||
args: &Args,
|
||||
) -> Result<Box<Plane>, KclError> {
|
||||
let plane = Plane::from_plane_data(data.clone(), exec_state);
|
||||
let plane = Plane::from_plane_data(&data, exec_state);
|
||||
|
||||
// Create the plane on the fly.
|
||||
let clobber = false;
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
Reference in New Issue
Block a user