Welcome to ground’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.

base module

class ground.base.Location(value)[source]

Represents kinds of locations in which point can be relative to geometry.

EXTERIOR = 0

point lies in the exterior of the geometry

BOUNDARY = 1

point lies on the boundary of the geometry

INTERIOR = 2

point lies in the interior of the geometry

class ground.base.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 ground.base.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

class ground.base.Relation(value)[source]

Represents kinds of relations in which geometries can be. Order of members assumes that conditions for previous ones do not hold.

DISJOINT = 0

intersection is empty

TOUCH = 1

intersection is a strict subset of each of the geometries, has dimension less than at least of one of the geometries and only boundaries intersect, but do not cross

CROSS = 2

intersection is a strict subset of each of the geometries, has dimension less than at least of one of the geometries, one of the geometries lies in interior & exterior of the other geometry or boundaries cross

OVERLAP = 3

intersection is a strict subset of each of the geometries and has the same dimension as geometries

COVER = 4

interior of the geometry is a superset of the other

ENCLOSES = 5

boundary of the geometry contains at least one boundary point of the other, but not all, interior of the geometry contains other points of the other

COMPOSITE = 6

geometry is a strict superset of the other and interior/boundary of the geometry is a superset of interior/boundary of the other

EQUAL = 7

geometries are equal

COMPONENT = 8

geometry is a strict subset of the other and interior/boundary of the geometry is a subset of interior/boundary of the other

ENCLOSED = 9

at least one boundary point of the geometry lies on the boundary of the other, but not all, other points of the geometry lie in the interior of the other

WITHIN = 10

geometry is a subset of the interior of the other

class ground.base.Mode(value)[source]

Represents possible context modes.

class ground.base.Context(*, box_cls: Type[ground.hints.Box] = <class 'ground.core.geometries.Box'>, contour_cls: Type[ground.hints.Contour] = <class 'ground.core.geometries.Contour'>, empty_cls: Type[ground.hints.Empty] = <class 'ground.core.geometries.Empty'>, mix_cls: Type[ground.hints.Mix] = <class 'ground.core.geometries.Mix'>, multipoint_cls: Type[ground.hints.Multipoint] = <class 'ground.core.geometries.Multipoint'>, multipolygon_cls: Type[ground.hints.Multipolygon] = <class 'ground.core.geometries.Multipolygon'>, multisegment_cls: Type[ground.hints.Multisegment] = <class 'ground.core.geometries.Multisegment'>, point_cls: Type[ground.hints.Point] = <class 'ground.core.geometries.Point'>, polygon_cls: Type[ground.hints.Polygon] = <class 'ground.core.geometries.Polygon'>, segment_cls: Type[ground.hints.Segment] = <class 'ground.core.geometries.Segment'>, mode: ground.base.Mode = Mode.EXACT, sqrt: Callable[[ground.core.hints.Scalar], ground.core.hints.Scalar] = <function sqrt>)[source]

Represents common language for computational geometry.

property angle_kind: Callable[[ground.hints.Point, ground.hints.Point, ground.hints.Point, ground.hints.Point], ground.core.enums.Kind]

Returns function for computing angle kind.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> (context.angle_kind(Point(0, 0), Point(1, 0), Point(-1, 0))
...  is Kind.OBTUSE)
True
>>> (context.angle_kind(Point(0, 0), Point(1, 0), Point(0, 1))
...  is Kind.RIGHT)
True
>>> (context.angle_kind(Point(0, 0), Point(1, 0), Point(1, 0))
...  is Kind.ACUTE)
True
property angle_orientation: Callable[[ground.hints.Point, ground.hints.Point, ground.hints.Point, ground.hints.Point], ground.core.enums.Orientation]

Returns function for computing angle orientation.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> (context.angle_orientation(Point(0, 0), Point(0, 1), Point(1, 0))
...  is Orientation.CLOCKWISE)
True
>>> (context.angle_orientation(Point(0, 0), Point(1, 0), Point(1, 0))
...  is Orientation.COLLINEAR)
True
>>> (context.angle_orientation(Point(0, 0), Point(1, 0), Point(0, 1))
...  is Orientation.COUNTERCLOCKWISE)
True
property box_cls: Type[ground.hints.Box]

Returns type for boxes.

property box_point_squared_distance: Callable[[ground.hints.Box, ground.hints.Point], ground.core.hints.Scalar]

Returns squared Euclidean distance between box and a point.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Box, Point = context.box_cls, context.point_cls
>>> context.box_point_squared_distance(Box(0, 1, 0, 1),
...                                    Point(1, 1)) == 0
True
>>> context.box_point_squared_distance(Box(0, 1, 0, 1),
...                                    Point(2, 1)) == 1
True
>>> context.box_point_squared_distance(Box(0, 1, 0, 1),
...                                    Point(2, 2)) == 2
True
property contour_cls: Type[ground.hints.Contour]

Returns type for contours.

property cross_product: Callable[[ground.hints.Point, ground.hints.Point, ground.hints.Point, ground.hints.Point], ground.core.hints.Scalar]

Returns cross product of the segments.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> context.cross_product(Point(0, 0), Point(0, 1), Point(0, 0),
...                       Point(1, 0)) == -1
True
>>> context.cross_product(Point(0, 0), Point(1, 0), Point(0, 0),
...                       Point(1, 0)) == 0
True
>>> context.cross_product(Point(0, 0), Point(1, 0), Point(0, 0),
...                       Point(0, 1)) == 1
True
property dot_product: Callable[[ground.hints.Point, ground.hints.Point, ground.hints.Point, ground.hints.Point], ground.core.hints.Scalar]

Returns dot product of the segments.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> context.dot_product(Point(0, 0), Point(1, 0), Point(0, 0),
...                     Point(-1, 0)) == -1
True
>>> context.dot_product(Point(0, 0), Point(1, 0), Point(0, 0),
...                     Point(0, 1)) == 0
True
>>> context.dot_product(Point(0, 0), Point(1, 0), Point(0, 0),
...                     Point(1, 0)) == 1
True
property empty: ground.hints.Empty

Returns an empty geometry.

property empty_cls: Type[ground.hints.Empty]

Returns type for empty geometries.

property mix_cls: Type[ground.hints.Mix]

Returns type for mixes.

property mode: ground.base.Mode

Returns mode of the context.

property multipoint_cls: Type[ground.hints.Multipoint]

Returns type for multipoints.

