Skip to content

Commit

Permalink
Merge pull request #761 from hannobraun/local
Browse files Browse the repository at this point in the history
Consolidate code that manages local forms
  • Loading branch information
hannobraun authored Jul 1, 2022
2 parents 2673287 + e850cd9 commit 4415967
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 199 deletions.
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/algorithms/approx/curves.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::cmp::max;

use fj_math::{Circle, Scalar};
use fj_math::{Circle, Point, Scalar};

use crate::{geometry::LocalPoint, objects::Curve};
use crate::{local::Local, objects::Curve};

use super::Tolerance;

Expand All @@ -23,7 +23,7 @@ use super::Tolerance;
pub fn approx_curve(
curve: &Curve<3>,
tolerance: Tolerance,
out: &mut Vec<LocalPoint<1>>,
out: &mut Vec<Local<Point<1>>>,
) {
match curve {
Curve::Circle(curve) => approx_circle(curve, tolerance, out),
Expand All @@ -38,7 +38,7 @@ pub fn approx_curve(
pub fn approx_circle(
circle: &Circle<3>,
tolerance: Tolerance,
out: &mut Vec<LocalPoint<1>>,
out: &mut Vec<Local<Point<1>>>,
) {
let radius = circle.a.magnitude();

Expand All @@ -53,7 +53,7 @@ pub fn approx_circle(
for i in 0..n {
let angle = Scalar::PI * 2. / n as f64 * i as f64;
let point = circle.point_from_circle_coords([angle]);
out.push(LocalPoint::new([angle], point));
out.push(Local::new([angle], point));
}
}

Expand Down
13 changes: 5 additions & 8 deletions crates/fj-kernel/src/algorithms/approx/cycles.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use fj_math::Segment;
use fj_math::{Point, Segment};

use crate::{geometry::LocalPoint, objects::Cycle};
use crate::objects::Cycle;

use super::{curves::approx_curve, edges::approx_edge, Tolerance};

/// An approximation of a [`Cycle`]
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct CycleApprox {
/// The points that approximate the cycle
pub points: Vec<LocalPoint<3>>,
pub points: Vec<Point<3>>,
}

impl CycleApprox {
Expand All @@ -27,10 +27,8 @@ impl CycleApprox {
points.extend(edge_points);
}

let mut points: Vec<_> = points
.into_iter()
.map(|point| LocalPoint::new(point.global(), point.global()))
.collect();
let mut points: Vec<_> =
points.into_iter().map(|point| point.global()).collect();

points.dedup();

Expand All @@ -46,7 +44,6 @@ impl CycleApprox {
// up, once `array_windows` is stable.
let segment = [segment[0], segment[1]];

let segment = segment.map(|point| point.global());
segments.push(Segment::from(segment));
}

Expand Down
21 changes: 13 additions & 8 deletions crates/fj-kernel/src/algorithms/approx/edges.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::{geometry::LocalPoint, objects::VerticesOfEdge};
use fj_math::Point;

pub fn approx_edge(vertices: VerticesOfEdge, points: &mut Vec<LocalPoint<1>>) {
use crate::{local::Local, objects::VerticesOfEdge};

pub fn approx_edge(
vertices: VerticesOfEdge,
points: &mut Vec<Local<Point<1>>>,
) {
// Insert the exact vertices of this edge into the approximation. This means
// we don't rely on the curve approximation to deliver accurate
// representations of these vertices, which they might not be able to do.
Expand All @@ -10,7 +15,7 @@ pub fn approx_edge(vertices: VerticesOfEdge, points: &mut Vec<LocalPoint<1>>) {
// the same vertex would be understood to refer to very close, but distinct
// vertices.
let vertices = vertices.convert(|vertex| {
LocalPoint::new(vertex.position(), vertex.global().position())
Local::new(vertex.position(), vertex.global().position())
});
if let Some([a, b]) = vertices {
points.insert(0, a);
Expand All @@ -32,7 +37,7 @@ mod test {
use fj_math::Point;

use crate::{
geometry::LocalPoint,
local::Local,
objects::{GlobalVertex, Vertex, VerticesOfEdge},
};

Expand All @@ -51,10 +56,10 @@ mod test {
Vertex::new(Point::from([1.]), v2),
]);

let a = LocalPoint::new([0.0], a);
let b = LocalPoint::new([0.25], b);
let c = LocalPoint::new([0.75], c);
let d = LocalPoint::new([1.0], d);
let a = Local::new([0.0], a);
let b = Local::new([0.25], b);
let c = Local::new([0.75], c);
let d = Local::new([1.0], d);

// Regular edge
let mut points = vec![b, c];
Expand Down
20 changes: 5 additions & 15 deletions crates/fj-kernel/src/algorithms/approx/faces.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashSet;

use crate::{geometry::LocalPoint, objects::Face};
use fj_math::Point;

use crate::objects::Face;

use super::{CycleApprox, Tolerance};

Expand All @@ -11,7 +13,7 @@ pub struct FaceApprox {
///
/// These could be actual vertices from the model, points that approximate
/// an edge, or points that approximate a face.
pub points: HashSet<LocalPoint<3>>,
pub points: HashSet<Point<3>>,

/// Approximation of the exterior cycle
pub exterior: CycleApprox,
Expand Down Expand Up @@ -81,10 +83,7 @@ mod tests {
use fj_math::{Point, Scalar};
use map_macro::set;

use crate::{
geometry::LocalPoint,
objects::{Face, Surface},
};
use crate::objects::{Face, Surface};

use super::{CycleApprox, FaceApprox, Tolerance};

Expand Down Expand Up @@ -118,15 +117,6 @@ mod tests {
let g = g.to_xyz();
let h = h.to_xyz();

let a = LocalPoint::new(a, a);
let b = LocalPoint::new(b, b);
let c = LocalPoint::new(c, c);
let d = LocalPoint::new(d, d);
let e = LocalPoint::new(e, e);
let f = LocalPoint::new(f, f);
let g = LocalPoint::new(g, g);
let h = LocalPoint::new(h, h);

let approx = FaceApprox::new(&face, tolerance);
let expected = FaceApprox {
points: set![a, b, c, d, e, f, g, h],
Expand Down
7 changes: 3 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use fj_math::{Circle, Line, Point, Vector};

use crate::{
local::Local,
objects::{Curve, Cycle, CyclesInFace, Edge, Face},
shape::LocalForm,
};

/// Reverse the direction of a face
Expand Down Expand Up @@ -31,7 +31,7 @@ fn reverse_local_coordinates_in_cycle(
.iter()
.map(|edge| {
let curve = {
let local = match *edge.curve.local() {
let local = match edge.curve.local() {
Curve::Circle(Circle { center, a, b }) => {
let center = Point::from([center.u, -center.v]);

Expand All @@ -49,8 +49,7 @@ fn reverse_local_coordinates_in_cycle(
}
};

let canonical = *edge.curve.canonical();
LocalForm::new(local, canonical)
Local::new(local, edge.curve.global())
};
let vertices = edge.vertices.clone();

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use fj_math::{Point, Scalar, Transform, Triangle, Vector};

use crate::{
iter::ObjectIters,
local::Local,
objects::{
Curve, Cycle, Edge, Face, GlobalVertex, Surface, Vertex, VerticesOfEdge,
},
shape::LocalForm,
};

use super::{reverse_face, transform::transform_face, CycleApprox, Tolerance};
Expand Down Expand Up @@ -144,7 +144,7 @@ fn create_non_continuous_side_face(
let global = [a, b].map(|vertex| vertex.1.position());
let global = Curve::line_from_points(global);

LocalForm::new(local, global)
Local::new(local, global)
};

let vertices = VerticesOfEdge::from_vertices([
Expand All @@ -153,7 +153,7 @@ fn create_non_continuous_side_face(
]);

let edge = Edge {
curve: curve.clone(),
curve,
vertices: vertices.clone(),
};

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use fj_math::Transform;

use crate::{
local::Local,
objects::{
Cycle, CyclesInFace, Edge, Face, FaceBRep, GlobalVertex, Vertex,
},
shape::LocalForm,
};

/// Transform a shape
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn transform_cycles(
.edges
.iter()
.map(|edge| {
let curve_local = *edge.curve.local();
let curve_local = edge.curve.local();
let curve_canonical = edge.curve().transform(transform);

let vertices = edge
Expand All @@ -62,7 +62,7 @@ pub fn transform_cycles(
.map(|vertex| transform_vertex(&vertex, transform));

Edge {
curve: LocalForm::new(curve_local, curve_canonical),
curve: Local::new(curve_local, curve_canonical),
vertices,
}
})
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/triangulate/delaunay.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use fj_math::{Scalar, Triangle, Winding};
use fj_math::{Point, Scalar, Triangle, Winding};
use spade::HasPosition;

use crate::geometry::LocalPoint;
use crate::local::Local;

/// Create a Delaunay triangulation of all points
pub fn triangulate(points: Vec<LocalPoint<2>>) -> Vec<[LocalPoint<2>; 3]> {
pub fn triangulate(points: Vec<Local<Point<2>>>) -> Vec<[Local<Point<2>>; 3]> {
use spade::Triangulation as _;

let triangulation = spade::DelaunayTriangulation::<_>::bulk_load(points)
Expand All @@ -29,7 +29,7 @@ pub fn triangulate(points: Vec<LocalPoint<2>>) -> Vec<[LocalPoint<2>; 3]> {
}

// Enables the use of `LocalPoint` in the triangulation.
impl HasPosition for LocalPoint<2> {
impl HasPosition for Local<Point<2>> {
type Scalar = Scalar;

fn position(&self) -> spade::Point2<Self::Scalar> {
Expand Down
10 changes: 3 additions & 7 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ pub fn triangulate(
.map(|vertex| {
// Can't panic, unless the approximation wrongfully
// generates points that are not in the surface.
surface.point_to_surface_coords(vertex.global())
surface.point_to_surface_coords(vertex)
})
.collect();
let face_as_polygon = Polygon::new(surface)
.with_exterior(approx.exterior.points.into_iter().map(
|point| {
// Can't panic, unless the approximation wrongfully
// generates points that are not in the surface.
surface
.point_to_surface_coords(point.global())
.local()
surface.point_to_surface_coords(point).local()
},
))
.with_interiors(approx.interiors.into_iter().map(
Expand All @@ -50,9 +48,7 @@ pub fn triangulate(
// Can't panic, unless the approximation
// wrongfully generates points that are not in
// the surface.
surface
.point_to_surface_coords(point.global())
.local()
surface.point_to_surface_coords(point).local()
})
},
));
Expand Down
5 changes: 0 additions & 5 deletions crates/fj-kernel/src/geometry/mod.rs

This file was deleted.

55 changes: 0 additions & 55 deletions crates/fj-kernel/src/geometry/points.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/fj-kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@

pub mod algorithms;
pub mod builder;
pub mod geometry;
pub mod iter;
pub mod local;
pub mod objects;
pub mod shape;
pub mod validation;
Loading

0 comments on commit 4415967

Please sign in to comment.