Skip to content

Commit

Permalink
Integrate SurfaceVertex into Vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 6, 2022
1 parent dd17af7 commit 28670fc
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 23 deletions.
26 changes: 24 additions & 2 deletions crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use fj_math::{Circle, Line, Point, Vector};

use crate::objects::{Curve, CurveKind, Cycle, Edge, Face, Vertex};
use crate::objects::{
Curve, CurveKind, Cycle, Edge, Face, SurfaceVertex, Vertex,
};

use super::Reverse;

Expand Down Expand Up @@ -77,7 +79,27 @@ fn reverse_local_coordinates_in_cycle<'r>(
};

let vertices = edge.vertices().map(|vertex| {
Vertex::new(vertex.position(), curve, *vertex.global_form())
let surface_vertex = {
let vertex = vertex.surface_form();

let position = Point::from([
vertex.position().u,
-vertex.position().v,
]);

SurfaceVertex::new(
position,
vertex.surface().reverse(),
*vertex.global_form(),
)
};

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

Edge::from_curve_and_vertices(curve, vertices)
Expand Down
54 changes: 45 additions & 9 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
transform::TransformObject,
},
objects::{
Curve, CurveKind, Cycle, Edge, Face, GlobalEdge, Surface, Vertex,
VerticesOfEdge,
Curve, CurveKind, Cycle, Edge, Face, GlobalEdge, Surface,
SurfaceVertex, Vertex, VerticesOfEdge,
},
};

Expand Down Expand Up @@ -73,9 +73,31 @@ fn create_non_continuous_side_face(
};

let vertices = {
let vertices = vertices.map(|vertex| {
Vertex::new(vertex.position(), curve, *vertex.global_form())
});
let points_surface = points_curve_and_surface
.map(|(_, point_surface)| point_surface);

// Can be cleaned up, once `zip` is stable:
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let [a_vertex, b_vertex] = vertices;
let [a_surface, b_surface] = points_surface;
let vertices_with_surface_points =
[(a_vertex, a_surface), (b_vertex, b_surface)];

let vertices =
vertices_with_surface_points.map(|(vertex, point_surface)| {
let surface_vertex = SurfaceVertex::new(
point_surface,
surface,
*vertex.global_form(),
);

Vertex::new(
vertex.position(),
curve,
surface_vertex,
*vertex.global_form(),
)
});
VerticesOfEdge::from_vertices(vertices)
};

Expand Down Expand Up @@ -121,14 +143,28 @@ fn create_non_continuous_side_face(
};