property multipolygon_cls: Type[ground.hints.Multipolygon]

Returns type for multipolygons.

property multisegment_cls: Type[ground.hints.Multisegment]

Returns type for multisegments.

property origin: ground.hints.Point

Returns origin.

property point_cls: Type[ground.hints.Point]

Returns type for points.

property locate_point_in_point_point_point_circle: Callable[[ground.hints.Point, ground.hints.Point, ground.hints.Point, ground.hints.Point], ground.core.enums.Location]

Returns location of point in point-point-point circle.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> (context.locate_point_in_point_point_point_circle(
...      Point(1, 1), Point(0, 0), Point(2, 0), Point(0, 2))
...  is Location.INTERIOR)
True
>>> (context.locate_point_in_point_point_point_circle(
...      Point(2, 2), Point(0, 0), Point(2, 0), Point(0, 2))
...  is Location.BOUNDARY)
True
>>> (context.locate_point_in_point_point_point_circle(
...      Point(3, 3), Point(0, 0), Point(2, 0), Point(0, 2))
...  is Location.EXTERIOR)
True
property points_squared_distance: Callable[[ground.hints.Point, ground.hints.Point], ground.core.hints.Scalar]

Returns squared Euclidean distance between two points.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> context.points_squared_distance(Point(0, 0), Point(0, 0)) == 0
True
>>> context.points_squared_distance(Point(0, 0), Point(1, 0)) == 1
True
>>> context.points_squared_distance(Point(0, 1), Point(1, 0)) == 2
True
property polygon_cls: Type[ground.hints.Polygon]

Returns type for polygons.

property region_signed_area: Callable[[ground.hints.Contour[ground.core.hints.Scalar]], ground.core.hints.Scalar]

Returns signed area of the region given its contour.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> (context.region_signed_area(Contour([Point(0, 0), Point(1, 0),
...                                      Point(1, 1), Point(0, 1)]))
...  == 1)
True
>>> (context.region_signed_area(Contour([Point(0, 0), Point(0, 1),
...                                      Point(1, 1), Point(1, 0)]))
...  == -1)
True
property segment_cls: Type[ground.hints.Segment]

Returns type for segments.

property sqrt: Callable[[ground.core.hints.Scalar], ground.core.hints.Scalar]

Returns function for computing square root.

box_segment_squared_distance(box: ground.hints.Box, segment: ground.hints.Segment) ground.core.hints.Scalar[source]

Returns squared Euclidean distance between box and a segment.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Box = context.box_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.box_segment_squared_distance(
...     Box(0, 1, 0, 1), Segment(Point(0, 0), Point(1, 1))) == 0
True
>>> context.box_segment_squared_distance(
...     Box(0, 1, 0, 1), Segment(Point(2, 0), Point(2, 1))) == 1
True
>>> context.box_segment_squared_distance(
...     Box(0, 1, 0, 1), Segment(Point(2, 2), Point(3, 2))) == 2
True
contour_box(contour: ground.hints.Contour) ground.hints.Box[source]

Constructs box from contour.

Time complexity:

O(vertices_count)

Memory complexity:

O(1)

where vertices_count = len(contour.vertices).

>>> context = get_context()
>>> Box, Contour, Point = (context.box_cls, context.contour_cls,
...                        context.point_cls)
>>> (context.contour_box(Contour([Point(0, 0), Point(1, 0),
...                               Point(1, 1), Point(0, 1)]))
...  == Box(0, 1, 0, 1))
True
contour_centroid(contour: ground.hints.Contour) ground.hints.Point[source]

Constructs centroid of a contour.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour, Point = context.contour_cls, context.point_cls
>>> (context.contour_centroid(Contour([Point(0, 0), Point(2, 0),
...                                    Point(2, 2), Point(0, 2)]))
...  == Point(1, 1))
True
contour_length(contour: ground.hints.Contour) ground.core.hints.Scalar[source]

Returns Euclidean length of a contour.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.contour_length(Contour([Point(0, 0), Point(3, 0),
...                                 Point(0, 4)])) == 12
True
>>> context.contour_length(Contour([Point(0, 0), Point(1, 0),
...                                 Point(1, 1), Point(0, 1)])) == 4
True
contour_segments(contour: ground.hints.Contour) Sequence[ground.hints.Segment][source]

Constructs segments of a contour.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.contour_segments(Contour([Point(0, 0), Point(2, 0),
...                                    Point(2, 2), Point(0, 2)]))
...  == [Segment(Point(0, 2), Point(0, 0)),
...      Segment(Point(0, 0), Point(2, 0)),
...      Segment(Point(2, 0), Point(2, 2)),
...      Segment(Point(2, 2), Point(0, 2))])
True
contours_box(contours: Sequence[ground.hints.Contour]) ground.hints.Box[source]

Constructs box from contours.

Time complexity:

O(vertices_count)

Memory complexity:

O(1)

where vertices_count = sum(len(contour.vertices) for contour in contours).

>>> context = get_context()
>>> Box = context.box_cls
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> (context.contours_box([Contour([Point(0, 0), Point(1, 0),
...                                 Point(1, 1), Point(0, 1)]),
...                        Contour([Point(1, 1), Point(2, 1),
...                                 Point(2, 2), Point(1, 2)])])
...  == Box(0, 2, 0, 2))
True
is_region_convex(contour: ground.hints.Contour) bool[source]

Checks if region (given its contour) is convex.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> context.is_region_convex(Contour([Point(0, 0), Point(3, 0),
...                                   Point(1, 1), Point(0, 3)]))
False
>>> context.is_region_convex(Contour([Point(0, 0), Point(2, 0),
...                                   Point(2, 2), Point(0, 2)]))
True
merged_box(first_box: ground.hints.Box, second_box: ground.hints.Box) ground.hints.Box[source]

Merges two boxes.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Box = context.box_cls
>>> (context.merged_box(Box(0, 1, 0, 1), Box(1, 2, 1, 2))
...  == Box(0, 2, 0, 2))
True
multipoint_centroid(multipoint: ground.hints.Multipoint) ground.hints.Point[source]

Constructs centroid of a multipoint.

Time complexity:

O(len(multipoint.points))

Memory complexity:

O(1)

>>> context = get_context()
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> context.multipoint_centroid(
...     Multipoint([Point(0, 0), Point(2, 0), Point(2, 2),
...                 Point(0, 2)])) == Point(1, 1)
True
multipolygon_centroid(multipolygon: ground.hints.Multipolygon) ground.hints.Point[source]

