Skip to content

Commit

Permalink
Merge pull request #1 from novartole/dev
Browse files Browse the repository at this point in the history
Back | sal-3dlib | structures & traits
  • Loading branch information
a-givertzman authored Nov 19, 2024
2 parents db83b62 + cae8656 commit 967a014
Show file tree
Hide file tree
Showing 57 changed files with 168,588 additions and 634 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
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" }
4 changes: 4 additions & 0 deletions crates/sal-3dlib-core/Cargo.toml
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"
31 changes: 31 additions & 0 deletions crates/sal-3dlib-core/src/bound.rs
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
}
}
10 changes: 10 additions & 0 deletions crates/sal-3dlib-core/src/gmath.rs
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]);
19 changes: 19 additions & 0 deletions crates/sal-3dlib-core/src/gmath/point.rs
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)
}
}
19 changes: 19 additions & 0 deletions crates/sal-3dlib-core/src/gmath/vector.rs
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
}
}
8 changes: 8 additions & 0 deletions crates/sal-3dlib-core/src/lib.rs
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;
14 changes: 14 additions & 0 deletions crates/sal-3dlib-core/src/ops.rs
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;
}
37 changes: 37 additions & 0 deletions crates/sal-3dlib-core/src/ops/boolean.rs
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,
}
21 changes: 21 additions & 0 deletions crates/sal-3dlib-core/src/ops/boolean/volume.rs
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,
}
18 changes: 18 additions & 0 deletions crates/sal-3dlib-core/src/ops/transform.rs
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;
}
94 changes: 94 additions & 0 deletions crates/sal-3dlib-core/src/props.rs
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(),
}
}
}
16 changes: 16 additions & 0 deletions crates/sal-3dlib-core/src/topology.rs
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>),
}
55 changes: 55 additions & 0 deletions crates/sal-3dlib-core/src/topology/shape.rs
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>>,
}
Loading

0 comments on commit 967a014

Please sign in to comment.