diff --git a/crates/fj/src/group.rs b/crates/fj/src/group.rs index d675e2761..832b82104 100644 --- a/crates/fj/src/group.rs +++ b/crates/fj/src/group.rs @@ -10,8 +10,8 @@ use crate::Shape; /// Convenient syntax for this operation is available through [`crate::syntax`]. /// /// ``` rust -/// # let a = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); -/// # let b = fj::Sketch::from_points(vec![[2., 0.], [3., 0.], [2., 1.]]); +/// # let a = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]).unwrap(); +/// # let b = fj::Sketch::from_points(vec![[2., 0.], [3., 0.], [2., 1.]]).unwrap(); /// use fj::syntax::*; /// /// // `a` and `b` can be anything that converts to `fj::Shape` diff --git a/crates/fj/src/shape_2d.rs b/crates/fj/src/shape_2d.rs index cade8b933..a448a9bb0 100644 --- a/crates/fj/src/shape_2d.rs +++ b/crates/fj/src/shape_2d.rs @@ -29,8 +29,8 @@ impl Shape2d { /// Convenient syntax for this operation is available through [`crate::syntax`]. /// /// ``` rust -/// # let a = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); -/// # let b = fj::Sketch::from_points(vec![[2., 0.], [3., 0.], [2., 1.]]); +/// # let a = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]).unwrap(); +/// # let b = fj::Sketch::from_points(vec![[2., 0.], [3., 0.], [2., 1.]]).unwrap(); /// use fj::syntax::*; /// /// // `a` and `b` can be anything that converts to `fj::Shape2d` @@ -102,18 +102,28 @@ pub struct Sketch { impl Sketch { /// Create a sketch made of sketch segments - pub fn from_segments(segments: Vec) -> Self { - Self { - chain: Chain::PolyChain(PolyChain::from_segments(segments)), - color: [255, 0, 0, 255], + pub fn from_segments(segments: Vec) -> Option { + // TODO Returning an option is just a temporary solution, see: https://github.com/hannobraun/Fornjot/issues/1507 + if segments.is_empty() { + None + } else { + Some(Self { + chain: Chain::PolyChain(PolyChain::from_segments(segments)), + color: [255, 0, 0, 255], + }) } } /// Create a sketch made of straight lines from a bunch of points - pub fn from_points(points: Vec<[f64; 2]>) -> Self { - Self { - chain: Chain::PolyChain(PolyChain::from_points(points)), - color: [255, 0, 0, 255], + pub fn from_points(points: Vec<[f64; 2]>) -> Option { + if points.is_empty() { + // TODO Returning an option is just a temporary solution, see: https://github.com/hannobraun/Fornjot/issues/1507 + None + } else { + Some(Self { + chain: Chain::PolyChain(PolyChain::from_points(points)), + color: [255, 0, 0, 255], + }) } } diff --git a/crates/fj/src/sweep.rs b/crates/fj/src/sweep.rs index 14b805ebb..18f129148 100644 --- a/crates/fj/src/sweep.rs +++ b/crates/fj/src/sweep.rs @@ -7,7 +7,7 @@ use crate::{Shape, Shape2d}; /// Convenient syntax for this operation is available through [`crate::syntax`]. /// /// ``` rust -/// # let shape = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); +/// # let shape = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]).unwrap(); /// use fj::syntax::*; /// /// // `shape` can be anything that converts to `fj::Shape2d` diff --git a/crates/fj/src/syntax.rs b/crates/fj/src/syntax.rs index fb887191b..662cbbeee 100644 --- a/crates/fj/src/syntax.rs +++ b/crates/fj/src/syntax.rs @@ -69,7 +69,7 @@ where T: AsRef<[[f64; 2]]>, { fn sketch(&self) -> crate::Sketch { - crate::Sketch::from_points(self.as_ref().to_vec()) + crate::Sketch::from_points(self.as_ref().to_vec()).unwrap() } } diff --git a/crates/fj/src/transform.rs b/crates/fj/src/transform.rs index c388d141c..d22b84548 100644 --- a/crates/fj/src/transform.rs +++ b/crates/fj/src/transform.rs @@ -7,7 +7,7 @@ use crate::{Angle, Shape}; /// Convenient syntax for this operation is available through [`crate::syntax`]. /// /// ``` rust -/// # let shape = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); +/// # let shape = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]).unwrap(); /// use fj::syntax::*; /// /// // `shape` can be anything that converts to `fj::Shape` diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 6505e3612..6c8767664 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -10,7 +10,7 @@ pub fn model( [ x / 2., -y / 2.], [ x / 2., y / 2.], [-x / 2., y / 2.], - ]).with_color([100,255,0,200]); + ]).unwrap().with_color([100,255,0,200]); let cuboid = fj::Sweep::from_path(rectangle.into(), [0., 0., z]); diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 3d1775680..beb626e8f 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -29,8 +29,8 @@ pub fn model( inner.push([x / 2., y / 2.]); } - let outer = fj::Sketch::from_points(outer); - let inner = fj::Sketch::from_points(inner); + let outer = fj::Sketch::from_points(outer).unwrap(); + let inner = fj::Sketch::from_points(inner).unwrap(); let footprint = fj::Difference2d::from_shapes([outer.into(), inner.into()]); diff --git a/models/test/src/lib.rs b/models/test/src/lib.rs index 842adc3c0..1aaa37bdc 100644 --- a/models/test/src/lib.rs +++ b/models/test/src/lib.rs @@ -69,8 +69,8 @@ fn star( } } - let outer = fj::Sketch::from_segments(outer).with_color(color); - let inner = fj::Sketch::from_segments(inner); + let outer = fj::Sketch::from_segments(outer).unwrap().with_color(color); + let inner = fj::Sketch::from_segments(inner).unwrap(); let footprint = fj::Difference2d::from_shapes([outer.into(), inner.into()]);