Constructs centroid of a multipolygon.

Time complexity:

O(len(vertices_count))

Memory complexity:

O(1)

where vertices_count = sum(len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes) for polygon in multipolygon.polygons).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> Multipolygon = context.multipolygon_cls
>>> (context.multipolygon_centroid(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(1, 1), Point(0, 1)]),
...                            []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(2, 2), Point(1, 2)]),
...                            [])]))
...  == Point(1, 1))
True
multisegment_centroid(multisegment: ground.hints.Multisegment) ground.hints.Point[source]

Constructs centroid of a multisegment.

Time complexity:

O(len(multisegment.segments))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> Multisegment = context.multisegment_cls
>>> (context.multisegment_centroid(
...      Multisegment([Segment(Point(0, 0), Point(2, 0)),
...                    Segment(Point(2, 0), Point(2, 2)),
...                    Segment(Point(0, 2), Point(2, 2)),
...                    Segment(Point(0, 0), Point(0, 2))]))
...  == Point(1, 1))
True
multisegment_length(multisegment: ground.hints.Multisegment) ground.core.hints.Scalar[source]

Returns Euclidean length of a multisegment.

Time complexity:

O(len(multisegment.segments))

Memory complexity:

O(1)

>>> context = get_context()
>>> Multisegment = context.multisegment_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.multisegment_length(
...     Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(0, 0), Point(0, 1))])) == 2
True
>>> context.multisegment_length(
...     Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(0, 0), Point(3, 4))])) == 6
True
points_convex_hull(points: Sequence[ground.hints.Point]) Sequence[ground.hints.Point][source]

Constructs convex hull of points.

Time complexity:

O(points_count * log(points_count))

Memory complexity:

O(points_count)

where points_count = len(points).

>>> context = get_context()
>>> Point = context.point_cls
>>> (context.points_convex_hull([Point(0, 0), Point(2, 0), Point(2, 2),
...                              Point(0, 2)])
...  == [Point(0, 0), Point(2, 0), Point(2, 2), Point(0, 2)])
True
points_box(points: Sequence[ground.hints.Point]) ground.hints.Box[source]

Constructs box from points.

Time complexity:

O(len(points))

Memory complexity:

O(1)

>>> context = get_context()
>>> Box, Point = context.box_cls, context.point_cls
>>> (context.points_box([Point(0, 0), Point(2, 0), Point(2, 2),
...                      Point(0, 2)])
...  == Box(0, 2, 0, 2))
True
polygon_box(polygon: ground.hints.Polygon) ground.hints.Box[source]

Constructs box from polygon.

Time complexity:

O(vertices_count)

Memory complexity:

O(1)

where vertices_count = len(polygon.border.vertices).

>>> context = get_context()
>>> Box, Contour, Point, Polygon = (context.box_cls,
...                                 context.contour_cls,
...                                 context.point_cls,
...                                 context.polygon_cls)
>>> context.polygon_box(
...     Polygon(Contour([Point(0, 0), Point(1, 0), Point(1, 1),
...                      Point(0, 1)]), [])) == Box(0, 1, 0, 1)
True
polygon_centroid(polygon: ground.hints.Polygon) ground.hints.Point[source]

Constructs centroid of a polygon.

Time complexity:

O(vertices_count)

Memory complexity:

O(1)

where vertices_count = len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> context.polygon_centroid(
...     Polygon(Contour([Point(0, 0), Point(4, 0), Point(4, 4),
...                      Point(0, 4)]),
...             [Contour([Point(1, 1), Point(1, 3), Point(3, 3),
...                       Point(3, 1)])])) == Point(2, 2)
True
polygons_box(polygons: Sequence[ground.hints.Polygon]) ground.hints.Box[source]

Constructs box from polygons.

Time complexity:

O(vertices_count)

Memory complexity:

O(1)

where vertices_count = sum(len(polygon.border.vertices) for polygon in polygons).

>>> context = get_context()
>>> Box, Contour, Point, Polygon = (context.box_cls,
...                                 context.contour_cls,
...                                 context.point_cls,
...                                 context.polygon_cls)
>>> context.polygons_box(
...     [Polygon(Contour([Point(0, 0), Point(1, 0), Point(1, 1),
...                       Point(0, 1)]), []),
...      Polygon(Contour([Point(1, 1), Point(2, 1), Point(2, 2),
...                       Point(1, 2)]), [])]) == Box(0, 2, 0, 2)
True
region_centroid(contour: ground.hints.Contour) ground.hints.Point[source]

Constructs centroid of a region given its contour.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(1)

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> (context.region_centroid(Contour([Point(0, 0), Point(2, 0),
...                                   Point(2, 2), Point(0, 2)]))
...  == Point(1, 1))
True
replace(*, box_cls: Optional[Type[ground.hints.Box]] = None, contour_cls: Optional[Type[ground.hints.Contour]] = None, empty_cls: Optional[Type[ground.hints.Empty]] = None, mix_cls: Optional[Type[ground.hints.Mix]] = None, multipoint_cls: Optional[Type[ground.hints.Multipoint]] = None, multipolygon_cls: Optional[Type[ground.hints.Multipolygon]] = None, multisegment_cls: Optional[Type[ground.hints.Multisegment]] = None, point_cls: Optional[Type[ground.hints.Point]] = None, polygon_cls: Optional[Type[ground.hints.Polygon]] = None, segment_cls: Optional[Type[ground.hints.Segment]] = None, mode: Optional[ground.base.Mode] = None, sqrt: Optional[Callable[[ground.core.hints.Scalar], ground.core.hints.Scalar]] = None) ground.base.Context[source]

