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

Bound all edges by vertices #1057

Merged
merged 7 commits into from
Sep 8, 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
59 changes: 2 additions & 57 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
//! approximations are usually used to build cycle approximations, and this way,
//! the caller doesn't have to call with duplicate vertices.

use fj_math::{Point, Scalar};

use crate::objects::{Edge, GlobalVertex, SurfaceVertex, Vertex};
use crate::objects::Edge;

use super::{
curve::{CurveApprox, RangeOnCurve},
Expand All @@ -18,60 +16,7 @@ impl Approx for &Edge {
type Approximation = EdgeApprox;

fn approx(self, tolerance: super::Tolerance) -> Self::Approximation {
// The range is only used for circles right now.
let [a, b] = match self.vertices().get() {
Some(vertices) => vertices.map(|&vertex| vertex),
None => {
// Creating vertices from nothing, just for the sake of
// approximation is a bit weird. But this code is a temporary
// fallback anyway. It'll do for now, and it will likely be
// removed soon.

let start_curve = Point::from([Scalar::ZERO]);
let end_curve = Point::from([Scalar::TAU]);

// We're dealing with a circle here. Start and end are identical
// points, in global coordinates.
let vertex_global = {
let point_global = self
.global_form()
.curve()
.kind()
.point_from_curve_coords(start_curve);

GlobalVertex::from_position(point_global)
};

let [start_surface, end_surface] = [start_curve, end_curve]
.map(|point_curve| {
let point_surface = self
.curve()
.kind()
.point_from_curve_coords(point_curve);
SurfaceVertex::new(
point_surface,
*self.curve().surface(),
vertex_global,
)
});

let a = Vertex::new(
start_curve,
*self.curve(),
start_surface,
vertex_global,
);
let b = Vertex::new(
end_curve,
*self.curve(),
end_surface,
vertex_global,
);

[a, b]
}
};

let [a, b] = self.vertices().get().map(|&vertex| vertex);
let range = RangeOnCurve::new([a, b]);

let first = ApproxPoint::new(
Expand Down
11 changes: 3 additions & 8 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ impl CurveEdgeIntersection {
}
};

let edge_vertices = match edge.vertices().get() {
Some(vertices) => vertices.map(|vertex| {
edge_curve_as_line.point_from_line_coords(vertex.position())
}),
None => todo!(
"Curve-edge intersection does not support continuous edges"
),
};
let edge_vertices = edge.vertices().get().map(|vertex| {
edge_curve_as_line.point_from_line_coords(vertex.position())
});

Segment::from_points(edge_vertices)
};
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ impl Intersect for (&Face, &Point<2>) {
);
}
(Some(RaySegmentIntersection::RayStartsOnOnFirstVertex), _) => {
let vertex = *edge.vertices().get_or_panic()[0];
let vertex = *edge.vertices().get()[0];
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
}
(Some(RaySegmentIntersection::RayStartsOnSecondVertex), _) => {
let vertex = *edge.vertices().get_or_panic()[1];
let vertex = *edge.vertices().get()[1];
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
Expand Down Expand Up @@ -237,7 +237,7 @@ mod tests {
.edge_iter()
.copied()
.find(|edge| {
let [a, b] = edge.vertices().get_or_panic();
let [a, b] = edge.vertices().get();
a.global_form().position() == Point::from([0., 0., 0.])
&& b.global_form().position() == Point::from([2., 0., 0.])
})
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/ray_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Edge) {
}
};

let points = edge.vertices().get_or_panic().map(|vertex| {
let points = edge.vertices().get().map(|vertex| {
let point = vertex.position();
line.point_from_line_coords(point)
});
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ mod tests {
.edge_iter()
.copied()
.find(|edge| {
let [a, b] = edge.vertices().get_or_panic();
let [a, b] = edge.vertices().get();
a.global_form().position() == Point::from([1., 0., 1.])
&& b.global_form().position() == Point::from([1., 0., -1.])
})
Expand Down
4 changes: 0 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ use super::Reverse;

impl Reverse for Face {
fn reverse(self) -> Self {
if self.triangles().is_some() {
panic!("Reversing tri-rep faces is not supported");
}

let surface = self.surface().reverse();

let exteriors = reverse_local_coordinates_in_cycle(self.exteriors());
Expand Down
4 changes: 1 addition & 3 deletions crates/fj-kernel/src/algorithms/sweep/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ impl Sweep for Curve {
fn sweep(
self,
path: impl Into<super::Path>,
tolerance: impl Into<crate::algorithms::approx::Tolerance>,
color: fj_interop::mesh::Color,
) -> Self::Swept {
self.global_form().sweep(path, tolerance, color)
self.global_form().sweep(path, color)
}
}

Expand All @@ -21,7 +20,6 @@ impl Sweep for GlobalCurve {
fn sweep(
self,
path: impl Into<super::Path>,
_: impl Into<crate::algorithms::approx::Tolerance>,
_: fj_interop::mesh::Color,
) -> Self::Swept {
Surface::SweptCurve(SweptCurve {
Expand Down
Loading