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 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>
Sourcepub fn insert_point(&mut self, id: PointId, point: Point) -> GeopResult<()>
pub fn insert_point(&mut self, id: PointId, point: Point) -> GeopResult<()>
Adds point under the id id rather than a fresh one — for reading
back a sketch whose ids were chosen already, so that what refers to
them keeps doing so. Fails if id is taken.
Sourcepub fn insert_curve(&mut self, id: CurveId, curve: Curve) -> GeopResult<()>
pub fn insert_curve(&mut self, id: CurveId, curve: Curve) -> GeopResult<()>
Like Sketch::insert_point, for a curve.
pub fn add_point(&mut self, x: f64, y: f64) -> PointId
pub fn add_line(&mut self, start: PointId, end: PointId) -> CurveId
Sourcepub fn add_arc(
&mut self,
start: PointId,
end: PointId,
curvature: f64,
) -> CurveId
pub fn add_arc( &mut self, start: PointId, end: PointId, curvature: f64, ) -> CurveId
An arc from start to end with signed curvature (positive turns
counter-clockwise): the minor arc, or a half circle if |curvature|
exceeds what the chord allows. For a major arc, give the sweep
directly via Sketch::add_arc_with_sweep.
pub fn add_arc_with_sweep( &mut self, start: PointId, end: PointId, sweep: f64, ) -> CurveId
pub fn add_circle(&mut self, center: PointId, radius: f64) -> CurveId
pub fn add_spline(&mut self, control_points: Vec<PointId>) -> CurveId
pub fn set_construction(&mut self, curve: CurveId, construction: bool)
pub fn constrain(&mut self, constraint: Constraint) -> ConstraintId
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 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.
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 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, [f64; 2])],
) -> GeopResult<SolveReport>
pub fn solve_with_drag( &mut self, drags: &[(PointId, [f64; 2])], ) -> GeopResult<SolveReport>
Like Sketch::solve, while pulling each (point, target) towards
its target as far as the constraints allow — interactive dragging.