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

Merge Curve into HalfEdge #1616

Merged
merged 17 commits into from
Feb 24, 2023
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
28 changes: 11 additions & 17 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::collections::BTreeMap;

use crate::{
geometry::path::{GlobalPath, SurfacePath},
objects::{Curve, GlobalEdge, HalfEdge, Surface},
objects::{GlobalEdge, HalfEdge, Surface},
storage::{Handle, ObjectId},
};

Expand Down Expand Up @@ -41,7 +41,7 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {
Some(approx) => approx,
None => {
let approx = approx_edge(
half_edge.curve(),
&half_edge.curve(),
surface,
range,
tolerance,
Expand All @@ -56,14 +56,10 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {
.map(|point| {
let point_surface = half_edge
.curve()
.path()
.point_from_path_coords(point.local_form);

ApproxPoint::new(point_surface, point.global_form)
.with_source((
half_edge.curve().clone(),
point.local_form,
))
.with_source((half_edge.clone(), point.local_form))
})
.collect()
};
Expand Down Expand Up @@ -95,7 +91,7 @@ impl HalfEdgeApprox {
}

fn approx_edge(
curve: &Curve,
curve: &SurfacePath,
surface: &Surface,
range: RangeOnPath,
tolerance: impl Into<Tolerance>,
Expand All @@ -106,14 +102,14 @@ fn approx_edge(
// This will probably all be unified eventually, as `SurfacePath` and
// `GlobalPath` grow APIs that are better suited to implementing this code
// in a more abstract way.
let points = match (curve.path(), surface.geometry().u) {
let points = match (curve, surface.geometry().u) {
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
todo!(
"Approximating a circle on a curved surface not supported yet."
)
}
(SurfacePath::Circle(_), GlobalPath::Line(_)) => {
(curve.path(), range)
(curve, range)
.approx_with_cache(tolerance, &mut ())
.into_iter()
.map(|(point_curve, point_surface)| {
Expand Down Expand Up @@ -142,7 +138,7 @@ fn approx_edge(
(SurfacePath::Line(line), _) => {
let range_u =
RangeOnPath::from(range.boundary.map(|point_curve| {
[curve.path().point_from_path_coords(point_curve).u]
[curve.point_from_path_coords(point_curve).u]
}));

let approx_u = (surface.geometry().u, range_u)
Expand All @@ -151,7 +147,7 @@ fn approx_edge(
let mut points = Vec::new();
for (u, _) in approx_u {
let t = (u.t - line.origin().u) / line.direction().u;
let point_surface = curve.path().point_from_path_coords([t]);
let point_surface = curve.point_from_path_coords([t]);
let point_global =
surface.geometry().point_from_surface_coords(point_surface);
points.push((u, point_global));
Expand Down Expand Up @@ -323,10 +319,8 @@ mod tests {
.approx(tolerance)
.into_iter()
.map(|(point_local, _)| {
let point_surface = half_edge
.curve()
.path()
.point_from_path_coords(point_local);
let point_surface =
half_edge.curve().point_from_path_coords(point_local);
let point_global =
surface.geometry().point_from_surface_coords(point_surface);
ApproxPoint::new(point_surface, point_global)
Expand Down Expand Up @@ -355,7 +349,7 @@ mod tests {
let approx = (&half_edge, surface.deref()).approx(tolerance);

let expected_approx =
(half_edge.curve().path(), RangeOnPath::from([[0.], [TAU]]))
(&half_edge.curve(), RangeOnPath::from([[0.], [TAU]]))
.approx(tolerance)
.into_iter()
.map(|(_, point_surface)| {
Expand Down
6 changes: 1 addition & 5 deletions crates/fj-kernel/src/algorithms/approx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use std::{

use fj_math::Point;

use crate::{
objects::{Curve, HalfEdge},
storage::Handle,
};
use crate::{objects::HalfEdge, storage::Handle};

pub use self::tolerance::{InvalidTolerance, Tolerance};

Expand Down Expand Up @@ -121,5 +118,4 @@ impl<const D: usize> PartialOrd for ApproxPoint<D> {
/// The source of an [`ApproxPoint`]
pub trait Source: Any + Debug {}

impl Source for (Handle<Curve>, Point<1>) {}
impl Source for (Handle<HalfEdge>, Point<1>) {}
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/approx/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::geometry::path::{GlobalPath, SurfacePath};

use super::{Approx, Tolerance};

impl Approx for (SurfacePath, RangeOnPath) {
impl Approx for (&SurfacePath, RangeOnPath) {
type Approximation = Vec<(Point<1>, Point<2>)>;
type Cache = ();

Expand All @@ -49,7 +49,7 @@ impl Approx for (SurfacePath, RangeOnPath) {

match path {
SurfacePath::Circle(circle) => {
approx_circle(&circle, range, tolerance.into())
approx_circle(circle, range, tolerance.into())
}
SurfacePath::Line(_) => vec![],
}
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 @@ -35,7 +35,7 @@ impl CurveEdgeIntersection {
};

let edge_as_segment = {
let edge_curve_as_line = match half_edge.curve().path() {
let edge_curve_as_line = match half_edge.curve() {
SurfacePath::Line(line) => line,
_ => {
todo!("Curve-edge intersection only supports line segments")
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 @@ -17,7 +17,7 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Handle<HalfEdge>) {
fn intersect(self) -> Option<Self::Intersection> {
let (ray, edge) = self;

let line = match edge.curve().path() {
let line = match edge.curve() {
SurfacePath::Line(line) => line,
SurfacePath::Circle(_) => {
todo!("Casting rays against circles is not supported yet")
Expand Down
8 changes: 2 additions & 6 deletions crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ impl Reverse for Handle<HalfEdge> {
[b, a]
};

HalfEdge::new(
self.curve().clone(),
vertices,
self.global_form().clone(),
)
.insert(objects)
HalfEdge::new(self.curve(), vertices, self.global_form().clone())
.insert(objects)
}
}
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::{
builder::SurfaceBuilder,
geometry::path::{GlobalPath, SurfacePath},
insert::Insert,
objects::{Curve, Objects, Surface},
objects::{Objects, Surface},
partial::{PartialObject, PartialSurface},
services::Service,
storage::Handle,
};

use super::{Sweep, SweepCache};

impl Sweep for (Handle<Curve>, &Surface) {
impl Sweep for (SurfacePath, &Surface) {
type Swept = Handle<Surface>;

fn sweep_with_cache(
Expand Down Expand Up @@ -47,7 +47,7 @@ impl Sweep for (Handle<Curve>, &Surface) {
}
}

let u = match curve.path() {
let u = match curve {
SurfacePath::Circle(circle) => {
let center = surface
.geometry()
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl Sweep for (Handle<HalfEdge>, &Surface, Color) {
// we're sweeping.
{
let surface = Partial::from(
(edge.curve().clone(), surface)
.sweep_with_cache(path, cache, objects),
(edge.curve(), surface).sweep_with_cache(path, cache, objects),
);
face.surface = surface;
}
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ impl Sweep for Handle<Face> {
.into_iter()
.zip(top_cycle.write().half_edges.iter_mut())
{
top.write().curve.write().path =
Some(bottom.curve().path().into());
top.write().curve = Some(bottom.curve().into());

let boundary = bottom.boundary();

Expand Down
23 changes: 0 additions & 23 deletions crates/fj-kernel/src/algorithms/transform/curve.rs

This file was deleted.

7 changes: 3 additions & 4 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ impl TransformObject for HalfEdge {
objects: &mut Service<Objects>,
cache: &mut TransformCache,
) -> Self {
let curve = self
.curve()
.clone()
.transform_with_cache(transform, objects, cache);
// Don't need to transform curve, as that's defined in surface
// coordinates.
let curve = self.curve();
let boundary = self.boundary().zip_ext(self.surface_vertices()).map(
|(point, surface_vertex)| {
let surface_vertex = surface_vertex
Expand Down
1 change: 0 additions & 1 deletion crates/fj-kernel/src/algorithms/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! API for transforming objects

mod curve;
mod cycle;
mod edge;
mod face;
Expand Down
9 changes: 0 additions & 9 deletions crates/fj-kernel/src/builder/curve.rs

This file was deleted.

Loading