diff --git a/crates/fj-kernel/src/algorithms/approx/curves.rs b/crates/fj-kernel/src/algorithms/approx/curves.rs index 63b6508ab..6aaa93525 100644 --- a/crates/fj-kernel/src/algorithms/approx/curves.rs +++ b/crates/fj-kernel/src/algorithms/approx/curves.rs @@ -2,7 +2,7 @@ use std::cmp::max; use fj_math::{Circle, Scalar}; -use crate::geometry::{self, Curve}; +use crate::{geometry, objects::Curve}; use super::Tolerance; diff --git a/crates/fj-kernel/src/algorithms/approx/cycles.rs b/crates/fj-kernel/src/algorithms/approx/cycles.rs index 9cba6c1cf..d591fba91 100644 --- a/crates/fj-kernel/src/algorithms/approx/cycles.rs +++ b/crates/fj-kernel/src/algorithms/approx/cycles.rs @@ -1,6 +1,6 @@ use fj_math::Segment; -use crate::{geometry, topology::Cycle}; +use crate::{geometry, objects::Cycle}; use super::{curves::approx_curve, edges::approximate_edge, Tolerance}; diff --git a/crates/fj-kernel/src/algorithms/approx/edges.rs b/crates/fj-kernel/src/algorithms/approx/edges.rs index 5fd96a55a..c099b6f12 100644 --- a/crates/fj-kernel/src/algorithms/approx/edges.rs +++ b/crates/fj-kernel/src/algorithms/approx/edges.rs @@ -1,4 +1,4 @@ -use crate::{geometry, topology::VerticesOfEdge}; +use crate::{geometry, objects::VerticesOfEdge}; pub fn approximate_edge( vertices: VerticesOfEdge, @@ -36,8 +36,8 @@ mod test { use crate::{ geometry, + objects::{Vertex, VerticesOfEdge}, shape::{LocalForm, Shape}, - topology::{Vertex, VerticesOfEdge}, }; #[test] diff --git a/crates/fj-kernel/src/algorithms/approx/faces.rs b/crates/fj-kernel/src/algorithms/approx/faces.rs index 5cb6afd63..9ac8b03a7 100644 --- a/crates/fj-kernel/src/algorithms/approx/faces.rs +++ b/crates/fj-kernel/src/algorithms/approx/faces.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use crate::{geometry, topology::Face}; +use crate::{geometry, objects::Face}; use super::{CycleApprox, Tolerance}; @@ -82,9 +82,9 @@ mod tests { use map_macro::set; use crate::{ - geometry::{self, Surface}, + geometry, + objects::{Face, Surface}, shape::Shape, - topology::Face, }; use super::{CycleApprox, FaceApprox, Tolerance}; diff --git a/crates/fj-kernel/src/algorithms/intersection/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersection/surface_surface.rs index 916e0b0e3..2ec355905 100644 --- a/crates/fj-kernel/src/algorithms/intersection/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersection/surface_surface.rs @@ -1,6 +1,6 @@ use fj_math::{Line, Point, Scalar, Vector}; -use crate::geometry::{Curve, Surface}; +use crate::objects::{Curve, Surface}; /// Test intersection between two surfaces pub fn surface_surface(a: &Surface, b: &Surface) -> Option> { @@ -60,7 +60,7 @@ fn extract_plane(surface: &Surface) -> (Vector<3>, Scalar) { mod tests { use fj_math::Transform; - use crate::geometry::{Curve, Surface}; + use crate::objects::{Curve, Surface}; use super::surface_surface; diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index f0eaaeceb..af00299b7 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -3,9 +3,8 @@ use std::collections::HashMap; use fj_math::{Line, Scalar, Transform, Triangle, Vector}; use crate::{ - geometry::{Curve, Surface, SweptCurve}, + objects::{Curve, Cycle, Edge, Face, Surface, SweptCurve, Vertex}, shape::{Handle, LocalForm, Mapping, Shape, ValidationError}, - topology::{Cycle, Edge, Face, Vertex}, }; use super::{transform_shape, CycleApprox, Tolerance}; @@ -329,9 +328,8 @@ mod tests { use crate::{ algorithms::Tolerance, - geometry::Surface, + objects::{Face, Surface}, shape::{Handle, Shape}, - topology::Face, }; use super::sweep_shape; diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 614c7459b..45a0c9a5a 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -1,9 +1,8 @@ use fj_math::Transform; use crate::{ - geometry::{Curve, Surface}, + objects::{Curve, Face, Surface, Vertex}, shape::{Shape, ValidationError}, - topology::{Face, Vertex}, }; /// Transform the geometry of the shape diff --git a/crates/fj-kernel/src/algorithms/triangulation/mod.rs b/crates/fj-kernel/src/algorithms/triangulation/mod.rs index 06072e0b4..09a503ebf 100644 --- a/crates/fj-kernel/src/algorithms/triangulation/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulation/mod.rs @@ -5,7 +5,7 @@ mod ray; use fj_interop::{debug::DebugInfo, mesh::Mesh}; use fj_math::Point; -use crate::{shape::Shape, topology::Face}; +use crate::{objects::Face, shape::Shape}; use self::polygon::Polygon; @@ -88,7 +88,9 @@ mod tests { use fj_math::{Point, Scalar}; use crate::{ - algorithms::Tolerance, geometry::Surface, shape::Shape, topology::Face, + algorithms::Tolerance, + objects::{Face, Surface}, + shape::Shape, }; #[test] diff --git a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs index 5630b876f..f813a7a13 100644 --- a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs +++ b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs @@ -1,7 +1,7 @@ use fj_interop::debug::{DebugInfo, TriangleEdgeCheck}; use fj_math::{Point, PolyChain, Segment}; -use crate::geometry::Surface; +use crate::objects::Surface; use super::ray::{Hit, HorizontalRayToTheRight}; @@ -221,7 +221,7 @@ mod tests { use fj_interop::debug::DebugInfo; use fj_math::{Point, PolyChain}; - use crate::geometry::Surface; + use crate::objects::Surface; use super::Polygon; diff --git a/crates/fj-kernel/src/topology/builder.rs b/crates/fj-kernel/src/builder.rs similarity index 98% rename from crates/fj-kernel/src/topology/builder.rs rename to crates/fj-kernel/src/builder.rs index d52832f31..7e62f59b7 100644 --- a/crates/fj-kernel/src/topology/builder.rs +++ b/crates/fj-kernel/src/builder.rs @@ -1,12 +1,12 @@ +//! Convenient API to build objects + use fj_math::{Circle, Line, Point, Scalar, Vector}; use crate::{ - geometry::{Curve, Surface}, + objects::{Curve, Cycle, Edge, Face, Surface, Vertex, VerticesOfEdge}, shape::{Handle, LocalForm, Shape, ValidationError, ValidationResult}, }; -use super::{Cycle, Edge, Face, Vertex, VerticesOfEdge}; - /// API for building a [`Vertex`] #[must_use] pub struct VertexBuilder<'r> { diff --git a/crates/fj-kernel/src/geometry/mod.rs b/crates/fj-kernel/src/geometry/mod.rs index c965245d1..39d98cd21 100644 --- a/crates/fj-kernel/src/geometry/mod.rs +++ b/crates/fj-kernel/src/geometry/mod.rs @@ -1,16 +1,5 @@ -//! Geometry objects -//! -//! Simplifying a bit, geometry is responsible for where things are, but now how -//! they are related. The types in this module are referred to by the types in -//! [`crate::topology`], which are responsible for defining how objects are -//! related. +//! Miscellaneous geometry code -mod curves; mod points; -mod surfaces; -pub use self::{ - curves::Curve, - points::Point, - surfaces::{Surface, SweptCurve}, -}; +pub use self::points::Point; diff --git a/crates/fj-kernel/src/lib.rs b/crates/fj-kernel/src/lib.rs index 43e330541..f2f344afc 100644 --- a/crates/fj-kernel/src/lib.rs +++ b/crates/fj-kernel/src/lib.rs @@ -88,6 +88,7 @@ #![warn(missing_docs)] pub mod algorithms; +pub mod builder; pub mod geometry; +pub mod objects; pub mod shape; -pub mod topology; diff --git a/crates/fj-kernel/src/geometry/curves.rs b/crates/fj-kernel/src/objects/curves.rs similarity index 100% rename from crates/fj-kernel/src/geometry/curves.rs rename to crates/fj-kernel/src/objects/curves.rs diff --git a/crates/fj-kernel/src/topology/cycle.rs b/crates/fj-kernel/src/objects/cycle.rs similarity index 96% rename from crates/fj-kernel/src/topology/cycle.rs rename to crates/fj-kernel/src/objects/cycle.rs index 005b431b0..dc2927cb2 100644 --- a/crates/fj-kernel/src/topology/cycle.rs +++ b/crates/fj-kernel/src/objects/cycle.rs @@ -1,9 +1,9 @@ use crate::{ - geometry::Surface, + builder::CycleBuilder, shape::{Handle, LocalForm, Shape}, }; -use super::{CycleBuilder, Edge}; +use super::{Edge, Surface}; /// A cycle of connected edges /// diff --git a/crates/fj-kernel/src/topology/edge.rs b/crates/fj-kernel/src/objects/edge.rs similarity index 98% rename from crates/fj-kernel/src/topology/edge.rs rename to crates/fj-kernel/src/objects/edge.rs index cf0446af8..a08582adf 100644 --- a/crates/fj-kernel/src/topology/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -3,11 +3,11 @@ use std::fmt; use fj_math::Point; use crate::{ - geometry::Curve, + builder::EdgeBuilder, shape::{LocalForm, Shape}, }; -use super::{EdgeBuilder, Vertex}; +use super::{Curve, Vertex}; /// An edge of a shape /// diff --git a/crates/fj-kernel/src/topology/face.rs b/crates/fj-kernel/src/objects/face.rs similarity index 99% rename from crates/fj-kernel/src/topology/face.rs rename to crates/fj-kernel/src/objects/face.rs index 1e9f6bf8c..1f0788c6b 100644 --- a/crates/fj-kernel/src/topology/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -4,11 +4,11 @@ use fj_interop::mesh::Color; use fj_math::Triangle; use crate::{ - geometry::Surface, + builder::FaceBuilder, shape::{Handle, LocalForm, Shape}, }; -use super::{Cycle, FaceBuilder}; +use super::{Cycle, Surface}; /// A face of a shape /// diff --git a/crates/fj-kernel/src/objects/mod.rs b/crates/fj-kernel/src/objects/mod.rs new file mode 100644 index 000000000..e28d5a3db --- /dev/null +++ b/crates/fj-kernel/src/objects/mod.rs @@ -0,0 +1,56 @@ +//! Objects of a shape +//! +//! Objects, in Fornjot parlance, are the elements that make up shapes. An +//! object can be simple and just contain data (like, for example, [`Vertex`]), +//! or they can be quite complex and refer to other objects. +//! +//! # Equality +//! +//! Two objects, even if they are distinct and live in different memory +//! locations, are considered equal, if the data they contain and the objects +//! they reference are considered equal. +//! +//! In contrast to that, two [`Handle`]s are considered equal, only if they +//! reference the same object, in the same memory location. This means that two +//! objects can be considered equal, even if the [`Handle`]s they contain are +//! not. +//! +//! Equality is defined like this, two cover two distinct use cases: +//! +//! - If you need to know whether two [`Handle`]s actually refer to the same +//! object in the same [`Shape`], you can compare the [`Handle`]s. +//! - If you only need to check whether two objects look the same, but don't +//! care whether they are in the same shape, compare the objects directly. +//! +//! The second use case is common in test code. +//! +//! # Implementation Note +//! +//! The definition of equality, as detailed above, is overly complex. It is +//! necessary though, due to the way the kernel's core data structures work. +//! Each shape's objects are stored in a distinct [`Shape`] structure, even if +//! there is a high amount of redundancy between those shapes. +//! +//! If there was a single, append-only data structure for all objects in a CAD +//! model, in which objects were immutable, there would be no special definition +//! of equality for objects. Unfortunately, nobody has figured out how to make +//! this work yet. +//! +//! [`Handle`]: crate::shape::Handle +//! [`Shape`]: crate::shape::Shape + +mod curves; +mod cycle; +mod edge; +mod face; +mod surfaces; +mod vertex; + +pub use self::{ + curves::Curve, + cycle::Cycle, + edge::{Edge, VerticesOfEdge}, + face::{CyclesInFace, Face}, + surfaces::{Surface, SweptCurve}, + vertex::Vertex, +}; diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/objects/surfaces/mod.rs similarity index 100% rename from crates/fj-kernel/src/geometry/surfaces/mod.rs rename to crates/fj-kernel/src/objects/surfaces/mod.rs diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/objects/surfaces/swept.rs similarity index 98% rename from crates/fj-kernel/src/geometry/surfaces/swept.rs rename to crates/fj-kernel/src/objects/surfaces/swept.rs index d3458126f..a5997871e 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/objects/surfaces/swept.rs @@ -1,6 +1,6 @@ use fj_math::{Line, Point, Transform, Vector}; -use crate::geometry::Curve; +use crate::objects::Curve; /// A surface that was swept from a curve #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] @@ -74,7 +74,7 @@ mod tests { use fj_math::{Line, Point, Vector}; - use crate::geometry::Curve; + use crate::objects::Curve; use super::SweptCurve; diff --git a/crates/fj-kernel/src/topology/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs similarity index 95% rename from crates/fj-kernel/src/topology/vertex.rs rename to crates/fj-kernel/src/objects/vertex.rs index 797ead354..3f2e67a3b 100644 --- a/crates/fj-kernel/src/topology/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -2,9 +2,7 @@ use std::hash::Hash; use fj_math::Point; -use crate::shape::Shape; - -use super::VertexBuilder; +use crate::{builder::VertexBuilder, shape::Shape}; /// A vertex /// diff --git a/crates/fj-kernel/src/shape/api.rs b/crates/fj-kernel/src/shape/api.rs index eb02f3242..7070a83cf 100644 --- a/crates/fj-kernel/src/shape/api.rs +++ b/crates/fj-kernel/src/shape/api.rs @@ -1,9 +1,6 @@ use fj_math::Scalar; -use crate::{ - geometry::{Curve, Surface}, - topology::{Cycle, Edge, Face, Vertex}, -}; +use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex}; use super::{ stores::{Store, Stores}, @@ -295,9 +292,8 @@ mod tests { use fj_math::{Point, Scalar}; use crate::{ - geometry::{Curve, Surface}, + objects::{Curve, Cycle, Edge, Face, Surface, Vertex, VerticesOfEdge}, shape::{Handle, LocalForm, Shape, ValidationError, ValidationResult}, - topology::{Cycle, Edge, Face, Vertex, VerticesOfEdge}, }; #[test] diff --git a/crates/fj-kernel/src/shape/mapping.rs b/crates/fj-kernel/src/shape/mapping.rs index 329835db1..3cd317f4e 100644 --- a/crates/fj-kernel/src/shape/mapping.rs +++ b/crates/fj-kernel/src/shape/mapping.rs @@ -1,9 +1,6 @@ use std::collections::HashMap; -use crate::{ - geometry::{Curve, Surface}, - topology::{Cycle, Edge, Face, Vertex}, -}; +use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex}; use super::Handle; diff --git a/crates/fj-kernel/src/shape/object.rs b/crates/fj-kernel/src/shape/object.rs index 29142939f..a85bc20d2 100644 --- a/crates/fj-kernel/src/shape/object.rs +++ b/crates/fj-kernel/src/shape/object.rs @@ -1,6 +1,5 @@ -use crate::{ - geometry::{Curve, Surface}, - topology::{Cycle, Edge, Face, Vertex, VerticesOfEdge}, +use crate::objects::{ + Curve, Cycle, Edge, Face, Surface, Vertex, VerticesOfEdge, }; use super::{ diff --git a/crates/fj-kernel/src/shape/stores.rs b/crates/fj-kernel/src/shape/stores.rs index 9e780a98e..8cf10cd4e 100644 --- a/crates/fj-kernel/src/shape/stores.rs +++ b/crates/fj-kernel/src/shape/stores.rs @@ -8,10 +8,7 @@ use anymap::AnyMap; use parking_lot::{RwLock, RwLockReadGuard}; use slotmap::{DefaultKey, SlotMap}; -use crate::{ - geometry::{Curve, Surface}, - topology::{Cycle, Edge, Face, Vertex}, -}; +use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex}; use super::Object; diff --git a/crates/fj-kernel/src/shape/validate/coherence.rs b/crates/fj-kernel/src/shape/validate/coherence.rs index 6030e4873..1d5461648 100644 --- a/crates/fj-kernel/src/shape/validate/coherence.rs +++ b/crates/fj-kernel/src/shape/validate/coherence.rs @@ -2,7 +2,7 @@ use std::fmt; use fj_math::{Point, Scalar}; -use crate::topology::Edge; +use crate::objects::Edge; pub fn validate_edge( edge: &Edge<3>, @@ -101,8 +101,8 @@ mod tests { use fj_math::Scalar; use crate::{ + objects::Edge, shape::{LocalForm, Shape}, - topology::Edge, }; #[test] diff --git a/crates/fj-kernel/src/shape/validate/mod.rs b/crates/fj-kernel/src/shape/validate/mod.rs index 32d5bf966..6882d9da5 100644 --- a/crates/fj-kernel/src/shape/validate/mod.rs +++ b/crates/fj-kernel/src/shape/validate/mod.rs @@ -10,10 +10,7 @@ pub use self::{ use fj_math::Scalar; -use crate::{ - geometry::{Curve, Surface}, - topology::{Cycle, Edge, Face, Vertex}, -}; +use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex}; use super::{stores::Stores, Handle, Object}; diff --git a/crates/fj-kernel/src/shape/validate/structural.rs b/crates/fj-kernel/src/shape/validate/structural.rs index cc37e814b..59b6279df 100644 --- a/crates/fj-kernel/src/shape/validate/structural.rs +++ b/crates/fj-kernel/src/shape/validate/structural.rs @@ -1,9 +1,8 @@ use std::{collections::HashSet, fmt}; use crate::{ - geometry::{Curve, Surface}, + objects::{Curve, Cycle, Edge, Face, Surface, Vertex}, shape::{stores::Stores, Handle}, - topology::{Cycle, Edge, Face, Vertex}, }; pub fn validate_edge( diff --git a/crates/fj-kernel/src/shape/validate/uniqueness.rs b/crates/fj-kernel/src/shape/validate/uniqueness.rs index 0768c3f69..a9757bb3c 100644 --- a/crates/fj-kernel/src/shape/validate/uniqueness.rs +++ b/crates/fj-kernel/src/shape/validate/uniqueness.rs @@ -1,8 +1,8 @@ use std::fmt; use crate::{ + objects::{Edge, Vertex}, shape::{stores::Store, Handle}, - topology::{Edge, Vertex}, }; pub fn validate_vertex( diff --git a/crates/fj-kernel/src/topology/mod.rs b/crates/fj-kernel/src/topology/mod.rs deleted file mode 100644 index c2b70833d..000000000 --- a/crates/fj-kernel/src/topology/mod.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Topological objects -//! -//! Simplifying a bit, topology is responsible for defining how objects are -//! related, as opposed to geometry, which is responsible for where things are. -//! -//! The types in this module use the types from [`crate::geometry`]. -//! -//! # Equality -//! -//! Equality of topological objects is defined in terms of the geometry they -//! refer to. That means two topological objects that refer to identical -//! geometry are considered equal, even if they contain [`Handle`]s that refer -//! to objects in different [`Shape`] instances. -//! -//! This is different from the equality of [`Handle`], which follows a strict -//! definition of identity. Two [`Handle`]s are only considered equal, if they -//! refer to objects in the same memory location. - -mod builder; -mod cycle; -mod edge; -mod face; -mod vertex; - -pub use self::{ - builder::{CycleBuilder, EdgeBuilder, FaceBuilder, VertexBuilder}, - cycle::Cycle, - edge::{Edge, VerticesOfEdge}, - face::{CyclesInFace, Face}, - vertex::Vertex, -}; diff --git a/crates/fj-operations/src/circle.rs b/crates/fj-operations/src/circle.rs index c975da62e..7d1c56827 100644 --- a/crates/fj-operations/src/circle.rs +++ b/crates/fj-operations/src/circle.rs @@ -1,9 +1,8 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::Tolerance, - geometry::Surface, + objects::{Cycle, Edge, Face, Surface}, shape::{LocalForm, Shape, ValidationError}, - topology::{Cycle, Edge, Face}, }; use fj_math::{Aabb, Point, Scalar}; diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 5a36d1120..414873b8b 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -1,8 +1,8 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::Tolerance, + objects::{Cycle, Edge, Face}, shape::{LocalForm, Shape, ValidationError}, - topology::{Cycle, Edge, Face}, }; use fj_math::Aabb; diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 9247658fe..f9f24256c 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -1,9 +1,8 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::Tolerance, - geometry::Surface, + objects::{Face, Surface}, shape::{Shape, ValidationError}, - topology::Face, }; use fj_math::{Aabb, Point};