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

Un-derive Copy from various object types #1097

Merged
merged 7 commits into from
Sep 16, 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/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Approx for (&Curve, RangeOnPath) {
curve.path().point_from_path_coords(point.local_form);

ApproxPoint::new(point_surface, point.global_form)
.with_source((*curve, point.local_form))
.with_source((curve.clone(), point.local_form))
}),
)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Approx for &HalfEdge {
tolerance: impl Into<Tolerance>,
cache: &mut Self::Cache,
) -> Self::Approximation {
let &[a, b] = self.vertices();
let [a, b] = self.vertices();
let boundary = [a, b].map(|vertex| vertex.position());
let range = RangeOnPath { boundary };

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl CurveEdgeIntersection {
}
};

let edge_vertices = half_edge.vertices().map(|vertex| {
let edge_vertices = half_edge.vertices().clone().map(|vertex| {
edge_curve_as_line.point_from_line_coords(vertex.position())
});

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ impl FaceFaceIntersection {
// Can be cleaned up, once `zip` is stable:
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let curve_face_intersections = {
let [curve_a, curve_b] = intersection_curves;
let [curve_a, curve_b] = &intersection_curves;
let [face_a, face_b] = faces;

[(curve_a, face_a), (curve_b, face_b)].map(|(curve, face)| {
CurveFaceIntersection::compute(&curve, face)
CurveFaceIntersection::compute(curve, face)
})
};

Expand Down
18 changes: 8 additions & 10 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Intersect for (&Face, &Point<2>) {
let mut previous_hit = cycle
.half_edges()
.last()
.copied()
.cloned()
.and_then(|edge| (&ray, &edge).intersect());

for half_edge in cycle.half_edges() {
Expand All @@ -40,18 +40,18 @@ impl Intersect for (&Face, &Point<2>) {
) => {
// If the ray starts on the boundary of the face,
// there's nothing to else check.
return Some(
FacePointIntersection::PointIsOnEdge(*half_edge)
);
return Some(FacePointIntersection::PointIsOnEdge(
half_edge.clone()
));
}
(Some(RaySegmentIntersection::RayStartsOnOnFirstVertex), _) => {
let vertex = half_edge.vertices()[0];
let vertex = half_edge.vertices()[0].clone();
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
}
(Some(RaySegmentIntersection::RayStartsOnSecondVertex), _) => {
let vertex = half_edge.vertices()[1];
let vertex = half_edge.vertices()[1].clone();
return Some(
FacePointIntersection::PointIsOnVertex(vertex)
);
Expand Down Expand Up @@ -235,7 +235,6 @@ mod tests {

let edge = face
.half_edge_iter()
.copied()
.find(|edge| {
let [a, b] = edge.vertices();
a.global_form().position() == Point::from([0., 0., 0.])
Expand All @@ -244,7 +243,7 @@ mod tests {
.unwrap();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsOnEdge(edge))
Some(FacePointIntersection::PointIsOnEdge(edge.clone()))
);
}

Expand All @@ -259,14 +258,13 @@ mod tests {

let vertex = face
.vertex_iter()
.copied()
.find(|vertex| {
vertex.global_form().position() == Point::from([1., 0., 0.])
})
.unwrap();
assert_eq!(
intersection,
Some(FacePointIntersection::PointIsOnVertex(vertex))
Some(FacePointIntersection::PointIsOnVertex(vertex.clone()))
);
}
}
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 @@ -23,7 +23,7 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &HalfEdge) {
}
};

let points = edge.vertices().map(|vertex| {
let points = edge.vertices().clone().map(|vertex| {
let point = vertex.position();
line.point_from_line_coords(point)
});
Expand Down
8 changes: 3 additions & 5 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Intersect for (&HorizontalRayToTheRight<3>, &Face) {
}

/// A hit between a ray and a face
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum RayFaceIntersection {
/// The ray hits the face itself
Expand Down Expand Up @@ -211,7 +211,6 @@ mod tests {

let edge = face
.half_edge_iter()
.copied()
.find(|edge| {
let [a, b] = edge.vertices();
a.global_form().position() == Point::from([1., 0., 1.])
Expand All @@ -220,7 +219,7 @@ mod tests {
.unwrap();
assert_eq!(
(&ray, &face).intersect(),
Some(RayFaceIntersection::RayHitsEdge(edge))
Some(RayFaceIntersection::RayHitsEdge(edge.clone()))
);
}

Expand All @@ -235,14 +234,13 @@ mod tests {

let vertex = face
.vertex_iter()
.copied()
.find(|vertex| {
vertex.global_form().position() == Point::from([1., 0., 0.])
})
.unwrap();
assert_eq!(
(&ray, &face).intersect(),
Some(RayFaceIntersection::RayHitsVertex(vertex))
Some(RayFaceIntersection::RayHitsVertex(vertex.clone()))
);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use super::Reverse;
impl Reverse for HalfEdge {
fn reverse(self) -> Self {
let vertices = {
let &[a, b] = self.vertices();
let [a, b] = self.vertices().clone();
[b, a]
};

HalfEdge::from_curve_and_vertices(*self.curve(), vertices)
HalfEdge::from_curve_and_vertices(self.curve().clone(), vertices)
}
}
22 changes: 12 additions & 10 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ impl Sweep for (HalfEdge, Color) {
let (edge, color) = self;
let path = path.into();

let surface = edge.curve().sweep(path);
let surface = edge.curve().clone().sweep(path);

// We can't use the edge we're sweeping from as the bottom edge, as that
// is not defined in the right surface. Let's create a new bottom edge,
// by swapping the surface of the original.
let bottom_edge = {
let vertices = edge.vertices();

let points_curve_and_surface = vertices.map(|vertex| {
let points_curve_and_surface = vertices.clone().map(|vertex| {
(vertex.position(), [vertex.position().t, Scalar::ZERO])
});

Expand Down Expand Up @@ -62,31 +62,33 @@ impl Sweep for (HalfEdge, Color) {

Vertex::new(
vertex.position(),
curve,
curve.clone(),
surface_vertex,
*vertex.global_form(),
)
})
};

HalfEdge::new(curve, vertices, *edge.global_form())
HalfEdge::new(curve, vertices, edge.global_form().clone())
};

let side_edges = bottom_edge
.vertices()
.clone()
.map(|vertex| (vertex, surface).sweep(path));

let top_edge = {
let bottom_vertices = bottom_edge.vertices();

let global_vertices = side_edges.map(|edge| {
let global_vertices = side_edges.clone().map(|edge| {
let [_, vertex] = edge.vertices();
*vertex.global_form()
});

let points_curve_and_surface = bottom_vertices.map(|vertex| {
(vertex.position(), [vertex.position().t, Scalar::ONE])
});
let points_curve_and_surface =
bottom_vertices.clone().map(|vertex| {
(vertex.position(), [vertex.position().t, Scalar::ONE])
});

let curve = {
let global = bottom_edge.curve().global_form().translate(path);
Expand Down Expand Up @@ -126,7 +128,7 @@ impl Sweep for (HalfEdge, Color) {
);
Vertex::new(
vertex.position(),
curve,
curve.clone(),
vertex_surface,
vertex_global,
)
Expand Down Expand Up @@ -155,7 +157,7 @@ impl Sweep for (HalfEdge, Color) {
// be coincident when sweeping circles, despite the vertices
// being different!
if prev_last.surface_form() != next_first.surface_form() {
edges[j] = edges[j].reverse();
edges[j] = edges[j].clone().reverse();
}

i += 1;
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ impl Sweep for Face {
faces.push(top_face);

for cycle in self.all_cycles() {
for &half_edge in cycle.half_edges() {
for half_edge in cycle.half_edges() {
let edge = if is_negative_sweep {
half_edge.reverse()
half_edge.clone().reverse()
} else {
half_edge
half_edge.clone()
};
let face = (edge, self.color()).sweep(path);
faces.push(face);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Sweep for (Vertex, Surface) {
vertices.map(|(vertex_surface, &vertex_global)| {
Vertex::new(
[vertex_surface.position().v],
curve,
curve.clone(),
vertex_surface,
vertex_global,
)
Expand Down
10 changes: 6 additions & 4 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ impl TransformObject for GlobalVertex {

impl TransformObject for HalfEdge {
fn transform(self, transform: &Transform) -> Self {
let curve = self.curve().transform(transform);
let vertices =
self.vertices().map(|vertex| vertex.transform(transform));
let curve = self.curve().clone().transform(transform);
let vertices = self
.vertices()
.clone()
.map(|vertex| vertex.transform(transform));

Self::from_curve_and_vertices(curve, vertices)
}
Expand Down Expand Up @@ -165,7 +167,7 @@ impl TransformObject for Vertex {
fn transform(self, transform: &Transform) -> Self {
Self::new(
self.position(),
self.curve().transform(transform),
self.curve().clone().transform(transform),
self.surface_form().transform(transform),
self.global_form().transform(transform),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/validate/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn validate_curve(
point_surface,
point_surface_as_global,
point_global,
curve: *curve,
curve: curve.clone(),
})?
}
}
Expand Down
19 changes: 12 additions & 7 deletions crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,25 @@ mod tests {

let a = Vertex::new(
Point::from([Scalar::ZERO + deviation]),
curve,
curve.clone(),
a_surface,
a_global,
);
let b =
Vertex::new(Point::from([Scalar::ONE]), curve, b_surface, b_global);
let b = Vertex::new(
Point::from([Scalar::ONE]),
curve.clone(),
b_surface,
b_global,
);
let vertices = [a, b];

let half_edge = HalfEdge::from_curve_and_vertices(curve, vertices);

let result = half_edge.validate_with_config(&ValidationConfig {
identical_max_distance: deviation * 2.,
..ValidationConfig::default()
});
let result =
half_edge.clone().validate_with_config(&ValidationConfig {
identical_max_distance: deviation * 2.,
..ValidationConfig::default()
});
assert!(result.is_ok());

let result = half_edge.validate_with_config(&ValidationConfig {
Expand Down
16 changes: 13 additions & 3 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl HalfEdgeBuilder {
|(point_curve, surface_vertex)| {
Vertex::new(
point_curve,
curve,
curve.clone(),
surface_vertex,
global_vertex,
)
Expand Down Expand Up @@ -103,8 +103,18 @@ impl HalfEdgeBuilder {
let [a_surface, b_surface] = surface_vertices;

[
Vertex::new(Point::from([0.]), curve, a_surface, a_global),
Vertex::new(Point::from([1.]), curve, b_surface, b_global),
Vertex::new(
Point::from([0.]),
curve.clone(),
a_surface,
a_global,
),
Vertex::new(
Point::from([1.]),
curve.clone(),
b_surface,
b_global,
),
]
};

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ impl VertexBuilder {
global_form,
);

Vertex::new([0.], self.curve, surface_form, global_form)
Vertex::new([0.], self.curve.clone(), surface_form, global_form)
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use super::Surface;

/// A curve, defined in local surface coordinates
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Curve {
path: SurfacePath,
surface: Surface,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Cycle {
//
// Can be cleaned up, once `array_windows` is stable:
// https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows
let [a, b] = [half_edge[0], half_edge[1]];
let [a, b] = [&half_edge[0], &half_edge[1]];

let [a, b] = [a, b].map(|half_edge| {
let [vertex, _] = half_edge.vertices();
Expand Down
Loading