Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand and update constructors of Curve/Surface #542

Merged
merged 4 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/faces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod tests {
let g = Point::from([2., 2., 0.]);
let h = Point::from([1., 2., 0.]);

let face = Face::builder(Surface::x_y_plane(), &mut shape)
let face = Face::builder(Surface::xy_plane(), &mut shape)
.with_exterior_polygon([a, b, c, d])
.with_interior_polygon([e, f, g, h])
.build()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/triangulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod tests {
let c = [2., 2., 0.];
let d = [0., 1., 0.];

Face::builder(Surface::x_y_plane(), &mut shape)
Face::builder(Surface::xy_plane(), &mut shape)
.with_exterior_polygon([a, b, c, d])
.build()?;

Expand All @@ -123,7 +123,7 @@ mod tests {
let g = [3., 3., 0.];
let h = [1., 2., 0.];

Face::builder(Surface::x_y_plane(), &mut shape)
Face::builder(Surface::xy_plane(), &mut shape)
.with_exterior_polygon([a, b, c, d])
.with_interior_polygon([e, f, g, h])
.build()?;
Expand Down
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/algorithms/triangulation/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ mod tests {
let e = [2., 1.];
let f = [1., 2.];

let polygon = Polygon::new(Surface::x_y_plane())
let polygon = Polygon::new(Surface::xy_plane())
.with_exterior(PolyChain::from([a, b, c]).close())
.with_interiors([PolyChain::from([d, e, f]).close()]);

Expand All @@ -248,7 +248,7 @@ mod tests {
let b = [2., 1.];
let c = [0., 2.];

let polygon = Polygon::new(Surface::x_y_plane())
let polygon = Polygon::new(Surface::xy_plane())
.with_exterior(PolyChain::from([a, b, c]).close());

assert_contains_point(polygon, [1., 1.]);
Expand All @@ -264,7 +264,7 @@ mod tests {
let e = [2., 1.];
let f = [1., 3.];

let polygon = Polygon::new(Surface::x_y_plane())
let polygon = Polygon::new(Surface::xy_plane())
.with_exterior(PolyChain::from([a, b, c]).close())
.with_interiors([PolyChain::from([d, e, f]).close()]);

Expand All @@ -278,7 +278,7 @@ mod tests {
let c = [3., 0.];
let d = [3., 4.];

let polygon = Polygon::new(Surface::x_y_plane())
let polygon = Polygon::new(Surface::xy_plane())
.with_exterior(PolyChain::from([a, b, c, d]).close());

assert_contains_point(polygon, [1., 1.]);
Expand All @@ -291,7 +291,7 @@ mod tests {
let b = [2., 1.];
let c = [3., 1.];
let d = [0., 2.];
let polygon = Polygon::new(Surface::x_y_plane())
let polygon = Polygon::new(Surface::xy_plane())
.with_exterior(PolyChain::from([a, b, c, d]).close());
assert_contains_point(polygon, [1., 1.]);

Expand All @@ -301,7 +301,7 @@ mod tests {
let c = [3., 1.];
let d = [4., 0.];
let e = [4., 5.];
let polygon = Polygon::new(Surface::x_y_plane())
let polygon = Polygon::new(Surface::xy_plane())
.with_exterior(PolyChain::from([a, b, c, d, e]).close());
assert_contains_point(polygon, [1., 1.]);
}
Expand Down
16 changes: 16 additions & 0 deletions crates/fj-kernel/src/geometry/curves/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ impl Curve {
})
}

/// Construct a `Curve` that represents the y-axis
pub fn y_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_y(),
})
}

/// Construct a `Curve` that represents the z-axis
pub fn z_axis() -> Self {
Self::Line(Line {
origin: Point::origin(),
direction: Vector::unit_z(),
})
}

/// Access the origin of the curve's coordinate system
pub fn origin(&self) -> Point<3> {
match self {
Expand Down
20 changes: 18 additions & 2 deletions crates/fj-kernel/src/geometry/surfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ pub enum Surface {
}

impl Surface {
/// Construct a `Surface` that represents the x-y plane
pub fn x_y_plane() -> Self {
/// Construct a `Surface` that represents the xy-plane
pub fn xy_plane() -> Self {
Self::SweptCurve(SweptCurve {
curve: Curve::x_axis(),
path: Vector::unit_y(),
})
}

/// Construct a `Surface` that represents the xz-plane
pub fn xz_plane() -> Self {
Self::SweptCurve(SweptCurve {
curve: Curve::x_axis(),
path: Vector::unit_z(),
})
}

/// Construct a `Surface` that represents the yz-plane
pub fn yz_plane() -> Self {
Self::SweptCurve(SweptCurve {
curve: Curve::y_axis(),
path: Vector::unit_z(),
})
}

/// Create a new instance that is reversed
#[must_use]
pub fn reverse(self) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/shape/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod tests {

let point = Point::from([1., 0., 0.]);
let curve = Curve::x_axis();
let surface = Surface::x_y_plane();
let surface = Surface::xy_plane();

assert!(shape.get_handle(&point).is_none());
assert!(shape.get_handle(&curve).is_none());
Expand Down Expand Up @@ -396,7 +396,7 @@ mod tests {
}

fn add_surface(&mut self) -> Handle<Surface> {
self.insert(Surface::x_y_plane()).unwrap()
self.insert(Surface::xy_plane()).unwrap()
}

fn add_edge(&mut self) -> anyhow::Result<Handle<Edge>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl ToShape for fj::Circle {
shape.insert(Cycle { edges: vec![edge] }).unwrap();

let cycles = shape.cycles().collect();
let surface = shape.insert(Surface::x_y_plane()).unwrap();
let surface = shape.insert(Surface::xy_plane()).unwrap();
shape
.insert(Face::Face {
exteriors: cycles,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ToShape for fj::Sketch {
shape.insert(Cycle { edges }).unwrap();
};

let surface = shape.insert(Surface::x_y_plane()).unwrap();
let surface = shape.insert(Surface::xy_plane()).unwrap();
let face = Face::Face {
exteriors: shape.cycles().collect(),
interiors: Vec::new(),
Expand Down