Constructs context from the original one replacing given parameters.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> robust_context = context.replace(mode=Mode.ROBUST)
>>> isinstance(robust_context, Context)
True
>>> robust_context.mode is Mode.ROBUST
True
rotate_contour(contour: ground.hints.Contour, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Contour[source]

Returns contour rotated by given angle around given center.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(len(contour.vertices))

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> (context.rotate_contour(
...      Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), 1, 0,
...      Point(0, 1))
...  == Contour([Point(0, 0), Point(1, 0), Point(0, 1)]))
True
>>> (context.rotate_contour(
...      Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), 0, 1,
...      Point(0, 1))
...  == Contour([Point(1, 1), Point(1, 2), Point(0, 1)]))
True
rotate_contour_around_origin(contour: ground.hints.Contour, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Contour[source]

Returns contour rotated by given angle around origin.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(len(contour.vertices))

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> (context.rotate_contour_around_origin(
...      Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), 1, 0)
...  == Contour([Point(0, 0), Point(1, 0), Point(0, 1)]))
True
>>> (context.rotate_contour_around_origin(
...      Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), 0, 1)
...  == Contour([Point(0, 0), Point(0, 1), Point(-1, 0)]))
True
rotate_multipoint(multipoint: ground.hints.Multipoint, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Multipoint[source]

Returns multipoint rotated by given angle around given center.

Time complexity:

O(len(multipoint.points))

Memory complexity:

O(len(multipoint.points))

>>> context = get_context()
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> (context.rotate_multipoint(Multipoint([Point(0, 0), Point(1, 0)]),
...                            1, 0, Point(0, 1))
...  == Multipoint([Point(0, 0), Point(1, 0)]))
True
>>> (context.rotate_multipoint(Multipoint([Point(0, 0), Point(1, 0)]),
...                            0, 1, Point(0, 1))
...  == Multipoint([Point(1, 1), Point(1, 2)]))
True
rotate_multipoint_around_origin(multipoint: ground.hints.Multipoint, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Multipoint[source]

Returns multipoint rotated by given angle around origin.

Time complexity:

O(len(multipoint.points))

Memory complexity:

O(len(multipoint.points))

>>> context = get_context()
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> (context.rotate_multipoint_around_origin(
...      Multipoint([Point(0, 0), Point(1, 0)]), 1, 0)
...  == Multipoint([Point(0, 0), Point(1, 0)]))
True
>>> (context.rotate_multipoint_around_origin(
...      Multipoint([Point(0, 0), Point(1, 0)]), 0, 1)
...  == Multipoint([Point(0, 0), Point(0, 1)]))
True
rotate_multipolygon(multipolygon: ground.hints.Multipolygon, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Multipolygon[source]

Returns multipolygon rotated by given angle around given center.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = sum(len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes) for polygon in multipolygon.polygons).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Multipolygon = context.multipolygon_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> (context.rotate_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), [])]),
...      1, 0, Point(0, 1))
...  == Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                    Point(0, 1)]), [])]))
True
>>> (context.rotate_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), [])]),
...      0, 1, Point(0, 1))
...  == Multipolygon([Polygon(Contour([Point(1, 1), Point(1, 2),
...                                    Point(0, 1)]), [])]))
True
rotate_multipolygon_around_origin(multipolygon: ground.hints.Multipolygon, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Multipolygon[source]

Returns multipolygon rotated by given angle around origin.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = sum(len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes) for polygon in multipolygon.polygons).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Multipolygon = context.multipolygon_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> (context.rotate_multipolygon_around_origin(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), [])]),
...      1, 0)
...  == Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                    Point(0, 1)]), [])]))
True
>>> (context.rotate_multipolygon_around_origin(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), [])]),
...      0, 1)
...  == Multipolygon([Polygon(Contour([Point(0, 0), Point(0, 1),
...                                    Point(-1, 0)]), [])]))
True
rotate_multisegment(multisegment: ground.hints.Multisegment, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Multisegment[source]

Returns multisegment rotated by given angle around given center.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Multisegment = context.multisegment_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.rotate_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 1, 0,
...      Point(0, 1))
...  == Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(0, 0), Point(0, 1))]))
True
>>> (context.rotate_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 0, 1,
...      Point(0, 1))
...  == Multisegment([Segment(Point(1, 1), Point(1,2)),
...                   Segment(Point(1, 1), Point(0, 1))]))
True
rotate_multisegment_around_origin(multisegment: ground.hints.Multisegment, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Multisegment[source]

Returns multisegment rotated by given angle around origin.

Time complexity:

O(len(multisegment.segments))

Memory complexity:

O(len(multisegment.segments))

>>> context = get_context()
>>> Multisegment = context.multisegment_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.rotate_multisegment_around_origin(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 1, 0)
...  == Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(0, 0), Point(0, 1))]))
True
>>> (context.rotate_multisegment_around_origin(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 0, 1)
...  == Multisegment([Segment(Point(0, 0), Point(0, 1)),
...                   Segment(Point(0, 0), Point(-1, 0))]))
True
rotate_point(point: ground.hints.Point, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Point[source]

Returns point rotated by given angle around given center.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> context.rotate_point(Point(1, 0), 1, 0, Point(0, 1)) == Point(1, 0)
True
>>> context.rotate_point(Point(1, 0), 0, 1, Point(0, 1)) == Point(1, 2)
True
rotate_point_around_origin(point: ground.hints.Point, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Point[source]

Returns point rotated by given angle around origin.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> (context.rotate_point_around_origin(Point(1, 0), 1, 0)
...  == Point(1, 0))
True
>>> (context.rotate_point_around_origin(Point(1, 0), 0, 1)
...  == Point(0, 1))
True
rotate_polygon(polygon: ground.hints.Polygon, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Polygon[source]

Returns polygon rotated by given angle around given center.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> (context.rotate_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      1, 0, Point(0, 1))
...  == Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []))
True
>>> (context.rotate_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      0, 1, Point(0, 1))
...  == Polygon(Contour([Point(1, 1), Point(1, 2), Point(0, 1)]), []))
True
rotate_polygon_around_origin(polygon: ground.hints.Polygon, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Polygon[source]

Returns polygon rotated by given angle around origin.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> (context.rotate_polygon_around_origin(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      1, 0)
...  == Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []))
True
>>> (context.rotate_polygon_around_origin(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      0, 1)
...  == Polygon(Contour([Point(0, 0), Point(0, 1), Point(-1, 0)]), []))
True
rotate_segment(segment: ground.hints.Segment, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar, center: ground.hints.Point) ground.hints.Segment[source]

Returns segment rotated by given angle around given center.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.rotate_segment(Segment(Point(0, 0), Point(1, 0)), 1, 0,
...                         Point(0, 1))
...  == Segment(Point(0, 0), Point(1, 0)))
True
>>> (context.rotate_segment(Segment(Point(0, 0), Point(1, 0)), 0, 1,
...                         Point(0, 1))
...  == Segment(Point(1, 1), Point(1, 2)))
True
rotate_segment_around_origin(segment: ground.hints.Segment, cosine: ground.core.hints.Scalar, sine: ground.core.hints.Scalar) ground.hints.Segment[source]

