fj_core/
lib.rs

1//! # Fornjot Core
2//!
3//! [Fornjot] is an early-stage b-rep CAD kernel written in Rust. The kernel is
4//! split into multiple libraries that can be used semi-independently, and this
5//! is one of those.
6//!
7//! This library defines geometric and topological primitives, and the
8//! algorithms that operate on them.
9//!
10//!
11//! ## Design Principle
12//!
13//! The CAD kernel follows the design principle of **robustness through
14//! explicitness**. This means that geometrical relationships must be expressed
15//! explicitly, or they are not accepted.
16//!
17//! This principle is not fully implemented yet. There are quite a few
18//! validation checks that enforce part of it, but many are still missing.
19//!
20//! ### Motivation
21//!
22//! A problem that CAD kernels need to handle is the inherent fuzziness of
23//! geometric relationships. Is a point on a curve, or just close to it? Does a
24//! curve lie in a surface, or does it not? This is exacerbated by the limited
25//! precision of numerical representations in computers, and especially the
26//! inconvenient precision characteristics of floating-point numbers.
27//!
28//! These problems can be addressed by always comparing numbers using an epsilon
29//! value. Numbers that are very close together (their difference is smaller
30//! than epsilon) are considered equal.
31//!
32//! This approach has several problems:
33//! - If the epsilon value is chosen too high, then very small models can become
34//!   buggy, as distinct geometry is merged together.
35//! - If the epsilon value is chosen too low, then very large models can become
36//!   buggy, as geometry that is supposed to be identical is recognized as
37//!   distinct.
38//! - These epsilon comparisons need to be used everywhere where numbers are
39//!   handled. It can be easy to forget this. Using custom wrapper types is
40//!   possible, but either inflexible (because the epsilon value is hardcoded)
41//!   or inconvenient (because the epsilon value needs to be provided).
42//!
43//! Choosing an epsilon value that is suitable for *most* use cases is possible,
44//! at the cost of non-standard use cases breaking in unexpected and non-obvious
45//! ways. Fornjot has chosen a different approach.
46//!
47//! ### Explicitness
48//!
49//! By requiring geometric relationships to be *explicit*, we don't have to use
50//! error-prone heuristics to determine those relationships. That means, for
51//! example, two vertices that happen to be identical, or very close to each
52//! other, are not accepted.
53//!
54//! If vertex instances that refer to the same point are used in different
55//! places (for example, in two neighboring edges that share a vertex), then
56//! those vertex instances must be known by the system to refer to the same
57//! vertex. If a vertex lies on an edge or in a surface, then it must be defined
58//! in terms of its position on that edge or surface.
59//!
60//! This can have consequences for how users define models. For example, if the
61//! user moves two shapes close to each other, so they touch but don't
62//! intersect, this should lead to an error message, explaining to the user why
63//! what they did is a problem, and teaching them how to define their model in
64//! a different way, so the system knows the semantic relationships between
65//! geometrical objects.
66//!
67//! ### Validation
68//!
69//! These rules of explicitness must be validated, so the user can know if there
70//! is a problem in the model, and fix it. This is preferable to failing in
71//! unexpected ways later on.
72//!
73//! For the comparisons required for validation, an epsilon value must be used.
74//! This epsilon value can be derived from the size of the model, and should be
75//! chosen as high as possible, so any potential problems can be immediately
76//! reported as errors.
77//!
78//! If the user does something non-standard, they can override the epsilon value
79//! on a per-shape basis. Forcing the user to deal with these issues up-front
80//! should lead to less work overall.
81//!
82//! [Fornjot]: https://www.fornjot.app/
83
84pub mod algorithms;
85pub mod geometry;
86pub mod layers;
87pub mod objects;
88pub mod operations;
89pub mod presentation;
90pub mod queries;
91pub mod storage;
92pub mod validate;
93pub mod validation;
94
95mod core;
96
97pub use self::core::Core;