Welcome to robust’s documentation!

Note

If object is not listed in documentation it should be considered as implementation detail that can change and should not be relied upon.

angular module

class robust.angular.Kind(value)[source]

Represents kinds of angles based on their degrees value in range [0, 180].

OBTUSE = -1

(90, 180] degrees

RIGHT = 0

90 degrees

ACUTE = 1

[0, 90) degrees

class robust.angular.Orientation(value)[source]

Represents kinds of angle orientations.

CLOCKWISE = -1

in the same direction as a clock’s hands

COLLINEAR = 0

to the top and then to the bottom or vice versa

COUNTERCLOCKWISE = 1

opposite to clockwise

robust.angular.kind(first_ray_point: Tuple[numbers.Real, numbers.Real], vertex: Tuple[numbers.Real, numbers.Real], second_ray_point: Tuple[numbers.Real, numbers.Real])robust.angular.Kind[source]

Returns kind of angle built on given points.

>>> kind((1, 0), (0, 0), (1, 0)) is Kind.ACUTE
True
>>> kind((1, 0), (0, 0), (0, 1)) is Kind.RIGHT
True
>>> kind((1, 0), (0, 0), (-1, 0)) is Kind.OBTUSE
True
robust.angular.orientation(first_ray_point: Tuple[numbers.Real, numbers.Real], vertex: Tuple[numbers.Real, numbers.Real], second_ray_point: Tuple[numbers.Real, numbers.Real])robust.angular.Orientation[source]

Returns orientation of angle built on given points.

>>> orientation((1, 0), (0, 0), (1, 0)) is Orientation.COLLINEAR
True
>>> orientation((1, 0), (0, 0), (0, 1)) is Orientation.COUNTERCLOCKWISE
True
>>> orientation((0, 1), (0, 0), (1, 0)) is Orientation.CLOCKWISE
True

cocircular module

robust.cocircular.determinant(first_point: Tuple[numbers.Real, numbers.Real], second_point: Tuple[numbers.Real, numbers.Real], third_point: Tuple[numbers.Real, numbers.Real], fourth_point: Tuple[numbers.Real, numbers.Real]) → numbers.Real[source]

Calculates determinant of linear equations’ system for checking if four points lie on the same circle.

Positive sign of result means that point lies inside, negative – outside, zero – on a circle defined by other points.

>>> determinant((0, 0), (2, 0), (2, 2), (0, 2))
0
>>> determinant((0, 0), (2, 0), (2, 2), (0, 3))
-12
>>> determinant((0, 0), (2, 0), (2, 2), (0, 1))
4

linear module

class robust.linear.SegmentsRelationship(value)[source]

Represents relationship between segments based on their intersection.

NONE = 0

intersection is empty

TOUCH = 1

intersection is an endpoint of one of segments

CROSS = 2

intersection is a point which is not an endpoint of any of segments

OVERLAP = 3

intersection is a segment itself

robust.linear.segments_relationship(left: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]], right: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]])robust.linear.SegmentsRelationship[source]

Finds relationship between segments.

>>> (segments_relationship(((0, 0), (2, 0)), ((0, 0), (2, 0)))
...  is SegmentsRelationship.OVERLAP)
True
>>> (segments_relationship(((0, 0), (2, 0)), ((0, 0), (0, 2)))
...  is SegmentsRelationship.TOUCH)
True
>>> (segments_relationship(((0, 0), (2, 0)), ((0, 0), (1, 0)))
...  is SegmentsRelationship.OVERLAP)
True
>>> (segments_relationship(((0, 0), (2, 0)), ((1, 0), (1, 1)))
...  is SegmentsRelationship.TOUCH)
True
>>> (segments_relationship(((0, 0), (2, 0)), ((1, 0), (2, 0)))
...  is SegmentsRelationship.OVERLAP)
True
>>> (segments_relationship(((0, 0), (2, 0)), ((2, 0), (3, 0)))
...  is SegmentsRelationship.TOUCH)
True
>>> (segments_relationship(((0, 0), (2, 0)), ((3, 0), (4, 0)))
...  is SegmentsRelationship.NONE)
True
robust.linear.segments_intersections(left: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]], right: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]]) → Tuple[Tuple[numbers.Real, numbers.Real], ][source]