Returns segment rotated by given angle around origin.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.rotate_segment_around_origin(
...      Segment(Point(0, 0), Point(1, 0)), 1, 0)
...  == Segment(Point(0, 0), Point(1, 0)))
True
>>> (context.rotate_segment_around_origin(
...      Segment(Point(0, 0), Point(1, 0)), 0, 1)
...  == Segment(Point(0, 0), Point(0, 1)))
True
scale_contour(contour: ground.hints.Contour, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) Union[ground.hints.Contour, ground.hints.Multipoint, ground.hints.Segment][source]

Returns contour scaled by given factor.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(len(contour.vertices))

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.scale_contour(Contour([Point(0, 0), Point(1, 0),
...                                 Point(0, 1)]), 0, 0)
...  == Multipoint([Point(0, 0)]))
True
>>> (context.scale_contour(Contour([Point(0, 0), Point(1, 0),
...                                 Point(0, 1)]), 1, 0)
...  == Segment(Point(0, 0), Point(1, 0)))
True
>>> (context.scale_contour(Contour([Point(0, 0), Point(1, 0),
...                                 Point(0, 1)]), 0, 1)
...  == Segment(Point(0, 0), Point(0, 1)))
True
>>> (context.scale_contour(Contour([Point(0, 0), Point(1, 0),
...                                 Point(0, 1)]), 1, 1)
...  == Contour([Point(0, 0), Point(1, 0), Point(0, 1)]))
True
scale_multipoint(multipoint: ground.hints.Multipoint, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) ground.hints.Multipoint[source]

Returns multipoint scaled by given factor.

Time complexity:

O(len(multipoint.points))

Memory complexity:

O(len(multipoint.points))

>>> context = get_context()
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> (context.scale_multipoint(Multipoint([Point(0, 0), Point(1, 1)]),
...                           0, 0)
...  == Multipoint([Point(0, 0)]))
True
>>> (context.scale_multipoint(Multipoint([Point(0, 0), Point(1, 1)]),
...                           1, 0)
...  == Multipoint([Point(0, 0), Point(1, 0)]))
True
>>> (context.scale_multipoint(Multipoint([Point(0, 0), Point(1, 1)]),
...                           0, 1)
...  == Multipoint([Point(0, 0), Point(0, 1)]))
True
>>> (context.scale_multipoint(Multipoint([Point(0, 0), Point(1, 1)]),
...                           1, 1)
...  == Multipoint([Point(0, 0), Point(1, 1)]))
True
scale_multipolygon(multipolygon: ground.hints.Multipolygon, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) Union[ground.hints.Multipoint, ground.hints.Multipolygon, ground.hints.Multisegment][source]

Returns multipolygon scaled by given factor.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = sum(len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes) for polygon in multipolygon.polygons).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Multipoint = context.multipoint_cls
>>> Multipolygon = context.multipolygon_cls
>>> Multisegment = context.multisegment_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> Segment = context.segment_cls
>>> (context.scale_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 0, 0)
...  == Multipoint([Point(0, 0)]))
True
>>> (context.scale_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 1, 0)
...  == Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(1, 0), Point(2, 0))]))
True
>>> (context.scale_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 0, 1)
...  == Multisegment([Segment(Point(0, 0), Point(0, 1)),
...                   Segment(Point(0, 1), Point(0, 2))]))
True
>>> (context.scale_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 1, 1)
...  == Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                    Point(0, 1)]), []),
...                   Polygon(Contour([Point(1, 1), Point(2, 1),
...                                    Point(1, 2)]), [])]))
True
scale_multisegment(multisegment: ground.hints.Multisegment, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) Union[ground.hints.Mix, ground.hints.Multipoint, ground.hints.Multisegment][source]

Returns multisegment scaled by given factor.

Time complexity:

O(len(multisegment.segments))

Memory complexity:

O(len(multisegment.segments))

>>> context = get_context()
>>> EMPTY = context.empty
>>> Mix = context.mix_cls
>>> Multipoint = context.multipoint_cls
>>> Multisegment = context.multisegment_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.scale_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 0, 0)
...  == Multipoint([Point(0, 0)]))
True
>>> (context.scale_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 1, 0)
...  == Mix(Multipoint([Point(0, 0)]),
...         Segment(Point(0, 0), Point(1, 0)), EMPTY))
True
>>> (context.scale_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 0, 1)
...  == Mix(Multipoint([Point(0, 0)]),
...         Segment(Point(0, 0), Point(0, 1)), EMPTY))
True
>>> (context.scale_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 1, 1)
...  == Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(0, 0), Point(0, 1))]))
True
scale_point(point: ground.hints.Point, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) ground.hints.Point[source]

Returns point scaled by given factor.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> context.scale_point(Point(1, 1), 0, 0) == Point(0, 0)
True
>>> context.scale_point(Point(1, 1), 1, 0) == Point(1, 0)
True
>>> context.scale_point(Point(1, 1), 0, 1) == Point(0, 1)
True
>>> context.scale_point(Point(1, 1), 1, 1) == Point(1, 1)
True
scale_polygon(polygon: ground.hints.Polygon, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) Union[ground.hints.Multipoint, ground.hints.Polygon, ground.hints.Segment][source]

Returns polygon scaled by given factor.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> Segment = context.segment_cls
>>> (context.scale_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      0, 0)
...  == Multipoint([Point(0, 0)]))
True
>>> (context.scale_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      1, 0)
...  == Segment(Point(0, 0), Point(1, 0)))
True
>>> (context.scale_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      0, 1)
...  == Segment(Point(0, 0), Point(0, 1)))
True
>>> (context.scale_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      1, 1)
...  == Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []))
True
scale_segment(segment: ground.hints.Segment, factor_x: ground.core.hints.Scalar, factor_y: ground.core.hints.Scalar) Union[ground.hints.Multipoint, ground.hints.Segment][source]

Returns segment scaled by given factor.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.scale_segment(Segment(Point(0, 0), Point(1, 1)), 0, 0)
...  == Multipoint([Point(0, 0)]))
True
>>> (context.scale_segment(Segment(Point(0, 0), Point(1, 1)), 1, 0)
...  == Segment(Point(0, 0), Point(1, 0)))
True
>>> (context.scale_segment(Segment(Point(0, 0), Point(1, 1)), 0, 1)
...  == Segment(Point(0, 0), Point(0, 1)))
True
>>> (context.scale_segment(Segment(Point(0, 0), Point(1, 1)), 1, 1)
...  == Segment(Point(0, 0), Point(1, 1)))
True
segment_box(segment: ground.hints.Segment) ground.hints.Box[source]

