mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-06 15:25:53 +00:00
Remove GlobalCurve
from Curve
/PartialCurve
This commit is contained in:
parent
944f791cf1
commit
4befa7c6e8
@ -3,7 +3,7 @@ use fj_math::{Line, Plane, Point, Scalar};
|
||||
use crate::{
|
||||
geometry::path::{GlobalPath, SurfacePath},
|
||||
insert::Insert,
|
||||
objects::{Curve, GlobalCurve, Objects, Surface},
|
||||
objects::{Curve, Objects, Surface},
|
||||
services::Service,
|
||||
storage::Handle,
|
||||
};
|
||||
@ -55,9 +55,7 @@ impl SurfaceSurfaceIntersection {
|
||||
|
||||
let curves = planes.map(|plane| {
|
||||
let path = SurfacePath::Line(plane.project_line(&line));
|
||||
let global_form = GlobalCurve.insert(objects);
|
||||
|
||||
Curve::new(path, global_form).insert(objects)
|
||||
Curve::new(path).insert(objects)
|
||||
});
|
||||
|
||||
Some(Self {
|
||||
|
@ -135,9 +135,6 @@ impl Sweep for (Handle<HalfEdge>, &Surface, Color) {
|
||||
.zip_ext(global_edges)
|
||||
.map(|(mut half_edge, global_edge)| {
|
||||
let global_edge = Partial::from(global_edge);
|
||||
|
||||
half_edge.curve.write().global_form =
|
||||
global_edge.read().curve.clone();
|
||||
half_edge.global_form = global_edge;
|
||||
});
|
||||
|
||||
|
@ -10,20 +10,15 @@ use super::{TransformCache, TransformObject};
|
||||
impl TransformObject for Curve {
|
||||
fn transform_with_cache(
|
||||
self,
|
||||
transform: &Transform,
|
||||
objects: &mut Service<Objects>,
|
||||
cache: &mut TransformCache,
|
||||
_: &Transform,
|
||||
_: &mut Service<Objects>,
|
||||
_: &mut TransformCache,
|
||||
) -> Self {
|
||||
// Don't need to transform path, as that's defined in surface
|
||||
// coordinates, and thus transforming `surface` takes care of it.
|
||||
let path = self.path();
|
||||
|
||||
let global_form = self
|
||||
.global_form()
|
||||
.clone()
|
||||
.transform_with_cache(transform, objects, cache);
|
||||
|
||||
Self::new(path, global_form)
|
||||
Self::new(path)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,7 +224,6 @@ impl HalfEdgeBuilder for PartialHalfEdge {
|
||||
surface: &SurfaceGeometry,
|
||||
) {
|
||||
let global_curve = other.read().global_form.read().curve.clone();
|
||||
self.curve.write().global_form = global_curve.clone();
|
||||
self.global_form.write().curve = global_curve;
|
||||
|
||||
self.curve.write().path =
|
||||
|
@ -1,36 +1,21 @@
|
||||
use crate::{
|
||||
geometry::path::SurfacePath,
|
||||
storage::{Handle, HandleWrapper},
|
||||
};
|
||||
use crate::geometry::path::SurfacePath;
|
||||
|
||||
/// A curve, defined in local surface coordinates
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub struct Curve {
|
||||
path: SurfacePath,
|
||||
global_form: HandleWrapper<GlobalCurve>,
|
||||
}
|
||||
|
||||
impl Curve {
|
||||
/// Construct a new instance of `Curve`
|
||||
pub fn new(
|
||||
path: SurfacePath,
|
||||
global_form: impl Into<HandleWrapper<GlobalCurve>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
path,
|
||||
global_form: global_form.into(),
|
||||
}
|
||||
pub fn new(path: SurfacePath) -> Self {
|
||||
Self { path }
|
||||
}
|
||||
|
||||
/// Access the path that defines the curve
|
||||
pub fn path(&self) -> SurfacePath {
|
||||
self.path
|
||||
}
|
||||
|
||||
/// Access the global form of the curve
|
||||
pub fn global_form(&self) -> &Handle<GlobalCurve> {
|
||||
&self.global_form
|
||||
}
|
||||
}
|
||||
|
||||
/// A curve, defined in global (3D) coordinates
|
||||
|
@ -3,7 +3,7 @@ use fj_math::Scalar;
|
||||
use crate::{
|
||||
geometry::path::SurfacePath,
|
||||
objects::{Curve, GlobalCurve, Objects},
|
||||
partial::{FullToPartialCache, Partial, PartialObject},
|
||||
partial::{FullToPartialCache, PartialObject},
|
||||
services::Service,
|
||||
};
|
||||
|
||||
@ -12,22 +12,18 @@ use crate::{
|
||||
pub struct PartialCurve {
|
||||
/// The path that defines the curve
|
||||
pub path: Option<MaybeSurfacePath>,
|
||||
|
||||
/// The global form of the curve
|
||||
pub global_form: Partial<GlobalCurve>,
|
||||
}
|
||||
|
||||
impl PartialObject for PartialCurve {
|
||||
type Full = Curve;
|
||||
|
||||
fn from_full(curve: &Self::Full, cache: &mut FullToPartialCache) -> Self {
|
||||
fn from_full(curve: &Self::Full, _: &mut FullToPartialCache) -> Self {
|
||||
Self {
|
||||
path: Some(curve.path().into()),
|
||||
global_form: Partial::from_full(curve.global_form().clone(), cache),
|
||||
}
|
||||
}
|
||||
|
||||
fn build(self, objects: &mut Service<Objects>) -> Self::Full {
|
||||
fn build(self, _: &mut Service<Objects>) -> Self::Full {
|
||||
let path = match self.path.expect("Need path to build curve") {
|
||||
MaybeSurfacePath::Defined(path) => path,
|
||||
undefined => {
|
||||
@ -36,9 +32,8 @@ impl PartialObject for PartialCurve {
|
||||
)
|
||||
}
|
||||
};
|
||||
let global_form = self.global_form.build(objects);
|
||||
|
||||
Curve::new(path, global_form)
|
||||
Curve::new(path)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,6 @@ impl Default for PartialHalfEdge {
|
||||
(None, surface_form)
|
||||
});
|
||||
|
||||
let global_curve = curve.read().global_form.clone();
|
||||
let global_vertices = vertices.each_ref_ext().map(
|
||||
|vertex: &(Option<Point<1>>, Partial<SurfaceVertex>)| {
|
||||
let surface_vertex = vertex.1.clone();
|
||||
@ -84,8 +83,8 @@ impl Default for PartialHalfEdge {
|
||||
);
|
||||
|
||||
let global_form = Partial::from_partial(PartialGlobalEdge {
|
||||
curve: global_curve,
|
||||
vertices: global_vertices,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
Self {
|
||||
|
@ -13,7 +13,6 @@ impl Validate for HalfEdge {
|
||||
config: &ValidationConfig,
|
||||
errors: &mut Vec<ValidationError>,
|
||||
) {
|
||||
HalfEdgeValidationError::check_global_curve_identity(self, errors);
|
||||
HalfEdgeValidationError::check_global_vertex_identity(self, errors);
|
||||
HalfEdgeValidationError::check_vertex_coincidence(self, config, errors);
|
||||
}
|
||||
@ -107,26 +106,6 @@ pub enum HalfEdgeValidationError {
|
||||
}
|
||||
|
||||
impl HalfEdgeValidationError {
|
||||
fn check_global_curve_identity(
|
||||
half_edge: &HalfEdge,
|
||||
errors: &mut Vec<ValidationError>,
|
||||
) {
|
||||
let global_curve_from_curve = half_edge.curve().global_form();
|
||||
let global_curve_from_global_form = half_edge.global_form().curve();
|
||||
|
||||
if global_curve_from_curve.id() != global_curve_from_global_form.id() {
|
||||
errors.push(
|
||||
Box::new(Self::GlobalCurveMismatch {
|
||||
global_curve_from_curve: global_curve_from_curve.clone(),
|
||||
global_curve_from_global_form:
|
||||
global_curve_from_global_form.clone(),
|
||||
half_edge: half_edge.clone(),
|
||||
})
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_global_vertex_identity(
|
||||
half_edge: &HalfEdge,
|
||||
errors: &mut Vec<ValidationError>,
|
||||
@ -185,47 +164,12 @@ mod tests {
|
||||
|
||||
use crate::{
|
||||
builder::HalfEdgeBuilder,
|
||||
insert::Insert,
|
||||
objects::{GlobalCurve, HalfEdge},
|
||||
objects::HalfEdge,
|
||||
partial::{Partial, PartialHalfEdge, PartialObject},
|
||||
services::Services,
|
||||
validate::Validate,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn half_edge_global_curve_mismatch() -> anyhow::Result<()> {
|
||||
let mut services = Services::new();
|
||||
|
||||
let valid = {
|
||||
let surface = services.objects.surfaces.xy_plane();
|
||||
|
||||
let mut half_edge = PartialHalfEdge::default();
|
||||
half_edge.update_as_line_segment_from_points([[0., 0.], [1., 0.]]);
|
||||
half_edge.infer_vertex_positions_if_necessary(&surface.geometry());
|
||||
|
||||
half_edge.build(&mut services.objects)
|
||||
};
|
||||
let invalid = {
|
||||
let global_form = {
|
||||
let mut global_edge =
|
||||
Partial::from(valid.global_form().clone());
|
||||
global_edge.write().curve =
|
||||
Partial::from(GlobalCurve.insert(&mut services.objects));
|
||||
global_edge.build(&mut services.objects)
|
||||
};
|
||||
let vertices = valid
|
||||
.boundary()
|
||||
.zip_ext(valid.surface_vertices().map(Clone::clone));
|
||||
|
||||
HalfEdge::new(valid.curve().clone(), vertices, global_form)
|
||||
};
|
||||
|
||||
valid.validate_and_return_first_error()?;
|
||||
assert!(invalid.validate_and_return_first_error().is_err());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn half_edge_global_vertex_mismatch() -> anyhow::Result<()> {
|
||||
let mut services = Services::new();
|
||||
|
Loading…
Reference in New Issue
Block a user