Skip to main content

GcsSystem

Struct GcsSystem 

Source
pub struct GcsSystem { /* private fields */ }
Expand description

The geometric constraint system.

Owns all entities (points, lines, circles) and constraints. Provides CRUD operations and orchestrates the solver.

Implementations§

Source§

impl GcsSystem

Source

pub fn new() -> GcsSystem

Create a new empty GCS.

Source

pub fn add_point(&mut self, data: PointData) -> Handle<PointData>

Add a point. Returns its handle.

Source

pub fn point(&self, id: Handle<PointData>) -> Option<&PointData>

Get a point by handle.

Source

pub fn point_mut(&mut self, id: Handle<PointData>) -> Option<&mut PointData>

Get a mutable reference to a point.

Source

pub fn remove_point( &mut self, id: Handle<PointData>, ) -> Result<PointData, SketchError>

Remove a point. Fails if referenced by any line, circle, or constraint.

§Errors

Returns SketchError::EntityInUse if the point is referenced by a line, circle, or constraint. Returns SketchError::InvalidHandle if the handle is stale or invalid.

Source

pub fn add_line( &mut self, p1: Handle<PointData>, p2: Handle<PointData>, ) -> Result<Handle<LineData>, SketchError>

Add a line between two existing points.

§Errors

Returns SketchError::InvalidHandle if either point handle is invalid.

Source

pub fn line(&self, id: Handle<LineData>) -> Option<&LineData>

Get a line by handle.

Source

pub fn remove_line( &mut self, id: Handle<LineData>, ) -> Result<LineData, SketchError>

Remove a line. Fails if referenced by any constraint.

§Errors

Returns SketchError::EntityInUse if the line is referenced by a constraint. Returns SketchError::InvalidHandle if the handle is stale or invalid.

Source

pub fn add_circle( &mut self, center: Handle<PointData>, radius: f64, ) -> Result<Handle<CircleData>, SketchError>

Add a circle with a center point and radius.

§Errors

Returns SketchError::InvalidHandle if the center point handle is invalid.

Source

pub fn circle(&self, id: Handle<CircleData>) -> Option<&CircleData>

Get a circle by handle.

Source

pub fn remove_circle( &mut self, id: Handle<CircleData>, ) -> Result<CircleData, SketchError>

Remove a circle. Fails if referenced by any constraint.

§Errors

Returns SketchError::EntityInUse if the circle is referenced by a constraint. Returns SketchError::InvalidHandle if the handle is stale or invalid.

Source

pub fn add_arc( &mut self, center: Handle<PointData>, start: Handle<PointData>, end: Handle<PointData>, ) -> Result<Handle<ArcData>, SketchError>

Add an arc defined by center, start, and end points.

Auto-adds an internal PointOnArc(end, arc) constraint so that dist(center, end) == dist(center, start) is maintained dynamically as the start point moves.

§Errors

Returns SketchError::InvalidHandle if any point handle is invalid.

Source

pub fn arc(&self, id: Handle<ArcData>) -> Option<&ArcData>

Get an arc by handle.

Source

pub fn arc_mut(&mut self, id: Handle<ArcData>) -> Option<&mut ArcData>

Get a mutable reference to an arc.

Source

pub fn remove_arc( &mut self, id: Handle<ArcData>, ) -> Result<ArcData, SketchError>

Remove an arc. Fails if referenced by any user constraint.

Also removes the internal distance constraint that was auto-added by add_arc.

§Errors

Returns SketchError::EntityInUse if the arc is referenced by a constraint. Returns SketchError::InvalidHandle if the handle is stale or invalid.

Source

pub fn arc_count(&self) -> usize

Number of arcs.

Source

pub fn arcs(&self) -> impl Iterator<Item = (Handle<ArcData>, &ArcData)>

Iterate over all arcs.

Source

pub fn add_constraint( &mut self, constraint: Constraint, ) -> Result<Handle<ConstraintEntry>, SketchError>

Add a constraint. Validates that all referenced entities exist.

§Errors

Returns SketchError::InvalidHandle if any entity referenced by the constraint does not exist.

Source

pub fn remove_constraint( &mut self, id: Handle<ConstraintEntry>, ) -> Result<(), SketchError>

Remove a constraint by handle.

§Errors

Returns SketchError::InvalidHandle if the handle is stale or invalid.

Source

pub fn constraint(&self, id: Handle<ConstraintEntry>) -> Option<&Constraint>

Get a constraint by handle.

Source

pub fn constraint_count(&self) -> usize

Number of constraints (includes internal arc constraints).

Source

pub fn point_count(&self) -> usize

Number of points.

Source

pub fn line_count(&self) -> usize

Number of lines.

Source

pub fn circle_count(&self) -> usize

Number of circles.

Source

pub fn solve( &mut self, max_iterations: usize, tolerance: f64, ) -> Result<SolveResult, SketchError>

Solve the constraint system.

Modifies entity positions in-place to satisfy all constraints.

§Errors

Returns SketchError if the system parameters are in an invalid state. The Result wrapper is retained for future error paths (e.g. singular Jacobian detection).

Source

pub fn dof(&mut self) -> DofAnalysis

Analyze degrees of freedom in the current system.

Source

pub fn points(&self) -> impl Iterator<Item = (Handle<PointData>, &PointData)>

Iterate over all points.

Source

pub fn lines(&self) -> impl Iterator<Item = (Handle<LineData>, &LineData)>

Iterate over all lines.

Source

pub fn circles(&self) -> impl Iterator<Item = (Handle<CircleData>, &CircleData)>

Iterate over all circles.

Trait Implementations§

Source§

impl Clone for GcsSystem

Source§

fn clone(&self) -> GcsSystem

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 Default for GcsSystem

Source§

fn default() -> GcsSystem

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

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.