-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from novartole/dev
Back | sal-3dlib | structures & traits
- Loading branch information
Showing
57 changed files
with
168,588 additions
and
634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[package] | ||
name = "sal-3dlib" | ||
version = "0.1.0" | ||
edition = "2021" | ||
[workspace] | ||
resolver = "2" | ||
members = ["crates/*"] | ||
exclude = ["research/try-occt-rs"] | ||
|
||
[dependencies] | ||
log = "^0.4" | ||
[workspace.dependencies] | ||
debugging = { git = "https://github.com/a-givertzman/rust-debuging.git", tag = "0.0.1" } | ||
env_logger = "^0.11" | ||
|
||
log = "^0.4" | ||
sal-sync = { git = "https://github.com/a-givertzman/rust-sal-sync.git" } | ||
testing = { git = "https://github.com/a-givertzman/rust-testing.git" } | ||
debugging = { git = "https://github.com/a-givertzman/rust-debuging.git", tag = "0.0.1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "sal-3dlib-core" | ||
version = "0.0.1" | ||
edition = "2021" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! Defining the [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box). | ||
/// | ||
/// Create a bounding box. | ||
pub trait Bound<T> { | ||
/// | ||
/// Creates a new instance. | ||
fn bounding_box(&self) -> BoundingBox<T>; | ||
} | ||
/// | ||
/// Holds the minimum and maximum points of the bounding box. | ||
pub struct BoundingBox<T>(T, T); | ||
// | ||
// | ||
impl<T> BoundingBox<T> { | ||
/// | ||
/// Contructor without equality check. | ||
#[allow(unused)] | ||
pub(crate) fn new_unchecked(min: T, max: T) -> Self { | ||
Self(min, max) | ||
} | ||
/// | ||
/// Returns a reference to the minimum point. | ||
pub fn min(&self) -> &T { | ||
&self.0 | ||
} | ||
/// | ||
/// Returns a reference to the maximum point. | ||
pub fn max(&self) -> &T { | ||
&self.1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! Mathematical structures that are independent of any CAD. | ||
// | ||
mod point; | ||
mod vector; | ||
/// | ||
/// Location in N-dimensional space. | ||
pub struct Point<const N: usize>(pub(crate) [f64; N]); | ||
/// | ||
/// Displacment in N-dimensional space. | ||
pub struct Vector<const N: usize>(pub(crate) [f64; N]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::*; | ||
use std::ops::Deref; | ||
// | ||
// | ||
impl<const N: usize> Deref for Point<N> { | ||
type Target = [f64; N]; | ||
// | ||
// | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
// | ||
// | ||
impl<const N: usize> From<[f64; N]> for Point<N> { | ||
fn from(value: [f64; N]) -> Self { | ||
Self(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::*; | ||
use std::ops::Deref; | ||
// | ||
// | ||
impl<const N: usize> From<[f64; N]> for Vector<N> { | ||
fn from(value: [f64; N]) -> Self { | ||
Self(value) | ||
} | ||
} | ||
// | ||
// | ||
impl<const N: usize> Deref for Vector<N> { | ||
type Target = [f64; N]; | ||
// | ||
// | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//! Abstact definition of objects and operations over the CAD kernel. | ||
//! It is assumed that the kernel is universal, but it implements all the necessary traits. | ||
// | ||
pub mod bound; | ||
pub mod gmath; | ||
pub mod ops; | ||
pub mod props; | ||
pub mod topology; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//! Operations for creating, transforming, and modifying objects. | ||
// | ||
pub mod boolean; | ||
pub mod transform; | ||
/// | ||
/// Algorithm to build a polygon. | ||
pub trait Polygon<T> { | ||
type Error; | ||
/// | ||
/// Creates a polygon. | ||
fn polygon(iter: impl IntoIterator<Item = T>, closed: bool) -> Result<Self, Self::Error> | ||
where | ||
Self: Sized; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Create new objects from combinations of two groups of objects. | ||
// | ||
pub mod volume; | ||
/// | ||
/// Union of two groups. | ||
pub trait Fuse<Rhs, C, O> | ||
where | ||
OpConf: From<C>, | ||
{ | ||
/// Returns the union of `&self` and `&rhs`. It's configured using `conf`. | ||
fn fuse(&self, rhs: &Rhs, conf: C) -> O; | ||
} | ||
/// | ||
/// Intersection of two groups. | ||
pub trait Intersect<Rhs, C, O> | ||
where | ||
OpConf: From<C>, | ||
{ | ||
/// Returns the common part of `&self` and `&rhs`. It's configured using `conf`. | ||
fn intersect(&self, rhs: &Rhs, conf: C) -> O; | ||
} | ||
/// | ||
/// Difference between two groups. | ||
pub trait Cut<Rhs, C, O> | ||
where | ||
OpConf: From<C>, | ||
{ | ||
/// Returns the difference between `&self` and `&rhs`. It's configured using `conf`. | ||
fn cut(&self, rhs: &Rhs, conf: C) -> O; | ||
} | ||
/// | ||
/// Config to perform [Fuse], [Intersect] and [Cut]. | ||
pub struct OpConf { | ||
/// | ||
/// Whether parallel processing is enabled. | ||
pub parallel: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! Build an elementary volume from a set of objects. | ||
// | ||
use super::*; | ||
/// | ||
/// Volume creation algorithm. | ||
pub trait Volume<Rhs, C, O> | ||
where | ||
VolumeConf: From<C>, | ||
{ | ||
/// | ||
/// Returns the volume of `&self` and `&rhs`. It's configured using `conf`. | ||
fn volume(&self, rhs: &Rhs, conf: C) -> O; | ||
} | ||
/// | ||
/// Configuration used to perform [Volume]. | ||
pub struct VolumeConf { | ||
/// | ||
/// [Volume] is based on [crate::ops::boolean] operations, | ||
/// so all fields of [OpConf] also make sense. | ||
pub op_conf: OpConf, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! Rotate and move objects. | ||
// | ||
/// Defines the rotation of the object. | ||
pub trait Rotate<O, A> { | ||
/// | ||
/// Consumes `self` and returns a new rotated instance, where | ||
/// - `origin` - rotation pivot, | ||
/// - `axis` - axis for rotation, | ||
/// - `rad` - angle in radians. | ||
fn rotated(self, origin: O, axis: A, rad: f64) -> Self; | ||
} | ||
/// | ||
/// Moving in space. | ||
pub trait Translate<T> { | ||
/// | ||
/// Consumes `self` and returns a new translated instance moved to `dir`. | ||
fn translated(self, dir: T) -> Self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//! Properties associated with the object. | ||
//! | ||
//! Note that the object does not necessarily have to implement all of them. | ||
/// | ||
/// Object with a length. | ||
#[allow(clippy::len_without_is_empty)] | ||
pub trait Length { | ||
/// | ||
/// Returns the length of the object. | ||
fn len(&self) -> f64; | ||
} | ||
/// | ||
/// Object with an area. | ||
pub trait Area { | ||
/// | ||
/// Returns the area of the object. | ||
fn area(&self) -> f64; | ||
} | ||
/// | ||
/// Object with a volume. | ||
pub trait Volume { | ||
/// | ||
/// Retruns the volume of the object. | ||
fn volume(&self) -> f64; | ||
} | ||
/// | ||
/// Object that has the center. | ||
pub trait Center { | ||
type Output; | ||
/// | ||
/// Returns the center of the object. | ||
fn center(&self) -> Self::Output; | ||
} | ||
/// | ||
/// Algorithm for calculating the distance. | ||
pub trait Dist<T> { | ||
/// | ||
/// Returns the distance between `&self` and `&t`. | ||
fn dist(&self, t: &T) -> f64; | ||
} | ||
/// | ||
/// Manages user-defined metadata. | ||
pub trait Metadata<T> { | ||
/// | ||
/// Returns a shared reference to the object attributes. | ||
fn attrs(&self) -> Option<&Attributes<T>>; | ||
/// | ||
/// Returns a shared reference to the object attributes. | ||
fn attrs_mut(&mut self) -> Option<&mut Attributes<T>>; | ||
} | ||
/// | ||
/// Data associated with the object. | ||
pub struct Attributes<T> { | ||
/// | ||
/// Object name. | ||
name: String, | ||
/// | ||
/// User-defined metadata. | ||
custom: T, | ||
} | ||
// | ||
// | ||
impl<T> Attributes<T> { | ||
/// | ||
/// Creates a new instance. | ||
pub fn new(name: String, custom: T) -> Self { | ||
Self { name, custom } | ||
} | ||
/// | ||
/// Returns a shared reference to the object name. | ||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
/// | ||
/// Returns a shared reference to the custom data of the object. | ||
pub fn custom(&self) -> &T { | ||
&self.custom | ||
} | ||
/// | ||
/// Returns the exclusive reference to the custom data of the object. | ||
pub fn custom_mut(&mut self) -> &mut T { | ||
&mut self.custom | ||
} | ||
} | ||
// | ||
// | ||
impl<T: Clone> Clone for Attributes<T> { | ||
fn clone(&self) -> Self { | ||
Self { | ||
name: self.name.clone(), | ||
custom: self.custom.clone(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Defines a topology in N-dimensional space. | ||
// | ||
mod shape; | ||
// | ||
pub use shape::*; | ||
/// | ||
/// Abstract topological structure describes general entity. | ||
pub enum Shape<const N: usize, V, E, W, F, L, D, C, T> { | ||
Vertex(Vertex<N, V, T>), | ||
Edge(Edge<N, E, T>), | ||
Wire(Wire<N, W, T>), | ||
Face(Face<N, F, T>), | ||
Shell(Shell<N, L, T>), | ||
Solid(Solid<N, D, T>), | ||
Compound(Compound<N, C, T>), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! Main topological entities. | ||
// | ||
#![allow(dead_code)] | ||
// | ||
mod compound; | ||
mod edge; | ||
mod face; | ||
mod shell; | ||
mod solid; | ||
mod vertex; | ||
mod wire; | ||
// | ||
use crate::props::Attributes; | ||
/// | ||
/// Zero-size shape corresponding to a point in the geometry. | ||
pub struct Vertex<const N: usize, V, T> { | ||
inner: V, | ||
attrs: Option<Attributes<T>>, | ||
} | ||
/// | ||
/// One-dimensional shape corresponding to a curve. | ||
pub struct Edge<const N: usize, E, T> { | ||
inner: E, | ||
attrs: Option<Attributes<T>>, | ||
} | ||
/// | ||
/// Sequence of edges connected by their vertices. | ||
pub struct Wire<const N: usize, W, T> { | ||
inner: W, | ||
attrs: Option<Attributes<T>>, | ||
} | ||
/// | ||
/// Part of a surface (e. g. a plane in 2D geometry) bounded by a closed wire. | ||
pub struct Face<const N: usize, F, T> { | ||
inner: F, | ||
attrs: Option<Attributes<T>>, | ||
} | ||
/// | ||
/// Set of faces connected by some edges of their wire boundaries. | ||
pub struct Shell<const N: usize, S, T> { | ||
inner: S, | ||
attrs: Option<Attributes<T>>, | ||
} | ||
/// | ||
/// Part of the N-dimensional space bounded by shells. | ||
pub struct Solid<const N: usize, S, T> { | ||
inner: S, | ||
attrs: Option<Attributes<T>>, | ||
} | ||
/// | ||
/// Group of any of main entities. | ||
pub struct Compound<const N: usize, C, T> { | ||
inner: C, | ||
attrs: Option<Attributes<T>>, | ||
} |
Oops, something went wrong.