pub struct Sketch {
pub points: BTreeMap<PointId, Point>,
pub curves: BTreeMap<CurveId, Curve>,
pub constraints: BTreeMap<ConstraintId, Constraint>,
pub next_id: u64,
}Expand description
A constraint sketch.
Every entity is keyed by a stable id rather than stored by position: an id
is handed out once, by the add_* methods, and never reused — not even
after the entity is removed. That is what lets anything outside the sketch
(a constraint, a profile, a topological name of the solid extruded from
it) keep referring to “that line” while the sketch is edited around it.
The maps are ordered, so a serialized sketch is deterministic and diffs
line by line.
Fields§
§points: BTreeMap<PointId, Point>§curves: BTreeMap<CurveId, Curve>§constraints: BTreeMap<ConstraintId, Constraint>§next_id: u64The id the next added entity gets; greater than every id in use. One
counter for all three kinds, so an id add_* hands out is unique
across the sketch.
Implementations§
Source§impl Sketch
impl Sketch
Sourcepub fn mirror(
&mut self,
curves: &[CurveId],
line: CurveId,
) -> GeopResult<Vec<CurveId>>
pub fn mirror( &mut self, curves: &[CurveId], line: CurveId, ) -> GeopResult<Vec<CurveId>>
Mirrors curves across the line line, each mirrored point
Constraint::Symmetric to its original. A point on the line —
by constraint, see Sketch::on_line — is its own mirror image,
and a point mirrored before across the same line has the image it
got then: so a half profile ending on the line closes into a whole
one, and mirroring one curve after another joins the copies up. A
curve that lies on the line is left out. Returns the new curves.
Sourcepub fn pattern(
&mut self,
curves: &[CurveId],
step: &Step,
count: usize,
) -> GeopResult<Made>
pub fn pattern( &mut self, curves: &[CurveId], step: &Step, count: usize, ) -> GeopResult<Made>
Repeats curves count times in all, the original among them, each
copy step on from the one before (see the module docs). Returns the
pattern’s construction curve and the dimension of its spacing.
The construction curve runs from a point of the original — for a circular pattern the one furthest from the center — to that point’s first copy. A point at a circular pattern’s center is its own copy.
Sourcepub fn pattern_count(&self, by: CurveId) -> Option<usize>
pub fn pattern_count(&self, by: CurveId) -> Option<usize>
How many copies the pattern by has, the original among them;
None if by is the construction curve of no pattern.
Sourcepub fn set_pattern_count(&mut self, by: CurveId, count: usize) -> GeopResult<()>
pub fn set_pattern_count(&mut self, by: CurveId, count: usize) -> GeopResult<()>
Gives the pattern by count copies, the original among them:
removes the copies past the last one kept, or adds copies after its
last one, as it is now.
Sourcepub fn pattern_spacing(&self, by: CurveId) -> Option<ConstraintId>
pub fn pattern_spacing(&self, by: CurveId) -> Option<ConstraintId>
The dimension of the spacing of the pattern by: a
Constraint::Length of its line, or the Constraint::Angle
between the radii to its arc’s ends — if it has one still.
Source§impl Sketch
impl Sketch
Sourcepub fn chain_side(&self, chain: &Chain, p: P2) -> GeopResult<f64>
pub fn chain_side(&self, chain: &Chain, p: P2) -> GeopResult<f64>
How far p is from the chain chain: positive to its left.
Sourcepub fn offset(
&mut self,
curves: &[CurveId],
distance: Scalar,
corners: Corners,
) -> GeopResult<Offsetted>
pub fn offset( &mut self, curves: &[CurveId], distance: Scalar, corners: Corners, ) -> GeopResult<Offsetted>
Offsets the chains curves (see Sketch::chains) by distance
— the first to its left, to its right if negative, and every other
one into the same area: away from the first where it lies inside or
round it, as a hole’s or an outline’s — its corners as corners
says (see the module docs). Returns the curves made, and the
dimension of the distance.
Sourcepub fn chains(&self, curves: &[CurveId]) -> GeopResult<Vec<Chain>>
pub fn chains(&self, curves: &[CurveId]) -> GeopResult<Vec<Chain>>
The curves curves as chains (see Sketch::chain): each made of
those joined to each other end to end.
Source§impl Sketch
impl Sketch
Sourcepub fn shape(&self) -> GeopResult<Shape>
pub fn shape(&self) -> GeopResult<Shape>
What the sketch draws to sweep (see Shape): its areas, or, if
its curves enclose nothing, the one chain they form.
Sourcepub fn chain(&self, curves: &[CurveId]) -> GeopResult<Chain>
pub fn chain(&self, curves: &[CurveId]) -> GeopResult<Chain>
curves in order as one chain, each joined to the next at an end
point, none branching: an open chain walked from its end at the
lower point id, a closed one from its first curve given — or a lone
circle.
Sourcepub fn runs(&self) -> GeopResult<Vec<Chain>>
pub fn runs(&self) -> GeopResult<Vec<Chain>>
Every run of the sketch’s non-construction curves, in the order of
their ids: each closed curve, each contour of a text, and each stretch
of curves joined end to end, broken where three or more meet. Unlike
Sketch::shape, which is what the sketch sweeps as one profile,
nothing is left out and nothing has to enclose anything: every line of
the sketch is in one run.
Sourcepub fn chain_through(&self, curve: CurveId) -> GeopResult<Vec<CurveId>>
pub fn chain_through(&self, curve: CurveId) -> GeopResult<Vec<CurveId>>
The chain through curve: it, and on from each of its ends the
line, arc or spline joined there — as long as exactly one other of
its kind (profile or construction) is.
Sourcepub fn regions(&self) -> GeopResult<Vec<Region>>
pub fn regions(&self) -> GeopResult<Vec<Region>>
Every region bounded by the sketch’s non-construction curves.
Source§impl Sketch
impl Sketch
pub fn new() -> Self
pub fn point(&self, id: PointId) -> GeopResult<&Point>
pub fn curve(&self, id: CurveId) -> GeopResult<&Curve>
pub fn add_point(&mut self, x: Scalar, y: Scalar) -> PointId
Sourcepub fn new_point_at(&mut self, at: [f64; 2]) -> PointId
pub fn new_point_at(&mut self, at: [f64; 2]) -> PointId
A point at at, as drawn.
Sourcepub fn add_fixed_point(&mut self, x: Scalar, y: Scalar) -> PointId
pub fn add_fixed_point(&mut self, x: Scalar, y: Scalar) -> PointId
A point given from outside the sketch, at (x, y) (see the module
docs).
Sourcepub fn add_curve(&mut self, kind: CurveKind) -> CurveId
pub fn add_curve(&mut self, kind: CurveKind) -> CurveId
Adds a curve of kind, profile geometry, solved for.
pub fn add_line(&mut self, start: PointId, end: PointId) -> CurveId
Sourcepub fn add_arc(
&mut self,
start: PointId,
end: PointId,
sweep: Scalar,
) -> CurveId
pub fn add_arc( &mut self, start: PointId, end: PointId, sweep: Scalar, ) -> CurveId
An arc from start to end, turning counter-clockwise by sweep
radians (clockwise if negative).
pub fn add_circle(&mut self, center: PointId, radius: Scalar) -> CurveId
pub fn add_spline(&mut self, control_points: Vec<PointId>) -> CurveId
Sourcepub fn add_text(
&mut self,
anchor: PointId,
text: impl Into<String>,
height: Scalar,
angle: Scalar,
) -> CurveId
pub fn add_text( &mut self, anchor: PointId, text: impl Into<String>, height: Scalar, angle: Scalar, ) -> CurveId
A text: text, its baseline from anchor, its capitals height
tall, turned by angle radians (see CurveKind::Text).
pub fn set_construction(&mut self, curve: CurveId, construction: bool)
pub fn constrain(&mut self, constraint: Constraint) -> ConstraintId
Sourcepub fn remove(
&mut self,
points: &[PointId],
curves: &[CurveId],
constraints: &[ConstraintId],
)
pub fn remove( &mut self, points: &[PointId], curves: &[CurveId], constraints: &[ConstraintId], )
Removes points, curves and constraints, and everything that
depends on them (see [remove]).
Sourcepub fn validate(&self) -> GeopResult<()>
pub fn validate(&self) -> GeopResult<()>
Check every reference and every constraint’s operand kinds, so the solver and profile code can rely on them.
Sourcepub fn validate_constraint(&self, c: &Constraint) -> GeopResult<()>
pub fn validate_constraint(&self, c: &Constraint) -> GeopResult<()>
Whether c could be a constraint of the sketch: its points and
curves are there, and of the kinds it constrains.
Sourcepub fn point_classes(&self) -> BTreeMap<PointId, PointId>
pub fn point_classes(&self) -> BTreeMap<PointId, PointId>
Union-find representative of every point under
Constraint::Coincident: points with the same representative are
one point.
Sourcepub fn on_line(&self, line: CurveId) -> GeopResult<BTreeSet<PointId>>
pub fn on_line(&self, line: CurveId) -> GeopResult<BTreeSet<PointId>>
Every point the constraints put on the infinite line through the line
line: its endpoints, points constrained onto it
(Constraint::PointOnCurve, a Constraint::Midpoint of it, an
endpoint of a Constraint::Collinear partner), and any point
coincident with one of those.
Structural, like all connectivity here: a point that merely happens to lie on the line is not reported.
Sourcepub fn tangent(&self, a: CurveId, b: CurveId) -> bool
pub fn tangent(&self, a: CurveId, b: CurveId) -> bool
Whether a Constraint::Tangent ties the curves a and b.
Which ends (a_at_end, b_at_end) of open curves a and b are the
same point, if any (false = start, true = end).
Source§impl Sketch
impl Sketch
Sourcepub fn enclose(&self) -> GeopResult<Enclosure>
pub fn enclose(&self) -> GeopResult<Enclosure>
The sketch’s geometry as the kernel builds on it (see Enclosure):
an enclosure of the exact solution of its constraints near the
solved positions, each variable the constraints leave free exactly
as drawn (see [System::enclose]).
A sketch whose constraints are not met is no solution of them, and is built exactly as drawn: that is all there is to build. Fails if the solution cannot be proven — a sketch meeting its constraints only at a singular configuration.
Sourcepub fn solve(&mut self) -> GeopResult<SolveReport>
pub fn solve(&mut self) -> GeopResult<SolveReport>
Move every point (and arc sweep, circle radius) so all constraints hold, changing the sketch as little as the constraints allow.
The sketch is updated even if the solve does not converge, to the closest configuration found — the report says which constraints could not be met.
Sourcepub fn solve_with_drag(
&mut self,
drags: &[(PointId, Vector2)],
) -> GeopResult<SolveReport>
pub fn solve_with_drag( &mut self, drags: &[(PointId, Vector2)], ) -> GeopResult<SolveReport>
Like Sketch::solve, while pulling each (point, target) towards
its target as far as the constraints allow — interactive dragging.