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

Source

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

Like Sketch::insert_point, for a curve.

Source

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

Source

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

Source

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.

Source

pub fn add_arc_with_sweep( &mut self, start: PointId, end: PointId, sweep: f64, ) -> CurveId

Source

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

Source

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

Source

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

Source

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

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 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 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 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, [f64; 2])], ) -> 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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.