Finds intersections of segments.

>>> (segments_intersections(((0, 0), (2, 0)), ((0, 0), (2, 0)))
...  == ((0, 0), (2, 0)))
True
>>> segments_intersections(((0, 0), (2, 0)), ((0, 0), (0, 2))) == ((0, 0),)
True
>>> (segments_intersections(((0, 0), (2, 0)), ((0, 0), (1, 0)))
...  == ((0, 0), (1, 0)))
True
>>> segments_intersections(((0, 0), (2, 0)), ((1, 0), (1, 1))) == ((1, 0),)
True
>>> (segments_intersections(((0, 0), (2, 0)), ((1, 0), (2, 0)))
...  == ((1, 0), (2, 0)))
True
>>> segments_intersections(((0, 0), (2, 0)), ((2, 0), (3, 0))) == ((2, 0),)
True
>>> segments_intersections(((0, 0), (2, 0)), ((3, 0), (4, 0))) == ()
True
robust.linear.segments_intersection(left: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]], right: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]]) → Tuple[numbers.Real, numbers.Real][source]

Finds intersection point of segments that known to have only one.

>>> segments_intersection(((0, 0), (2, 0)), ((0, 0), (0, 2))) == (0, 0)
True
>>> segments_intersection(((0, 0), (2, 0)), ((1, 0), (1, 1))) == (1, 0)
True
>>> segments_intersection(((0, 0), (2, 0)), ((2, 0), (3, 0))) == (2, 0)
True
robust.linear.segment_contains(segment: Tuple[Tuple[numbers.Real, numbers.Real], Tuple[numbers.Real, numbers.Real]], point: Tuple[numbers.Real, numbers.Real]) → bool[source]

Checks if segment contains point.

>>> segment_contains(((0, 0), (2, 0)), (0, 0))
True
>>> segment_contains(((0, 0), (2, 0)), (0, 2))
False
>>> segment_contains(((0, 0), (2, 0)), (1, 0))
True
>>> segment_contains(((0, 0), (2, 0)), (1, 1))
False
>>> segment_contains(((0, 0), (2, 0)), (2, 0))
True
>>> segment_contains(((0, 0), (2, 0)), (3, 0))
False

parallelogram module

robust.parallelogram.signed_area(first_start: Tuple[numbers.Real, numbers.Real], first_end: Tuple[numbers.Real, numbers.Real], second_start: Tuple[numbers.Real, numbers.Real], second_end: Tuple[numbers.Real, numbers.Real]) → numbers.Real[source]

Calculates signed area of parallelogram built on segments’ vectors.

Positive sign of result means that second vector is counterclockwise, negative – clockwise, zero – collinear to first vector.

>>> signed_area((0, 0), (1, 0), (0, 0), (1, 0))
0
>>> signed_area((0, 0), (1, 0), (0, 0), (0, 1))
1
>>> signed_area((0, 0), (1, 0), (0, 1), (0, 0))
-1

projection module

robust.projection.signed_length(first_start: Tuple[numbers.Real, numbers.Real], first_end: Tuple[numbers.Real, numbers.Real], second_start: Tuple[numbers.Real, numbers.Real], second_end: Tuple[numbers.Real, numbers.Real]) → numbers.Real[source]

Calculates signed length of projection of one vector onto another.

Positive sign of result means that angle between vectors is acute, negative – obtuse, zero – right.

>>> signed_length((0, 0), (1, 0), (0, 0), (1, 0))
1
>>> signed_length((0, 0), (1, 0), (0, 0), (0, 1))
0
>>> signed_length((0, 0), (1, 0), (1, 0), (0, 0))
-1