mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-19 05:35:55 +00:00
Empty segments & points (#1585)
* Made from_points and from_segments return Option * Updated models * Fixed doctests
This commit is contained in:
parent
04ea2d009c
commit
dc43d54dce
@ -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`
|
||||
|
@ -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<SketchSegment>) -> Self {
|
||||
Self {
|
||||
chain: Chain::PolyChain(PolyChain::from_segments(segments)),
|
||||
color: [255, 0, 0, 255],
|
||||
pub fn from_segments(segments: Vec<SketchSegment>) -> Option<Self> {
|
||||
// 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<Self> {
|
||||
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],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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`
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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`
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -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()]);
|
||||
|
||||
|
@ -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()]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user