The Rust manual covers the recommended facade. The complete native crate is documented in the native Rust API reference .
Geometry
Exact symbolic plane geometry. Coordinates, lengths, and angles are
Expression values.
Constructors#
Constructing a geometry class directly uses the shared default context.
The matching Context method constructs the object in an explicit context.
point_2d#
api::Session method
pub fn point_2d (
& self ,
coordinate_x: & Expression ,
coordinate_y: & Expression ,
) -> Result < Point2d , ApiError >
segment_2d#
api::Session method
pub fn segment_2d (
& self ,
start: & Point2d ,
end: & Point2d ,
) -> Result < Segment2d , ApiError >
polygon_2d#
api::Session method
pub fn polygon_2d < IteratorType > (
& self ,
vertices: IteratorType ,
) -> Result < Polygon2d , ApiError >
where
IteratorType : IntoIterator < Item = Point2d > ,
Simple polygon from its vertex list in order; degenerate inputs raise.
triangle_2d#
api::Session method
pub fn triangle_2d (
& self ,
first: & Point2d ,
second: & Point2d ,
third: & Point2d ,
) -> Result < Triangle2d , ApiError >
Collinear vertices raise.
circle_2d#
api::Session method
pub fn circle_2d (
& self ,
center: & Point2d ,
radius: & Expression ,
) -> Result < Circle2d , ApiError >
point_2d methods#
api::Point2d method
pub fn x ( & self ) -> Result < Expression , ApiError >
Returns this point's horizontal coordinate.
api::Point2d method
pub fn y ( & self ) -> Result < Expression , ApiError >
Returns this point's vertical coordinate.
coordinates#
api::Point2d method
pub fn coordinates ( & self ) -> Result < ( Expression , Expression ) , ApiError >
Provides the coordinates operation on this native type.
distance_to#
Euclidean distance, exact (a sqrt expression in general).
api::Point2d method
pub fn distance_to (
& self ,
other: & Point2d ,
) -> Result < Expression , ApiError >
Provides the distance_to operation on this native type.
segment_2d methods#
length#
Also the finite-set length accessor on Expression in WASM; context
disambiguates.
api::Segment2d method
pub fn length ( & self ) -> Result < Expression , ApiError >
Provides the length operation on this native type.
midpoint#
api::Segment2d method
pub fn midpoint ( & self ) -> Result < Point2d , ApiError >
Provides the midpoint operation on this native type.
perpendicular_bisector_equation#
The bisector line as an equal relation in x and y.
api::geometry_operations::Segment2d method
pub fn perpendicular_bisector_equation < 'a , 'b , XVariableType , YVariableType > (
& self ,
variable_x: XVariableType ,
variable_y: YVariableType ,
) -> Result < Expression , ApiError >
where
XVariableType : Into < VariableLike < 'a >> ,
YVariableType : Into < VariableLike < 'b >> ,
The equation of the perpendicular bisector in the two named coordinates.
polygon_2d and triangle_2d#
area#
api::Polygon2d method
pub fn area ( & self ) -> Result < Expression , ApiError >
Calling forms and variants
Variant for this object — api::Triangle2d method: api::Triangle2d::area
pub fn area ( & self ) -> Result < Expression , ApiError >
For a Polygon2d or Triangle2d, this is the unsigned shoelace area of the
ordered boundary, so a polygon's orientation does not change its area. A
circle's area is a different formula under a different owner; see
Circle2d.area .
perimeter#
api::Polygon2d method
pub fn perimeter ( & self ) -> Result < Expression , ApiError >
Calling forms and variants
Variant for this object — api::Triangle2d method: api::Triangle2d::perimeter
pub fn perimeter ( & self ) -> Result < Expression , ApiError >
centroid#
api::Polygon2d method
pub fn centroid ( & self ) -> Result < Point2d , ApiError >
Calling forms and variants
Variant for this object — api::geometry_operations::Triangle2d method: api::geometry_operations::Triangle2d::centroid
pub fn centroid ( & self ) -> Result < Point2d , ApiError >
interior_angles#
api::geometry_operations::Polygon2d method
pub fn interior_angles ( & self ) -> Result < Vec < VertexAngle > , ApiError >
Calling forms and variants
Variant for this object — api::geometry_operations::Triangle2d method: api::geometry_operations::Triangle2d::interior_angles
pub fn interior_angles ( & self ) -> Result < Vec < VertexAngle > , ApiError >
Each vertex paired with its interior angle. Notes: WASM returns
VertexAngle objects with vertex/angle getters.
vertex_angle (WASM result class)#
vertex#
api::results::VertexAngle method
pub fn vertex ( & self ) -> Point2d
The vertex.
angle#
api::results::VertexAngle method
pub fn angle ( & self ) -> Expression
The interior angle at the vertex.
circle_2d methods#
center#
api::Circle2d method
pub fn center ( & self ) -> Result < Point2d , ApiError >
Returns this circle's center point.
radius#
api::Circle2d method
pub fn radius ( & self ) -> Result < Expression , ApiError >
Returns this circle's radius expression.
Circle2d.area#
api::Circle2d method
pub fn area ( & self ) -> Result < Expression , ApiError >
The exact disk area π r 2 \pi r^2 π r 2 , from the circle's symbolic radius. This is not
the polygon and triangle shoelace operation of area above; the two
share a member name and nothing else.
circumference#
api::Circle2d method
pub fn circumference ( & self ) -> Result < Expression , ApiError >
Provides the circumference operation on this native type.
equation#
api::geometry_operations::Circle2d method
pub fn equation < 'a , 'b , XVariableType , YVariableType > (
& self ,
variable_x: XVariableType ,
variable_y: YVariableType ,
) -> Result < Expression , ApiError >
where
XVariableType : Into < VariableLike < 'a >> ,
YVariableType : Into < VariableLike < 'b >> ,
The circle as an equal relation in x and y.
Exact boundary intersections#
intersection#
api::Point2d method
pub fn intersection < GeometryType > (
& self ,
other: GeometryType ,
) -> Result < Vec < GeometryIntersectionComponent > , ApiError >
where
GeometryType : Into < Geometry2d > ,
Calling forms and variants
Variant for this object — api::Circle2d method: api::Circle2d::intersection
pub fn intersection < GeometryType > (
& self ,
other: GeometryType ,
) -> Result < Vec < GeometryIntersectionComponent > , ApiError >
where
GeometryType : Into < Geometry2d > ,
Variant for this object — api::Polygon2d method: api::Polygon2d::intersection
pub fn intersection < GeometryType > (
& self ,
other: GeometryType ,
) -> Result < Vec < GeometryIntersectionComponent > , ApiError >
where
GeometryType : Into < Geometry2d > ,
Variant for this object — api::Segment2d method: api::Segment2d::intersection
pub fn intersection < GeometryType > (
& self ,
other: GeometryType ,
) -> Result < Vec < GeometryIntersectionComponent > , ApiError >
where
GeometryType : Into < Geometry2d > ,
Variant for this object — api::Triangle2d method: api::Triangle2d::intersection
pub fn intersection < GeometryType > (
& self ,
other: GeometryType ,
) -> Result < Vec < GeometryIntersectionComponent > , ApiError >
where
GeometryType : Into < Geometry2d > ,
Every point, segment, polygon, triangle, and circle exposes the same symmetric
intersection method. Polygon and triangle operands mean their closed boundary;
circle operands mean their circumference. Isolated intersections are returned as
Point2d objects, while a shared edge or coincident circle is returned as the
corresponding Segment2d or Circle2d component instead of sampled points.
The component sequence is exact and deterministic. If any required symbolic
predicate cannot be decided, the operation declines instead of returning an
incomplete list. Both operands must belong to the same context.
Output#
All geometry classes also provide to_latex (and serialize_object in
WASM; Python serializes through Context.serializeObject).
Example#
Geometry objects return exact symbolic measurements.
use symi:: api:: prelude:: * ;
fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error >> {
let session = Session :: new ( ) ;
let first = session. point_2d ( & session. integer ( 0 ) , & session. integer ( 0 ) ) ? ;
let second = session. point_2d ( & session. integer ( 3 ) , & session. integer ( 4 ) ) ? ;
let segment = session. segment_2d ( & first, & second) ? ;
println! ( "{}" , segment. length ( ) ? ) ;
println! ( "{}" , session. circle_2d ( & first, & session. integer ( 2 ) ) ? . area ( ) ? ) ;
Ok ( ( ) )
}
Additional API#
api::geometry_operations#
api module
pub mod geometry_operations ;
Planar geometry operations of the native API.
Circle2d#
Type
Public native data structure named circle_2d.
Circle2d.generation#
api::Circle2d method
pub fn generation ( & self ) -> u64
The session generation this object was created in.
Circle2d.is_stale#
api::geometry_operations::Circle2d method
pub fn is_stale ( & self ) -> bool
Whether this circle's session has been reset since the circle was made.
Circle2d.session#
api::Circle2d method
pub fn session ( & self ) -> Session
The session that owns this object, for host adapters that carry the owner alongside it.
Geometry2d#
Type
Public native enumeration of supported two-dimensional geometry operands.
Geometry2d.Circle#
api::Geometry2d variant
Stores a circle circumference operand.
Geometry2d.Point#
api::Geometry2d variant
Stores a point operand.
Geometry2d.Polygon#
api::Geometry2d variant
Stores a polygon boundary operand.
Geometry2d.Segment#
api::Geometry2d variant
Stores a closed segment operand.
Geometry2d.Triangle#
api::Geometry2d variant
Stores a triangle boundary operand.
GeometryIntersectionComponent#
Type
pub enum GeometryIntersectionComponent
Public native enumeration of exact geometry intersection components.
GeometryIntersectionComponent.Circle#
api::GeometryIntersectionComponent variant
Stores an overlapping circle component.
GeometryIntersectionComponent.Point#
api::GeometryIntersectionComponent variant
Stores an isolated point component.
GeometryIntersectionComponent.Segment#
api::GeometryIntersectionComponent variant
Stores an overlapping closed segment component.
Point2d#
Type
Public native data structure named point_2d.
Point2d.generation#
api::Point2d method
pub fn generation ( & self ) -> u64
The session generation this object was created in.
Point2d.is_stale#
api::Point2d method
pub fn is_stale ( & self ) -> bool
Provides the is_stale operation on this native type.
Point2d.session#
api::Point2d method
pub fn session ( & self ) -> Session
The session that owns this object, for host adapters that carry the owner alongside it.
Polygon2d#
Type
Public native data structure named polygon_2d.
Polygon2d.generation#
api::Polygon2d method
pub fn generation ( & self ) -> u64
The session generation this object was created in.
Polygon2d.is_stale#
api::geometry_operations::Polygon2d method
pub fn is_stale ( & self ) -> bool
Whether this polygon's session has been reset since the polygon was made.
Polygon2d.session#
api::Polygon2d method
pub fn session ( & self ) -> Session
The session that owns this object, for host adapters that carry the owner alongside it.
Polygon2d.vertex_count#
api::geometry_operations::Polygon2d method
pub fn vertex_count ( & self ) -> Result < usize , ApiError >
The number of vertices bounding this polygon.
Segment2d#
Type
Public native data structure named segment_2d.
Segment2d.generation#
api::Segment2d method
pub fn generation ( & self ) -> u64
The session generation this object was created in.
Segment2d.is_stale#
api::geometry_operations::Segment2d method
pub fn is_stale ( & self ) -> bool
Whether this segment's session has been reset since the segment was made.
Segment2d.session#
api::Segment2d method
pub fn session ( & self ) -> Session
The session that owns this object, for host adapters that carry the owner alongside it.
Triangle2d#
Type
Public native data structure named triangle_2d.
Triangle2d.generation#
api::Triangle2d method
pub fn generation ( & self ) -> u64
The session generation this object was created in.
Triangle2d.is_stale#
api::geometry_operations::Triangle2d method
pub fn is_stale ( & self ) -> bool
Whether this triangle's session has been reset since the triangle was made.
Triangle2d.session#
api::Triangle2d method
pub fn session ( & self ) -> Session
The session that owns this object, for host adapters that carry the owner alongside it.
VertexAngle#
api re_export
pub use results:: VertexAngle ;
One vertex of a figure together with the interior angle at that vertex.
Calling forms
Type: api::results::VertexAngle