Compare commits
	
		
			1 Commits
		
	
	
		
			v1.0.2
			...
			jtran/offs
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 39e838a015 | 
| @ -545,7 +545,7 @@ pub struct Plane { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl 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(); |         let id = exec_state.id_generator.next_uuid(); | ||||||
|         match value { |         match value { | ||||||
|             crate::std::sketch::PlaneData::XY => Plane { |             crate::std::sketch::PlaneData::XY => Plane { | ||||||
| @ -609,10 +609,10 @@ impl Plane { | |||||||
|                 z_axis, |                 z_axis, | ||||||
|             } => Plane { |             } => Plane { | ||||||
|                 id, |                 id, | ||||||
|                 origin: *origin, |                 origin: **origin, | ||||||
|                 x_axis: *x_axis, |                 x_axis: **x_axis, | ||||||
|                 y_axis: *y_axis, |                 y_axis: **y_axis, | ||||||
|                 z_axis: *z_axis, |                 z_axis: **z_axis, | ||||||
|                 value: PlaneType::Custom, |                 value: PlaneType::Custom, | ||||||
|                 meta: vec![], |                 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. | /// Metadata. | ||||||
| #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Eq, Copy)] | #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Eq, Copy)] | ||||||
| #[ts(export)] | #[ts(export)] | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ use super::shapes::PolygonType; | |||||||
| use crate::{ | use crate::{ | ||||||
|     errors::{KclError, KclErrorDetails}, |     errors::{KclError, KclErrorDetails}, | ||||||
|     execution::{ |     execution::{ | ||||||
|         ExecState, ExecutorContext, ExtrudeSurface, KclObjectFields, KclValue, Metadata, Sketch, SketchSet, |         ExecState, ExecutorContext, ExtrudeSurface, KclObjectFields, KclValue, Metadata, Point3d, Sketch, SketchSet, | ||||||
|         SketchSurface, Solid, SolidSet, TagIdentifier, |         SketchSurface, Solid, SolidSet, TagIdentifier, | ||||||
|     }, |     }, | ||||||
|     parsing::ast::types::TagNode, |     parsing::ast::types::TagNode, | ||||||
| @ -1253,7 +1253,16 @@ impl<'a> FromKclValue<'a> for super::sketch::PlaneData { | |||||||
|                 _ => None, |                 _ => 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 obj = arg.as_object()?; | ||||||
|         let_field_of!(obj, plane, &KclObjectFields); |         let_field_of!(obj, plane, &KclObjectFields); | ||||||
|         let origin = plane.get("origin").and_then(FromKclValue::from_kcl_val).map(Box::new)?; |         let origin = plane.get("origin").and_then(FromKclValue::from_kcl_val).map(Box::new)?; | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; | |||||||
|  |  | ||||||
| use crate::{ | use crate::{ | ||||||
|     errors::KclError, |     errors::KclError, | ||||||
|     execution::{ExecState, KclValue, Plane, PlaneType}, |     execution::{ExecState, KclValue, Plane, PlaneType, Point3d}, | ||||||
|     std::{sketch::PlaneData, Args}, |     std::{sketch::PlaneData, Args}, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @ -52,8 +52,8 @@ impl From<StandardPlane> for PlaneData { | |||||||
|  |  | ||||||
| /// Offset a plane by a distance along its normal. | /// Offset a plane by a distance along its normal. | ||||||
| pub async fn offset_plane(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { | 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_data, offset): (PlaneData, f64) = args.get_data_and_float()?; | ||||||
|     let plane = inner_offset_plane(std_plane, offset, exec_state).await?; |     let plane = inner_offset_plane(plane_data, offset, exec_state).await?; | ||||||
|     make_offset_plane_in_engine(&plane, exec_state, &args).await?; |     make_offset_plane_in_engine(&plane, exec_state, &args).await?; | ||||||
|     Ok(KclValue::Plane(Box::new(plane))) |     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], %) | ///   |> line([0, 10], %) | ||||||
| ///   |> close(%) | ///   |> 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 { | #[stdlib { | ||||||
|     name = "offsetPlane", |     name = "offsetPlane", | ||||||
| }] | }] | ||||||
| async fn inner_offset_plane( | async fn inner_offset_plane(plane_data: PlaneData, offset: f64, exec_state: &mut ExecState) -> Result<Plane, KclError> { | ||||||
|     std_plane: StandardPlane, |  | ||||||
|     offset: f64, |  | ||||||
|     exec_state: &mut ExecState, |  | ||||||
| ) -> Result<Plane, KclError> { |  | ||||||
|     // Convert to the plane type. |  | ||||||
|     let plane_data: PlaneData = std_plane.into(); |  | ||||||
|     // Convert to a plane. |     // 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 |     // Though offset planes are derived from standard planes, they are not | ||||||
|     // standard planes themselves. |     // standard planes themselves. | ||||||
|     plane.value = PlaneType::Custom; |     plane.value = PlaneType::Custom; | ||||||
|  |  | ||||||
|     match std_plane { |     match plane_data { | ||||||
|         StandardPlane::XY => { |         PlaneData::XY => { | ||||||
|             plane.origin.z += offset; |             plane.origin.z += offset; | ||||||
|         } |         } | ||||||
|         StandardPlane::XZ => { |         PlaneData::NegXY => { | ||||||
|             plane.origin.y -= offset; |  | ||||||
|         } |  | ||||||
|         StandardPlane::YZ => { |  | ||||||
|             plane.origin.x += offset; |  | ||||||
|         } |  | ||||||
|         StandardPlane::NegXY => { |  | ||||||
|             plane.origin.z -= offset; |             plane.origin.z -= offset; | ||||||
|         } |         } | ||||||
|         StandardPlane::NegXZ => { |         PlaneData::XZ => { | ||||||
|  |             plane.origin.y -= offset; | ||||||
|  |         } | ||||||
|  |         PlaneData::NegXZ => { | ||||||
|             plane.origin.y += offset; |             plane.origin.y += offset; | ||||||
|         } |         } | ||||||
|         StandardPlane::NegYZ => { |         PlaneData::YZ => { | ||||||
|  |             plane.origin.x += offset; | ||||||
|  |         } | ||||||
|  |         PlaneData::NegYZ => { | ||||||
|             plane.origin.x -= offset; |             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) |     Ok(plane) | ||||||
|  | |||||||
| @ -1112,7 +1112,7 @@ async fn make_sketch_plane_from_orientation( | |||||||
|     exec_state: &mut ExecState, |     exec_state: &mut ExecState, | ||||||
|     args: &Args, |     args: &Args, | ||||||
| ) -> Result<Box<Plane>, KclError> { | ) -> 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. |     // Create the plane on the fly. | ||||||
|     let clobber = false; |     let clobber = false; | ||||||
|  | |||||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 56 KiB | 
		Reference in New Issue
	
	Block a user
	