Constructs box from segment.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Box, Point, Segment = (context.box_cls, context.point_cls,
...                        context.segment_cls)
>>> (context.segment_box(Segment(Point(0, 1), Point(2, 3)))
...  == Box(0, 2, 1, 3))
True
segment_centroid(segment: ground.hints.Segment) ground.hints.Point[source]

Constructs centroid of a segment.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point, Segment = context.point_cls, context.segment_cls
>>> (context.segment_centroid(Segment(Point(0, 1), Point(2, 3)))
...  == Point(1, 2))
True
segment_contains_point(segment: ground.hints.Segment, point: ground.hints.Point) bool[source]

Checks if a segment contains given point.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.segment_contains_point(Segment(Point(0, 0), Point(2, 0)),
...                                Point(0, 0))
True
>>> context.segment_contains_point(Segment(Point(0, 0), Point(2, 0)),
...                                Point(0, 2))
False
>>> context.segment_contains_point(Segment(Point(0, 0), Point(2, 0)),
...                                Point(1, 0))
True
>>> context.segment_contains_point(Segment(Point(0, 0), Point(2, 0)),
...                                Point(1, 1))
False
>>> context.segment_contains_point(Segment(Point(0, 0), Point(2, 0)),
...                                Point(2, 0))
True
>>> context.segment_contains_point(Segment(Point(0, 0), Point(2, 0)),
...                                Point(3, 0))
False
segment_length(segment: ground.hints.Segment) ground.core.hints.Scalar[source]

Returns Euclidean length of a segment.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.segment_length(Segment(Point(0, 0), Point(1, 0))) == 1
True
>>> context.segment_length(Segment(Point(0, 0), Point(0, 1))) == 1
True
>>> context.segment_length(Segment(Point(0, 0), Point(3, 4))) == 5
True
segment_point_squared_distance(segment: ground.hints.Segment, point: ground.hints.Point) ground.core.hints.Scalar[source]

Returns squared Euclidean distance between segment and a point.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.segment_point_squared_distance(
...     Segment(Point(0, 0), Point(1, 0)), Point(0, 0)) == 0
True
>>> context.segment_point_squared_distance(
...     Segment(Point(0, 0), Point(1, 0)), Point(0, 1)) == 1
True
>>> context.segment_point_squared_distance(
...     Segment(Point(0, 0), Point(1, 0)), Point(2, 1)) == 2
True
segments_box(segments: Sequence[ground.hints.Segment]) ground.hints.Box[source]

Constructs box from segments.

Time complexity:

O(len(segments))

Memory complexity:

O(1)

>>> context = get_context()
>>> Box, Point, Segment = (context.box_cls, context.point_cls,
...                        context.segment_cls)
>>> (context.segments_box([Segment(Point(0, 0), Point(1, 1)),
...                        Segment(Point(1, 1), Point(2, 2))])
...  == Box(0, 2, 0, 2))
True
segments_intersection(first: ground.hints.Segment, second: ground.hints.Segment) ground.hints.Point[source]

Returns intersection point of two segments.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.segments_intersection(Segment(Point(0, 0), Point(2, 0)),
...                                Segment(Point(0, 0), Point(0, 1)))
...  == Point(0, 0))
True
>>> (context.segments_intersection(Segment(Point(0, 0), Point(2, 0)),
...                                Segment(Point(1, 0), Point(1, 1)))
...  == Point(1, 0))
True
>>> (context.segments_intersection(Segment(Point(0, 0), Point(2, 0)),
...                                Segment(Point(2, 0), Point(3, 0)))
...  == Point(2, 0))
True
segments_relation(test: ground.hints.Segment, goal: ground.hints.Segment) ground.core.enums.Relation[source]

Returns relation between two segments.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                            Segment(Point(1, 0), Point(2, 0)))
...  is Relation.DISJOINT)
True
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                            Segment(Point(0, 0), Point(2, 0)))
...  is Relation.TOUCH)
True
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                            Segment(Point(2, 0), Point(0, 2)))
...  is Relation.CROSS)
True
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                           Segment(Point(0, 0), Point(1, 1)))
...  is Relation.COMPOSITE)
True
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                            Segment(Point(0, 0), Point(2, 2)))
...  is Relation.EQUAL)
True
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                            Segment(Point(0, 0), Point(3, 3)))
...  is Relation.COMPONENT)
True
>>> (context.segments_relation(Segment(Point(0, 0), Point(2, 2)),
...                            Segment(Point(1, 1), Point(3, 3)))
...  is Relation.OVERLAP)
True
segments_squared_distance(first: ground.hints.Segment, second: ground.hints.Segment) ground.core.hints.Scalar[source]

