Skip to main content

Sketch

Struct Sketch 

Source
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: u64

The 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn chain_side(&self, chain: &Chain, p: P2) -> GeopResult<f64>

How far p is from the chain chain: positive to its left.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn regions(&self) -> GeopResult<Vec<Region>>

Every region bounded by the sketch’s non-construction curves.

Source§

impl Sketch

Source

pub fn new() -> Self

Source

pub fn point(&self, id: PointId) -> GeopResult<&Point>

Source

pub fn curve(&self, id: CurveId) -> GeopResult<&Curve>

Source

pub fn positions(&self) -> Positions

Every point’s [x, y].

Source

pub fn add_point(&mut self, x: Scalar, y: Scalar) -> PointId

Source

pub fn new_point_at(&mut self, at: [f64; 2]) -> PointId

A point at at, as drawn.

Source

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).

Source

pub fn add_curve(&mut self, kind: CurveKind) -> CurveId

Adds a curve of kind, profile geometry, solved for.

Source

pub fn add_line(&mut self, start: PointId, end: PointId) -> CurveId

Source

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).

Source

pub fn add_circle(&mut self, center: PointId, radius: Scalar) -> CurveId

Source

pub fn add_spline(&mut self, control_points: Vec<PointId>) -> CurveId

Source

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).

Source

pub fn set_construction(&mut self, curve: CurveId, construction: bool)

Source

pub fn constrain(&mut self, constraint: Constraint) -> ConstraintId

Source

pub fn remove( &mut self, points: &[PointId], curves: &[CurveId], constraints: &[ConstraintId], )

Removes points, curves and constraints, and everything that depends on them (see [remove]).

Source

pub fn validate(&self) -> GeopResult<()>

Check every reference and every constraint’s operand kinds, so the solver and profile code can rely on them.

Source

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.

Source

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.

Source

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.

Source

pub fn tangent(&self, a: CurveId, b: CurveId) -> bool

Whether a Constraint::Tangent ties the curves a and b.

Source

pub fn shared_endpoint( &self, a: CurveId, b: CurveId, ) -> GeopResult<Option<(bool, bool)>>

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

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Sketch

Source§

fn clone(&self) -> Sketch

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Sketch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Sketch

Source§

fn default() -> Sketch

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Sketch

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Sketch

Source§

fn eq(&self, other: &Sketch) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Sketch

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Sketch

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.