Skip to content

Commit

Permalink
Merge pull request #694 from hannobraun/objects
Browse files Browse the repository at this point in the history
Move all objects to new `objects` module
  • Loading branch information
hannobraun authored Jun 14, 2022
2 parents 95cdb27 + 831a18a commit f14bea9
Show file tree
Hide file tree
Showing 32 changed files with 104 additions and 109 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/cycles.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/approx/edges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{geometry, topology::VerticesOfEdge};
use crate::{geometry, objects::VerticesOfEdge};

pub fn approximate_edge(
vertices: VerticesOfEdge,
Expand Down Expand Up @@ -36,8 +36,8 @@ mod test {

use crate::{
geometry,
objects::{Vertex, VerticesOfEdge},
shape::{LocalForm, Shape},
topology::{Vertex, VerticesOfEdge},
};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/faces.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use crate::{geometry, topology::Face};
use crate::{geometry, objects::Face};

use super::{CycleApprox, Tolerance};

Expand Down Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Curve<3>> {
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -329,9 +328,8 @@ mod tests {

use crate::{
algorithms::Tolerance,
geometry::Surface,
objects::{Face, Surface},
shape::{Handle, Shape},
topology::Face,
};

use super::sweep_shape;
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/triangulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/triangulation/polygon.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
15 changes: 2 additions & 13 deletions crates/fj-kernel/src/geometry/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
56 changes: 56 additions & 0 deletions crates/fj-kernel/src/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -74,7 +74,7 @@ mod tests {

use fj_math::{Line, Point, Vector};

use crate::geometry::Curve;
use crate::objects::Curve;

use super::SweptCurve;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
8 changes: 2 additions & 6 deletions crates/fj-kernel/src/shape/api.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 1 addition & 4 deletions crates/fj-kernel/src/shape/mapping.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 2 additions & 3 deletions crates/fj-kernel/src/shape/object.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
5 changes: 1 addition & 4 deletions crates/fj-kernel/src/shape/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/shape/validate/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -101,8 +101,8 @@ mod tests {
use fj_math::Scalar;

use crate::{
objects::Edge,
shape::{LocalForm, Shape},
topology::Edge,
};

#[test]
Expand Down
5 changes: 1 addition & 4 deletions crates/fj-kernel/src/shape/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
Loading

0 comments on commit f14bea9

Please sign in to comment.