Beispiel #1
0
def test_non_valid_holes_sizes(coordinates: Strategy[Scalar],
                               non_valid_sizes_pair: SizesPair) -> None:
    min_size, max_size = non_valid_sizes_pair

    with pytest.warns(HypothesisWarning) as warnings:
        polygons(coordinates, min_hole_size=min_size, max_hole_size=max_size)

    assert len(warnings) == 1
Beispiel #2
0
def test_invalid_holes_sizes(coordinates: Strategy[Scalar],
                             invalid_sizes_pair: SizesPair) -> None:
    min_hole_size, max_hole_size = invalid_sizes_pair

    with pytest.raises(ValueError):
        polygons(coordinates,
                 min_hole_size=min_hole_size,
                 max_hole_size=max_hole_size)
Beispiel #3
0
def coordinates_to_polygons(
        coordinates: st.SearchStrategy[Real]) -> st.SearchStrategy[Polygon]:
    return st.builds(
        Polygon.from_raw,
        planar.polygons(coordinates,
                        min_size=MIN_CONTOUR_SIZE,
                        max_size=MAX_CONTOUR_SIZE,
                        min_holes_size=MIN_HOLES_SIZE,
                        max_holes_size=MAX_HOLES_SIZE))
Beispiel #4
0
def test_basic(coordinates: Strategy[Scalar], sizes_pair: SizesPair,
               holes_sizes_pair: SizesPair,
               hole_sizes_pair: SizesPair) -> None:
    min_size, max_size = sizes_pair
    min_holes_size, max_holes_size = holes_sizes_pair
    min_hole_size, max_hole_size = hole_sizes_pair

    result = polygons(coordinates,
                      min_size=min_size,
                      max_size=max_size,
                      min_holes_size=min_holes_size,
                      max_holes_size=max_holes_size,
                      min_hole_size=min_hole_size,
                      max_hole_size=max_hole_size)

    assert isinstance(result, Strategy)
Beispiel #5
0
def test_properties(data: DataObject,
                    coordinates_limits_type_pair: Tuple[ScalarsLimitsType,
                                                        ScalarsLimitsType],
                    sizes_pair: SizesPair, holes_sizes_pair: SizesPair,
                    hole_sizes_pair: SizesPair) -> None:
    (x_coordinates_limits_type,
     y_coordinates_limits_type) = coordinates_limits_type_pair
    ((x_coordinates, (min_x_value, max_x_value)),
     x_type) = x_coordinates_limits_type
    ((y_coordinates, (min_y_value, max_y_value)),
     y_type) = y_coordinates_limits_type
    min_size, max_size = sizes_pair
    min_holes_size, max_holes_size = holes_sizes_pair
    min_hole_size, max_hole_size = hole_sizes_pair

    strategy = polygons(x_coordinates,
                        y_coordinates,
                        min_size=min_size,
                        max_size=max_size,
                        min_holes_size=min_holes_size,
                        max_holes_size=max_holes_size,
                        min_hole_size=min_hole_size,
                        max_hole_size=max_hole_size)

    result = data.draw(strategy)

    assert is_polygon(result)
    assert polygon_has_valid_sizes(result,
                                   min_size=min_size,
                                   max_size=max_size,
                                   min_holes_size=min_holes_size,
                                   max_holes_size=max_holes_size,
                                   min_hole_size=min_hole_size,
                                   max_hole_size=max_hole_size)
    assert polygon_has_coordinates_types(result, x_type=x_type, y_type=y_type)
    assert polygon_has_coordinates_in_range(result,
                                            min_x_value=min_x_value,
                                            max_x_value=max_x_value,
                                            min_y_value=min_y_value,
                                            max_y_value=max_y_value)
    assert is_polygon_strict(result)
    assert is_contour_non_self_intersecting(result.border)
    assert all(is_contour_non_self_intersecting(hole) for hole in result.holes)
    assert contours_do_not_cross_or_overlap(result.holes)
    assert is_contour_counterclockwise(result.border)
    assert all(not is_contour_counterclockwise(hole) for hole in result.holes)
Beispiel #6
0
from hypothesis import strategies
from hypothesis_geometry import planar

from tests.binding_tests.utils import (bound_fill_kinds, bound_polygon_kinds)
from tests.integration_tests.utils import (
    to_bound_with_ported_linear_rings_pair,
    to_bound_with_ported_multipolygons_pair,
    to_bound_with_ported_points_lists_pair, to_bound_with_ported_polygons_pair,
    to_bound_with_ported_wagyus_pair)