let vertices = {
let surface_points = points_curve_and_surface
.map(|(_, point_surface)| point_surface);

// Can be cleaned up, once `zip` is stable:
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let [a_vertex, b_vertex] = bottom_vertices;
let [a_surface, b_surface] = surface_points;
let [a_global, b_global] = global_vertices;
let vertices = [(a_vertex, a_global), (b_vertex, b_global)];

vertices.map(|(vertex, vertex_global)| {
Vertex::new(vertex.position(), curve, vertex_global)
let vertices = [
(a_vertex, a_surface, a_global),
(b_vertex, b_surface, b_global),
];

vertices.map(|(vertex, point_surface, vertex_global)| {
let vertex_surface =
SurfaceVertex::new(point_surface, surface, vertex_global);
Vertex::new(
vertex.position(),
curve,
vertex_surface,
vertex_global,
)
})
};

Expand Down
26 changes: 23 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
algorithms::approx::Tolerance,
objects::{
Curve, CurveKind, Edge, GlobalCurve, GlobalEdge, GlobalVertex, Surface,
SweptCurve, Vertex, VerticesOfEdge,
SurfaceVertex, SweptCurve, Vertex, VerticesOfEdge,
},
};

Expand Down Expand Up @@ -105,10 +105,30 @@ impl Sweep for (Vertex, Surface) {
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let [a_surface, b_surface] = points_surface;
let [a_global, b_global] = vertices_global;
let vertices_surface =
[(a_surface, a_global), (b_surface, b_global)].map(
|(point_surface, &vertex_global)| {
SurfaceVertex::new(
point_surface,
surface,
vertex_global,
)
},
);

// Can be cleaned up, once `zip` is stable:
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let [a_surface, b_surface] = vertices_surface;
let [a_global, b_global] = vertices_global;
let vertices = [(a_surface, a_global), (b_surface, b_global)];

let vertices = vertices.map(|(point_surface, &vertex_global)| {
Vertex::new([point_surface.v], curve, vertex_global)
let vertices = vertices.map(|(vertex_surface, &vertex_global)| {
Vertex::new(
[vertex_surface.position().v],
curve,
vertex_surface,
vertex_global,
)
});

VerticesOfEdge::from_vertices(vertices)
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl TransformObject for Vertex {
Self::new(
self.position(),
self.curve().transform(transform),
self.surface_form().transform(transform),
self.global_form().transform(transform),
)
}
Expand Down
19 changes: 16 additions & 3 deletions crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ mod tests {
use crate::{
algorithms::validate::{Validate, ValidationConfig, ValidationError},
objects::{
Curve, CurveKind, Edge, GlobalCurve, GlobalVertex, Surface, Vertex,
VerticesOfEdge,
Curve, CurveKind, Edge, GlobalCurve, GlobalVertex, Surface,
SurfaceVertex, Vertex, VerticesOfEdge,
},
};

Expand Down Expand Up @@ -200,14 +200,27 @@ mod tests {
let [a_global, b_global] =
points_global.map(GlobalVertex::from_position);

let [a_surface, b_surface] = {
// Can be cleaned up, once `zip` is stable:
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let [a_surface, b_surface] = points_surface;
[(a_surface, a_global), (b_surface, b_global)].map(
|(point_surface, vertex_global)| {
SurfaceVertex::new(point_surface, surface, vertex_global)
},
)
};

let deviation = Scalar::from_f64(0.25);

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

let edge = Edge::from_curve_and_vertices(curve, vertices);
Expand Down
26 changes: 22 additions & 4 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use fj_math::{Circle, Line, Point, Scalar, Vector};

use crate::objects::{
Curve, CurveKind, Edge, GlobalCurve, GlobalVertex, Surface, Vertex,
VerticesOfEdge,
Curve, CurveKind, Edge, GlobalCurve, GlobalVertex, Surface, SurfaceVertex,
Vertex, VerticesOfEdge,
};

/// API for building an [`Edge`]
Expand Down Expand Up @@ -50,6 +50,22 @@ impl EdgeBuilder {
GlobalVertex::from_position(position)
});

let surface_vertices = {
// Can be cleaned up, once `zip` is stable:
// https://doc.rust-lang.org/std/primitive.array.html#method.zip
let [a_surface, b_surface] = points;
let [a_global, b_global] = global_vertices;
[(a_surface, a_global), (b_surface, b_global)].map(
|(point_surface, vertex_global)| {
SurfaceVertex::new(
point_surface,
self.surface,
vertex_global,
)
},
)
};

let curve = {
let curve_local = CurveKind::Line(Line::from_points(points));
let curve_global = {
Expand All @@ -64,9 +80,11 @@ impl EdgeBuilder {

let vertices = {
let [a_global, b_global] = global_vertices;
let [a_surface, b_surface] = surface_vertices;

let vertices = [
Vertex::new(Point::from([0.]), curve, a_global),
Vertex::new(Point::from([1.]), curve, b_global),
Vertex::new(Point::from([0.]), curve, a_surface, a_global),
Vertex::new(Point::from([1.]), curve, b_surface, b_global),
];

VerticesOfEdge::from_vertices(vertices)
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl<T> Iterator for Iter<T> {
mod tests {
use crate::objects::{
Curve, Cycle, Edge, Face, GlobalCurve, GlobalVertex, Shell, Sketch,
Solid, Surface, Vertex,
Solid, Surface, SurfaceVertex, Vertex,
};

use super::ObjectIters as _;
Expand Down Expand Up @@ -547,7 +547,9 @@ mod tests {
let surface = Surface::xy_plane();
let curve = Curve::build(surface).u_axis();
let global_vertex = GlobalVertex::from_position([0., 0., 0.]);
let object = Vertex::new([0.], curve, global_vertex);
let surface_vertex =
SurfaceVertex::new([0., 0.], surface, global_vertex);
let object = Vertex::new([0.], curve, surface_vertex, global_vertex);

assert_eq!(1, object.curve_iter().count());
assert_eq!(0, object.cycle_iter().count());
Expand Down
2 changes: 2 additions & 0 deletions crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ impl VerticesOfEdge<Vertex> {
Vertex::new(
-b.position(),
b.curve().reverse(),
*b.surface_form(),
*b.global_form(),
),
Vertex::new(
-a.position(),
a.curve().reverse(),
*a.surface_form(),
*a.global_form(),
),
]
Expand Down
8 changes: 8 additions & 0 deletions crates/fj-kernel/src/objects/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::{Curve, Surface};
pub struct Vertex {
position: Point<1>,
curve: Curve,
surface_form: SurfaceVertex,
global_form: GlobalVertex,
}

Expand All @@ -27,12 +28,14 @@ impl Vertex {
pub fn new(
position: impl Into<Point<1>>,
curve: Curve,
surface_form: SurfaceVertex,
global_form: GlobalVertex,
) -> Self {
let position = position.into();
Self {
position,
curve,
surface_form,
global_form,
}
}
Expand All @@ -47,6 +50,11 @@ impl Vertex {
&self.curve
}

/// Access the surface form of this vertex
pub fn surface_form(&self) -> &SurfaceVertex {
&self.surface_form
}

/// Access the global form of this vertex
pub fn global_form(&self) -> &GlobalVertex {
&self.global_form
Expand Down

0 comments on commit 28670fc

Please sign in to comment.