Skip to main content

geop_ops_pattern/
lib.rs

1//! Repeating and moving bodies, as operations of a program (see
2//! [`geop_core_editor::part_operation::PartOperation`]):
3//!
4//! - [`LinearPattern`]: copies in a row along a direction, or in a grid
5//!   along two.
6//! - [`CircularPattern`]: copies turned around an axis.
7//! - [`Pattern`]: copies wherever a list of frames puts them — along a
8//!   curve, at points, from a table, filling a face, at holes (see
9//!   [`geop_ops_model::spacing::Frames`]).
10//! - [`Mirror`]: a mirror image in a plane.
11//! - [`MoveBody`]: bodies, or a copy of them, turned and shifted.
12//! - [`ScaleBody`]: bodies scaled about a point, evenly or along each axis.
13//! - [`DeformBody`]: bodies tapered, twisted or bent about an axis.
14//!
15//! The first four repeat bodies or features.
16//!
17//! Each acts on solids, and on sheets — faces standing on their own — and
18//! keeps what it makes as new bodies, or combines it with a solid as an
19//! extrude does ([`geop_ops_model::Combine`]): joined to the bodies
20//! themselves, or cut from another solid. The copies are moved exactly as
21//! the bodies are (see `geop_core_topology::Model::transform_body`): every
22//! surface and curve by the same motion, each pcurve as it was.
23//!
24//! # Patterning a feature
25//!
26//! Patterns and mirrors also repeat features — a hole cut by an extrude, a
27//! boss joined to a plate, a tapped hole with its thread — picked by a face
28//! each made. A step only sees the part the steps before it built, never
29//! their arguments; what it sees of a feature is what the feature's step
30//! recorded on the part as it combined its tools (see
31//! [`geop_ops_model::Feature`]), and a feature is picked by a face it made
32//! ([`Feature`]). A pattern copies those tools, moves them, and
33//! combines each copy with the solid the feature lies on as the feature
34//! combined it: why that, rather than running the step again, is said in
35//! `features.rs`.
36//!
37//! # Spacing
38//!
39//! Where instances go — in a row, each a step from the last or spread over
40//! an extent, round an axis, along a curve, at points, filling a face — is
41//! [`geop_ops_model::spacing`]'s, shared with every operation that lays out
42//! instances (a placed part's copies, fasteners in holes, too).
43
44mod circular;
45mod common;
46mod deform_body;
47#[cfg(test)]
48mod editor_tests;
49#[cfg(any(test, feature = "examples"))]
50pub mod examples;
51mod features;
52mod icons;
53mod linear;
54mod mirror;
55mod move_body;
56mod pattern;
57#[cfg(test)]
58mod program_tests;
59mod references;
60#[cfg(test)]
61mod regression_tests;
62mod scale_body;
63#[cfg(test)]
64mod tests;
65
66pub use circular::{CircularPattern, CircularPatternArgs};
67pub use common::{BodyRef, Seeds, body};
68pub use deform_body::{Deform, DeformBody, DeformBodyArgs};
69pub use features::{Feature, FeatureRef, feature};
70pub use geop_ops_model::spacing::{Direction, Frames, Offset, PointsRef};
71pub use linear::{LinearPattern, LinearPatternArgs};
72pub use mirror::{Mirror, MirrorArgs};
73pub use move_body::{MoveBody, MoveBodyArgs};
74pub use pattern::{Pattern, PatternArgs};
75pub use references::{PatternDirection, TurnAxis};
76pub use scale_body::{ScaleBody, ScaleBodyArgs};
77
78use geop_core_editor::registry::Registry;
79use geop_core_math::geop_error::GeopResult;
80
81/// Adds what this crate offers an editor to `r`: patterns, mirrors and
82/// moved bodies.
83pub fn register(r: Registry) -> GeopResult<Registry> {
84    let r = r
85        .operation(LinearPattern)?
86        .operation(CircularPattern)?
87        .operation(Pattern)?
88        .operation(Mirror)?
89        .operation(MoveBody)?
90        .operation(ScaleBody)?
91        .operation(DeformBody)?;
92    #[cfg(any(test, feature = "examples"))]
93    let r = r.examples(examples::set())?;
94    Ok(r)
95}