from tests.port_tests.utils import (ported_fill_kinds, ported_polygon_kinds)
from tests.strategies import coordinates

booleans = strategies.booleans()
wagyus_pairs = strategies.builds(to_bound_with_ported_wagyus_pair, booleans)
linear_rings_points_pairs = (
    planar.contours(coordinates).map(to_bound_with_ported_points_lists_pair))
linear_rings_pairs = (
    linear_rings_points_pairs.map(to_bound_with_ported_linear_rings_pair))
polygons_pairs = (
    planar.polygons(coordinates).map(to_bound_with_ported_polygons_pair))
polygon_kinds_pairs = strategies.sampled_from(
    list(zip(bound_polygon_kinds, ported_polygon_kinds)))
multipolygons_pairs = (planar.multipolygons(coordinates).map(
    to_bound_with_ported_multipolygons_pair))
fill_kinds_pairs = strategies.sampled_from(
    list(zip(bound_fill_kinds, ported_fill_kinds)))
Beispiel #7
0
from tests.port_tests.utils import (ported_polygon_kinds,
                                    to_ported_linear_rings_points,
                                    to_ported_polygon_linear_rings)
from tests.strategies import coordinates
from tests.utils import Strategy
from wagyu.enums import PolygonKind
from wagyu.linear_ring import LinearRing
from wagyu.local_minimum import LocalMinimumList

linear_rings_points = (
    planar.contours(coordinates).map(to_ported_linear_rings_points))
linear_rings = strategies.builds(LinearRing, linear_rings_points)
polygon_kinds = strategies.sampled_from(ported_polygon_kinds)
linear_rings_lists = (
    planar.polygons(coordinates).map(to_ported_polygon_linear_rings))
empty_local_minimum_lists = strategies.builds(LocalMinimumList)


def to_local_minimum_list(
    linear_rings_with_polygon_kinds: List[Tuple[LinearRing, PolygonKind]]
) -> LocalMinimumList:
    result = LocalMinimumList()
    for linear_ring, polygon_kind in linear_rings_with_polygon_kinds:
        result.add_linear_ring(linear_ring, polygon_kind)
    return result


def to_linear_rings_with_polygon_kinds(
    linear_rings: List[LinearRing]
) -> Strategy[List[Tuple[LinearRing, PolygonKind]]]:
Beispiel #8
0
def coordinates_to_polygons_with_multisegments(
        coordinates: Strategy[Scalar]) -> Strategy[PolygonWithMultisegment]:
    return strategies.tuples(planar.polygons(coordinates),
                             planar.multisegments(coordinates))
Beispiel #9
0
                                     MIN_COORDINATE, MIN_HOLES_SIZE)
from pode.utils import joined_constrained_delaunay_triangles

T = TypeVar('T')

TRIANGULAR_CONTOUR_SIZE = 3
RECTANGLE_CONTOUR_SIZE = 4
MIN_PARTITION_SIZE = 1

nonnegative_integers = st.integers(min_value=0)
fractions = st.fractions(MIN_COORDINATE, MAX_COORDINATE)
raw_fraction_contours = planar.contours(fractions)
fractions_contours = st.builds(Contour.from_raw, raw_fraction_contours)
fraction_triangles = st.builds(
    Polygon.from_raw,
    planar.polygons(fractions, max_size=TRIANGULAR_CONTOUR_SIZE))
convex_divisors = st.sampled_from(
    [constrained_delaunay_triangles, joined_constrained_delaunay_triangles])

coordinates_strategies_factories = {
    int: st.integers,
    Fraction: st.fractions,
    float: st.floats
}
coordinates_strategies = st.sampled_from([
    factory(MIN_COORDINATE, MAX_COORDINATE)
    for factory in coordinates_strategies_factories.values()
])


def coordinates_to_polygons(
Beispiel #10
0
def to_polygons_with_points(
        coordinates: Strategy[Scalar]) -> Strategy[Tuple[Polygon, Point]]:
    return strategies.tuples(planar.polygons(coordinates),
                             planar.points(coordinates))
Beispiel #11
0
def to_polygons_with_points(
        coordinates: Strategy[Coordinate]) -> Strategy[Tuple[Contour, Point]]:
    return strategies.tuples(planar.polygons(coordinates),
                             planar.points(coordinates))