Beispiel #1
0
    return strategies.tuples(coordinates_to_ported_points(coordinates),
                             coordinates_to_origins(coordinates))


def coordinates_to_origins(
        coordinates: Strategy[Coordinate]) -> Strategy[Point]:
    def coordinate_to_origin(coordinate: Coordinate) -> Point:
        domain = type(coordinate)
        return Point(domain(), domain())

    return coordinates.map(coordinate_to_origin)


points_with_origins = (
    coordinates_strategies.flatmap(coordinates_to_points_with_origins))


def coordinates_to_points_pairs_with_origins(
        coordinates: Strategy[Coordinate]
) -> Strategy[Tuple[Point, Point, Point]]:
    points = coordinates_to_ported_points(coordinates)
    return strategies.tuples(points, points,
                             coordinates_to_origins(coordinates))


points_pairs_with_origins = coordinates_strategies.flatmap(
    coordinates_to_points_pairs_with_origins)
points_strategies = coordinates_strategies.map(coordinates_to_ported_points)
points_pairs = points_strategies.flatmap(to_pairs)
points_triplets = points_strategies.flatmap(to_triplets)
Beispiel #2
0
from typing import (Sequence, Tuple)

from hypothesis import strategies
from hypothesis_geometry import planar
from robust.linear import segment_contains

from sect.core.utils import contour_to_segments
from sect.hints import (Point, Segment)
from tests.strategies import coordinates_strategies
from tests.strategies.base import MAX_COORDINATE
from tests.utils import (Polygon, Strategy, points_do_not_lie_on_the_same_line,
                         sub_lists)

to_points_lists = partial(strategies.lists, unique=True)
points_lists = (coordinates_strategies.map(planar.points).flatmap(
    partial(to_points_lists,
            min_size=3)).filter(points_do_not_lie_on_the_same_line))
non_triangle_points_lists = (coordinates_strategies.map(planar.points).flatmap(
    partial(to_points_lists, min_size=4)))
triangles = (coordinates_strategies.flatmap(
    planar.triangular_contours).map(tuple))
contours = coordinates_strategies.flatmap(planar.contours)
polygons = coordinates_strategies.flatmap(planar.polygons)