Returns squared Euclidean distance between two segments.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> context.segments_squared_distance(
...     Segment(Point(0, 0), Point(1, 0)),
...     Segment(Point(0, 0), Point(0, 1))) == 0
True
>>> context.segments_squared_distance(
...     Segment(Point(0, 0), Point(1, 0)),
...     Segment(Point(0, 1), Point(1, 1))) == 1
True
>>> context.segments_squared_distance(
...     Segment(Point(0, 0), Point(1, 0)),
...     Segment(Point(2, 1), Point(2, 2))) == 2
True
translate_contour(contour: ground.hints.Contour, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Contour[source]

Returns contour translated by given step.

Time complexity:

O(len(contour.vertices))

Memory complexity:

O(len(contour.vertices))

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.translate_contour(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), 0, 0)
...  == Contour([Point(0, 0), Point(1, 0), Point(0, 1)]))
True
>>> (context.translate_contour(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), 1, 0)
...  == Contour([Point(1, 0), Point(2, 0), Point(1, 1)]))
True
>>> (context.translate_contour(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), 0, 1)
...  == Contour([Point(0, 1), Point(1, 1), Point(0, 2)]))
True
>>> (context.translate_contour(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), 1, 1)
...  == Contour([Point(1, 1), Point(2, 1), Point(1, 2)]))
True
translate_multipoint(multipoint: ground.hints.Multipoint, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Multipoint[source]

Returns multipoint translated by given step.

Time complexity:

O(len(multipoint.points))

Memory complexity:

O(len(multipoint.points))

>>> context = get_context()
>>> Multipoint = context.multipoint_cls
>>> Point = context.point_cls
>>> (context.translate_multipoint(Multipoint([Point(0, 0),
...                                           Point(1, 0)]), 0, 0)
...  == Multipoint([Point(0, 0), Point(1, 0)]))
True
>>> (context.translate_multipoint(Multipoint([Point(0, 0),
...                                           Point(1, 0)]), 1, 0)
...  == Multipoint([Point(1, 0), Point(2, 0)]))
True
>>> (context.translate_multipoint(Multipoint([Point(0, 0),
...                                           Point(1, 0)]), 0, 1)
...  == Multipoint([Point(0, 1), Point(1, 1)]))
True
>>> (context.translate_multipoint(Multipoint([Point(0, 0),
...                                           Point(1, 0)]), 1, 1)
...  == Multipoint([Point(1, 1), Point(2, 1)]))
True
translate_multipolygon(multipolygon: ground.hints.Multipolygon, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Multipolygon[source]

Returns multipolygon translated by given step.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = sum(len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes) for polygon in multipolygon.polygons).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Multipolygon = context.multipolygon_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> (context.translate_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 0, 0)
...  == Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                    Point(0, 1)]), []),
...                   Polygon(Contour([Point(1, 1), Point(2, 1),
...                                    Point(1, 2)]), [])]))
True
>>> (context.translate_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 1, 0)
...  == Multipolygon([Polygon(Contour([Point(1, 0), Point(2, 0),
...                                    Point(1, 1)]), []),
...                   Polygon(Contour([Point(2, 1), Point(3, 1),
...                                    Point(2, 2)]), [])]))
True
>>> (context.translate_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 0, 1)
...  == Multipolygon([Polygon(Contour([Point(0, 1), Point(1, 1),
...                                    Point(0, 2)]), []),
...                   Polygon(Contour([Point(1, 2), Point(2, 2),
...                                    Point(1, 3)]), [])]))
True
>>> (context.translate_multipolygon(
...      Multipolygon([Polygon(Contour([Point(0, 0), Point(1, 0),
...                                     Point(0, 1)]), []),
...                    Polygon(Contour([Point(1, 1), Point(2, 1),
...                                     Point(1, 2)]), [])]), 1, 1)
...  == Multipolygon([Polygon(Contour([Point(1, 1), Point(2, 1),
...                                    Point(1, 2)]), []),
...                   Polygon(Contour([Point(2, 2), Point(3, 2),
...                                    Point(2, 3)]), [])]))
True
translate_multisegment(multisegment: ground.hints.Multisegment, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Multisegment[source]

Returns multisegment translated by given step.

Time complexity:

O(len(multisegment.segments))

Memory complexity:

O(len(multisegment.segments))

>>> context = get_context()
>>> Multisegment = context.multisegment_cls
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.translate_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 0, 0)
...  == Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                   Segment(Point(0, 0), Point(0, 1))]))
True
>>> (context.translate_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 1, 0)
...  == Multisegment([Segment(Point(1, 0), Point(2, 0)),
...                   Segment(Point(1, 0), Point(1, 1))]))
True
>>> (context.translate_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 0, 1)
...  == Multisegment([Segment(Point(0, 1), Point(1, 1)),
...                   Segment(Point(0, 1), Point(0, 2))]))
True
>>> (context.translate_multisegment(
...      Multisegment([Segment(Point(0, 0), Point(1, 0)),
...                    Segment(Point(0, 0), Point(0, 1))]), 1, 1)
...  == Multisegment([Segment(Point(1, 1), Point(2, 1)),
...                   Segment(Point(1, 1), Point(1, 2))]))
True
translate_point(point: ground.hints.Point, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Point[source]

Returns point translated by given step.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> context.translate_point(Point(0, 0), 0, 0) == Point(0, 0)
True
>>> context.translate_point(Point(0, 0), 1, 0) == Point(1, 0)
True
>>> context.translate_point(Point(0, 0), 0, 1) == Point(0, 1)
True
>>> context.translate_point(Point(0, 0), 1, 1) == Point(1, 1)
True
translate_polygon(polygon: ground.hints.Polygon, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Polygon[source]

Returns polygon translated by given step.

Time complexity:

O(vertices_count)

Memory complexity:

O(vertices_count)

where vertices_count = len(polygon.border.vertices) + sum(len(hole.vertices) for hole in polygon.holes).

>>> context = get_context()
>>> Contour = context.contour_cls
>>> Point = context.point_cls
>>> Polygon = context.polygon_cls
>>> (context.translate_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      0, 0)
...  == Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []))
True
>>> (context.translate_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      1, 0)
...  == Polygon(Contour([Point(1, 0), Point(2, 0), Point(1, 1)]), []))
True
>>> (context.translate_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      0, 1)
...  == Polygon(Contour([Point(0, 1), Point(1, 1), Point(0, 2)]), []))
True
>>> (context.translate_polygon(
...      Polygon(Contour([Point(0, 0), Point(1, 0), Point(0, 1)]), []),
...      1, 1)
...  == Polygon(Contour([Point(1, 1), Point(2, 1), Point(1, 2)]), []))
True
translate_segment(segment: ground.hints.Segment, step_x: ground.core.hints.Scalar, step_y: ground.core.hints.Scalar) ground.hints.Segment[source]

Returns segment translated by given step.

Time complexity:

O(1)

Memory complexity:

O(1)

>>> context = get_context()
>>> Point = context.point_cls
>>> Segment = context.segment_cls
>>> (context.translate_segment(Segment(Point(0, 0), Point(1, 0)), 0, 0)
...  == Segment(Point(0, 0), Point(1, 0)))
True
>>> (context.translate_segment(Segment(Point(0, 0), Point(1, 0)), 1, 0)
...  == Segment(Point(1, 0), Point(2, 0)))
True
>>> (context.translate_segment(Segment(Point(0, 0), Point(1, 0)), 0, 1)
...  == Segment(Point(0, 1), Point(1, 1)))
True
>>> (context.translate_segment(Segment(Point(0, 0), Point(1, 0)), 1, 1)
...  == Segment(Point(1, 1), Point(2, 1)))
True
ground.base.get_context() ground.base.Context[source]

Returns current context.

ground.base.set_context(context: ground.base.Context) None[source]

Sets current context.

hints module

class ground.hints.Box(min_x: ground.core.hints.Scalar, max_x: ground.core.hints.Scalar, min_y: ground.core.hints.Scalar, max_y: ground.core.hints.Scalar)

Box is a limited closed region defined by axis-aligned rectangular contour.