def to_polygons_with_extra_points(
        polygon: Polygon) -> Strategy[Tuple[Polygon, Sequence[Point]]]:
    border, holes = polygon
    return strategies.tuples(
        strategies.just(polygon),
        sub_lists(
Beispiel #3
0
from itertools import combinations
from typing import List

from ground.hints import Scalar
from hypothesis import strategies
from hypothesis_geometry import planar

from tests.strategies import coordinates_strategies
from tests.utils import (MultisegmentWithSegment, Point,
                         PolygonWithMultisegment, PolygonWithSegment, Segment,
                         Strategy, to_pairs, to_triplets)

segments_strategies = coordinates_strategies.map(planar.segments)
segments = coordinates_strategies.flatmap(planar.segments)
segments_pairs = segments_strategies.flatmap(to_pairs)
segments_triplets = segments_strategies.flatmap(to_triplets)


def points_to_nets(points: Strategy[Point]) -> Strategy[List[Segment]]:
    def to_net(points_list: List[Point]) -> List[Segment]:
        return [
            Segment(start, end) for start, end in combinations(points_list, 2)
        ]

    return (strategies.lists(points, min_size=2, max_size=8,
                             unique=True).map(to_net))


segments_lists = (
    (coordinates_strategies.map(planar.segments).flatmap(strategies.lists))
    | (coordinates_strategies.map(planar.points).flatmap(points_to_nets)))
Beispiel #4
0
from tests.strategies import (coordinates_strategies,
                              coordinates_to_ported_leaves,
                              coordinates_to_ported_trapezoids, to_pairs,
                              to_triplets)

trapezoids = coordinates_strategies.flatmap(coordinates_to_ported_trapezoids)
leaves = coordinates_strategies.flatmap(coordinates_to_ported_leaves)
leaves_strategies = coordinates_strategies.map(coordinates_to_ported_leaves)
leaves_pairs = leaves_strategies.flatmap(to_pairs)
leaves_triplets = leaves_strategies.flatmap(to_triplets)
Beispiel #5
0
from tests.strategies import (coordinates_strategies,
                              coordinates_to_multipolygons,
                              coordinates_to_points, coordinates_to_polygons,
                              invalid_multipolygons)
from tests.utils import (cleave_in_tuples, to_pairs, to_triplets)

multipolygons = coordinates_strategies.flatmap(coordinates_to_multipolygons)
polygons = coordinates_strategies.flatmap(coordinates_to_polygons)
invalid_multipolygons = invalid_multipolygons
multipolygons_strategies = (
    coordinates_strategies.map(coordinates_to_multipolygons))
multipolygons_pairs = multipolygons_strategies.flatmap(to_pairs)
multipolygons_triplets = multipolygons_strategies.flatmap(to_triplets)
multipolygons_with_points = (coordinates_strategies.flatmap(
    cleave_in_tuples(coordinates_to_multipolygons, coordinates_to_points)))
Beispiel #6
0
from tests.strategies import (coordinates_strategies, coordinates_to_points,
                              coordinates_to_segments, invalid_segments,
                              rational_coordinates_strategies)
from tests.utils import (cleave_in_tuples, to_pairs, to_triplets)

rational_segments = (
    rational_coordinates_strategies.flatmap(coordinates_to_segments))
segments = coordinates_strategies.flatmap(coordinates_to_segments)
invalid_segments = invalid_segments
segments_strategies = coordinates_strategies.map(coordinates_to_segments)
segments_with_points = (coordinates_strategies.flatmap(
    cleave_in_tuples(coordinates_to_segments, coordinates_to_points)))
segments_pairs = segments_strategies.flatmap(to_pairs)
segments_triplets = segments_strategies.flatmap(to_triplets)
Beispiel #7
0
from tests.strategies import (coordinates_strategies,
                              coordinates_to_ported_points_with_nodes_pairs,
                              coordinates_to_ported_x_nodes, to_pairs,
                              to_triplets)

points_with_nodes_pairs = coordinates_strategies.flatmap(
    coordinates_to_ported_points_with_nodes_pairs)
x_nodes = coordinates_strategies.flatmap(coordinates_to_ported_x_nodes)
x_nodes_strategies = coordinates_strategies.map(coordinates_to_ported_x_nodes)
x_nodes_pairs = x_nodes_strategies.flatmap(to_pairs)
x_nodes_triplets = x_nodes_strategies.flatmap(to_triplets)
Beispiel #8
0
        segment.start.translate(scale * (segment.start.x - segment.end.x),
                                scale * (segment.start.y - segment.end.y)),
        segment.end)


invalid_mixes = (
    shaped_geometries.flatmap(shaped_to_invalid_mix)
    | strategies.builds(Mix, empty_geometries | multipoints, empty_geometries,
                        empty_geometries)
    | strategies.builds(Mix, empty_geometries,
                        empty_geometries | linear_geometries, empty_geometries)
    | strategies.builds(Mix, empty_geometries, empty_geometries,
                        empty_geometries | shaped_geometries)
    | strategies.builds(Mix, invalid_multipoints, empty_geometries
                        | linear_geometries, shaped_geometries)
    | strategies.builds(Mix, invalid_multipoints, linear_geometries,
                        empty_geometries | shaped_geometries)
    | strategies.builds(Mix, empty_geometries | multipoints,
                        invalid_linear_geometries, shaped_geometries)
    | strategies.builds(Mix, multipoints, invalid_linear_geometries,
                        empty_geometries | shaped_geometries)
    | strategies.builds(Mix, multipoints, empty_geometries | linear_geometries,
                        invalid_shaped_geometries)
    | strategies.builds(Mix, empty_geometries | multipoints, linear_geometries,
                        invalid_shaped_geometries))
mixes_with_points = (coordinates_strategies.flatmap(
    cleave_in_tuples(coordinates_to_mixes, coordinates_to_points)))
mixes_strategies = coordinates_strategies.map(coordinates_to_mixes)
mixes_pairs = mixes_strategies.flatmap(to_pairs)
mixes_triplets = mixes_strategies.flatmap(to_triplets)
Beispiel #9
0
from tests.strategies import (coordinates_strategies, coordinates_to_points,
                              coordinates_to_polygons, invalid_polygons,
                              rational_coordinates_strategies)
from tests.utils import (cleave_in_tuples, to_pairs, to_triplets)

rational_polygons = (
    rational_coordinates_strategies.flatmap(coordinates_to_polygons))
polygons = coordinates_strategies.flatmap(coordinates_to_polygons)
invalid_polygons = invalid_polygons
polygons_strategies = coordinates_strategies.map(coordinates_to_polygons)
polygons_pairs = polygons_strategies.flatmap(to_pairs)
polygons_triplets = polygons_strategies.flatmap(to_triplets)
polygons_with_points = (coordinates_strategies.flatmap(
    cleave_in_tuples(coordinates_to_polygons, coordinates_to_points)))
Beispiel #10
0
from tests.strategies import (coordinates_strategies,
                              coordinates_to_multipoints,
                              coordinates_to_points, invalid_multipoints)
from tests.utils import (cleave_in_tuples, to_pairs, to_triplets)

multipoints = coordinates_strategies.flatmap(coordinates_to_multipoints)
invalid_multipoints = invalid_multipoints
multipoints_with_points = (coordinates_strategies.flatmap(
    cleave_in_tuples(coordinates_to_multipoints, coordinates_to_points)))
multipoints_strategies = coordinates_strategies.map(coordinates_to_multipoints)
multipoints_pairs = multipoints_strategies.flatmap(to_pairs)
multipoints_triplets = multipoints_strategies.flatmap(to_triplets)
Beispiel #11
0
from typing import Tuple

from hypothesis import strategies

from seidel.bounding_box import BoundingBox
from seidel.hints import Coordinate
from seidel.point import Point
from tests.strategies import (coordinates_strategies,
                              coordinates_to_ported_points, to_pairs)
from tests.utils import Strategy

booleans = strategies.booleans()
points_pairs = (
    coordinates_strategies.map(coordinates_to_ported_points).flatmap(to_pairs))


def coordinates_to_bounding_boxes(
        coordinates: Strategy[Coordinate]) -> Strategy[BoundingBox]:
    def to_bounding_box(empty: bool, first_x: Coordinate, first_y: Coordinate,
                        second_x: Coordinate,
                        second_y: Coordinate) -> BoundingBox:
        left_x, right_x = sorted((first_x, second_x))
        lower_y, upper_y = sorted((first_y, second_y))
        return BoundingBox(empty, Point(left_x, lower_y),
                           Point(right_x, upper_y))

    return strategies.builds(to_bounding_box, booleans, coordinates,
                             coordinates, coordinates, coordinates)


bounding_boxes = coordinates_strategies.flatmap(coordinates_to_bounding_boxes)
Beispiel #12
0
from typing import Tuple

from hypothesis import strategies

from seidel.edge import Edge
from seidel.hints import Coordinate
from seidel.point import Point
from tests.strategies import (coordinates_strategies,
                              coordinates_to_ported_edges,
                              coordinates_to_ported_points,
                              coordinates_to_sorted_ported_points_pairs,
                              to_pairs, to_triplets)
from tests.utils import Strategy

sorted_points_pairs = (
    coordinates_strategies.flatmap(coordinates_to_sorted_ported_points_pairs))
edges = coordinates_strategies.flatmap(coordinates_to_ported_edges)


def coordinates_to_edges_with_points(
        coordinates: Strategy[Coordinate]) -> Strategy[Tuple[Edge, Point]]:
    return strategies.tuples(coordinates_to_ported_edges(coordinates),
                             coordinates_to_ported_points(coordinates))


edges_with_points = (
    coordinates_strategies.flatmap(coordinates_to_edges_with_points))
edges_strategies = coordinates_strategies.map(coordinates_to_ported_edges)
edges_pairs = edges_strategies.flatmap(to_pairs)
edges_triplets = edges_strategies.flatmap(to_triplets)
Beispiel #13
0
from typing import Tuple

from hypothesis import strategies

from gon.base import (Contour, Point)
from gon.hints import Scalar
from tests.strategies import (coordinates_strategies, coordinates_to_contours,
                              coordinates_to_points, invalid_contours,
                              to_non_zero_coordinates, to_zero_coordinates)
from tests.utils import (Strategy, cleave_in_tuples, to_pairs, to_triplets)

contours = coordinates_strategies.flatmap(coordinates_to_contours)


def coordinates_to_contours_with_points(
        coordinates: Strategy[Scalar]) -> Strategy[Tuple[Contour, Point]]:
    return strategies.tuples(coordinates_to_contours(coordinates),
                             coordinates_to_points(coordinates))


contours_with_points = (
    coordinates_strategies.flatmap(coordinates_to_contours_with_points))
invalid_contours = invalid_contours
contours_with_zero_non_zero_coordinates = coordinates_strategies.flatmap(
    cleave_in_tuples(coordinates_to_contours, to_zero_coordinates,
                     to_non_zero_coordinates))
contours_strategies = coordinates_strategies.map(coordinates_to_contours)
contours_pairs = contours_strategies.flatmap(to_pairs)
contours_triplets = contours_strategies.flatmap(to_triplets)
Beispiel #14
0
                         Strategy,
                         cleave_in_tuples,
                         left_scale_segment,
                         right_scale_segment,
                         sub_lists,
                         to_multipolygon_edges,
                         to_pairs,
                         to_polygon_edges,
                         to_triplets)

points = coordinates_strategies.flatmap(planar.points)
segments = coordinates_strategies.flatmap(planar.segments)
segments_with_points = (coordinates_strategies
                        .flatmap(cleave_in_tuples(planar.segments,
                                                  planar.points)))
segments_strategies = coordinates_strategies.map(planar.segments)
segments_pairs = segments_strategies.flatmap(to_pairs)
multisegments = coordinates_strategies.flatmap(planar.multisegments)
multisegments_with_points = (coordinates_strategies
                             .flatmap(cleave_in_tuples(planar.multisegments,
                                                       planar.points)))
multisegments_with_segments = (coordinates_strategies
                               .flatmap(cleave_in_tuples(planar.multisegments,
                                                         planar.segments)))
to_size_three_or_more_multisegments = partial(planar.multisegments,
                                              min_size=3)
size_three_or_more_multisegments_with_segments = (
    (coordinates_strategies
     .flatmap(cleave_in_tuples(to_size_three_or_more_multisegments,
                               planar.segments))))