abstract __eq__(other: ground.hints.Box) bool[source]

Checks if the box is equal to the other.

abstract static __new__(cls, min_x: ground.core.hints.Scalar, max_x: ground.core.hints.Scalar, min_y: ground.core.hints.Scalar, max_y: ground.core.hints.Scalar) ground.hints.Box[source]
abstract property max_x: ground.core.hints.Scalar

Maximum x-coordinate of the box.

abstract property max_y: ground.core.hints.Scalar

Maximum y-coordinate of the box.

abstract property min_x: ground.core.hints.Scalar

Minimum x-coordinate of the box.

abstract property min_y: ground.core.hints.Scalar

Minimum y-coordinate of the box.

class ground.hints.Contour(vertices: Sequence[ground.hints.Point])

Contour is a linear geometry that represents closed simple polyline defined by a sequence of points (called contour’s vertices).

abstract __eq__(other: ground.hints.Contour) bool[source]

Checks if the contour is equal to the other.

abstract static __new__(cls, vertices: Sequence[ground.hints.Point]) ground.hints.Contour[source]
abstract property vertices: Sequence[ground.hints.Point]

Vertices of the contour.

class ground.hints.Empty

Represents an empty set of points.

abstract __eq__(other: ground.hints.Empty) bool[source]

Checks if the empty geometry is equal to the other.

abstract static __new__(cls) ground.hints.Empty[source]
class ground.hints.Mix(discrete: Union[ground.hints.Empty, ground.hints.Multipoint], linear: Union[ground.hints.Empty, ground.hints.Segment, ground.hints.Multisegment, ground.hints.Contour], shaped: Union[ground.hints.Empty, ground.hints.Polygon, ground.hints.Multipolygon])

Mix is a set of two or more non-empty geometries with different dimensions.

abstract __eq__(other: ground.hints.Mix) bool[source]

Checks if the mix is equal to the other.

abstract static __new__(cls, discrete: Union[ground.hints.Empty, ground.hints.Multipoint], linear: Union[ground.hints.Empty, ground.hints.Segment, ground.hints.Multisegment, ground.hints.Contour], shaped: Union[ground.hints.Empty, ground.hints.Polygon, ground.hints.Multipolygon]) ground.hints.Mix[source]
abstract property discrete: Union[ground.hints.Empty, ground.hints.Multipoint]

Discrete component of the mix.

abstract property linear: Union[ground.hints.Empty, ground.hints.Segment, ground.hints.Multisegment, ground.hints.Contour]

Linear component of the mix.

abstract property shaped: Union[ground.hints.Empty, ground.hints.Polygon, ground.hints.Multipolygon]

Shaped component of the mix.

class ground.hints.Multipoint(points: Sequence[ground.hints.Point])

Multipoint is a discrete geometry that represents non-empty set of unique points.

abstract __eq__(other: ground.hints.Multipoint) bool[source]

Checks if the multipoint is equal to the other.

abstract static __new__(cls, points: Sequence[ground.hints.Point]) ground.hints.Multipoint[source]
abstract property points: Sequence[ground.hints.Point]

Points of the multipoint.

class ground.hints.Multipolygon(polygons: Sequence[ground.hints.Polygon])

Multipolygon is a shaped geometry that represents set of two or more non-overlapping polygons intersecting only in discrete set of points.

abstract __eq__(other: ground.hints.Multipolygon) bool[source]

Checks if the multipolygon is equal to the other.

abstract static __new__(cls, polygons: Sequence[ground.hints.Polygon]) ground.hints.Multipolygon[source]
abstract property polygons: Sequence[ground.hints.Polygon]

Polygons of the multipolygon.

class ground.hints.Multisegment(segments: Sequence[ground.hints.Segment])

Multisegment is a linear geometry that represents set of two or more non-crossing and non-overlapping segments.

abstract __eq__(other: ground.hints.Multisegment) bool[source]

Checks if the multisegment is equal to the other.

abstract static __new__(cls, segments: Sequence[ground.hints.Segment]) ground.hints.Multisegment[source]
abstract property segments: Sequence[ground.hints.Segment]

Segments of the multisegment.

class ground.hints.Point(x: ground.core.hints.Scalar, y: ground.core.hints.Scalar)

Point is a minimal element of the plane defined by pair of real numbers (called point’s coordinates).

Points considered to be sorted lexicographically, with abscissas being compared first.

abstract __eq__(other: ground.hints.Point) bool[source]

Checks if the point is equal to the other.

abstract __ge__(other: ground.hints.Point) bool[source]

Checks if the point is greater than or equal to the other.

abstract __gt__(other: ground.hints.Point) bool[source]

Checks if the point is greater than the other.

abstract __hash__() int[source]

Returns hash value of the point.

abstract __le__(other: ground.hints.Point) bool[source]

Checks if the point is less than or equal to the other.

abstract __lt__(other: ground.hints.Point) bool[source]

Checks if the point is less than the other.

abstract static __new__(cls, x: ground.core.hints.Scalar, y: ground.core.hints.Scalar) ground.hints.Point[source]
abstract property x: ground.core.hints.Scalar

Abscissa of the point.

abstract property y: ground.core.hints.Scalar

Ordinate of the point.

class ground.hints.Polygon(border: ground.hints.Contour, holes: Sequence[ground.hints.Contour])

Polygon is a shaped geometry that represents limited closed region defined by the pair of outer contour (called polygon’s border) and possibly empty sequence of inner contours (called polygon’s holes).

abstract __eq__(other: ground.hints.Polygon) bool[source]

Checks if the polygon is equal to the other.

abstract static __new__(cls, border: ground.hints.Contour, holes: Sequence[ground.hints.Contour]) ground.hints.Polygon[source]
abstract property border: ground.hints.Contour

Border of the polygon.

abstract property holes: Sequence[ground.hints.Contour]

Holes of the polygon.

class ground.hints.Segment(start: ground.hints.Point, end: ground.hints.Point)

Segment (or line segment) is a linear geometry that represents a limited continuous part of the line containing more than one point defined by a pair of unequal points (called segment’s endpoints).

abstract __eq__(other: ground.hints.Segment) bool[source]

Checks if the segment is equal to the other.

abstract static __new__(cls, start: ground.hints.Point, end: ground.hints.Point) ground.hints.Segment[source]
abstract property end: ground.hints.Point

End endpoint of the segment.

abstract property start: ground.hints.Point

Start endpoint of the segment.