Skip to content

Commit

Permalink
Complete 'point' module
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Mar 2, 2020
1 parent 88bed19 commit 514414c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
18 changes: 9 additions & 9 deletions bentley_ottmann/core/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
to_angle_kind,
to_orientation)
from .point import (RealPoint,
_is_real_point,
_to_rational_point,
_to_real_point,
_to_scalar_point)
is_real_point,
to_rational_point,
to_real_point,
to_scalar_point)

RealSegment = Tuple[RealPoint, RealPoint]

Expand Down Expand Up @@ -157,8 +157,8 @@ def find_intersections(left: Segment,
start, _ = left
start_x, _ = start
coordinate_type = type(start_x)
intersection_point = _to_scalar_point(intersection_point,
coordinate_type)
intersection_point = to_scalar_point(intersection_point,
coordinate_type)
return intersection_point,
else:
_, first_intersection_point, second_intersection_point, _ = sorted(
Expand Down Expand Up @@ -220,14 +220,14 @@ def find_intersection(left: RealSegment, right: RealSegment) -> Point:

def is_real_segment(segment: Segment) -> bool:
start, _ = segment
return _is_real_point(start)
return is_real_point(start)


def to_rational_segment(segment: Segment) -> Segment:
start, end = segment
return _to_rational_point(start), _to_rational_point(end)
return to_rational_point(start), to_rational_point(end)


def to_real_segment(segment: Segment) -> Segment:
start, end = segment
return _to_real_point(start), _to_real_point(end)
return to_real_point(start), to_real_point(end)
8 changes: 4 additions & 4 deletions bentley_ottmann/core/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
RealPoint = Tuple[Real, Real]


def _is_real_point(point: Point) -> bool:
def is_real_point(point: Point) -> bool:
x, y = point
return isinstance(x, Real)


def _to_real_point(point: Point) -> RealPoint:
def to_real_point(point: Point) -> RealPoint:
x, y = point
return float(x), float(y)


def _to_scalar_point(point: Point, coordinate_type: Type[Scalar]) -> Point:
def to_scalar_point(point: Point, coordinate_type: Type[Scalar]) -> Point:
x, y = point
return (coordinate_type(x.numerator) / x.denominator
if isinstance(x, Fraction)
Expand All @@ -29,6 +29,6 @@ def _to_scalar_point(point: Point, coordinate_type: Type[Scalar]) -> Point:
else coordinate_type(y))


def _to_rational_point(point: Point) -> Point:
def to_rational_point(point: Point) -> Point:
x, y = point
return Fraction(x), Fraction(y)
2 changes: 1 addition & 1 deletion tests/core_tests/linear_tests/test_find_intersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from hypothesis import given

from bentley_ottmann.core.linear import (find_intersections)
from bentley_ottmann.core.linear import find_intersections
from bentley_ottmann.hints import Segment
from tests.utils import (is_point,
reverse_segment)
Expand Down
3 changes: 1 addition & 2 deletions tests/planar_tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from tests.strategies import (points_strategies,
segments_strategies)

vertices_lists = (points_strategies
.flatmap(strategies.lists))
vertices_lists = points_strategies.flatmap(strategies.lists)
non_empty_vertices_lists = (points_strategies
.flatmap(partial(strategies.lists,
min_size=3)))
Expand Down
10 changes: 5 additions & 5 deletions tests/planar_tests/test_edges_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from bentley_ottmann.core.linear import (SegmentsRelationship,
find_intersections,
to_segments_relationship)
from bentley_ottmann.core.point import (_is_real_point,
_to_real_point)
from bentley_ottmann.core.point import (is_real_point,
to_real_point)
from bentley_ottmann.hints import Point
from bentley_ottmann.planar import (_vertices_to_edges,
edges_intersect)
Expand Down Expand Up @@ -39,9 +39,9 @@ def test_step(vertices: List[Point]) -> None:

first_vertex_real, rest_vertices_real = (
(first_vertex, rest_vertices)
if _is_real_point(first_vertex)
else (_to_real_point(first_vertex),
[_to_real_point(vertex) for vertex in rest_vertices]))
if is_real_point(first_vertex)
else (to_real_point(first_vertex),
[to_real_point(vertex) for vertex in rest_vertices]))
first_edge, last_edge = ((first_vertex_real, rest_vertices_real[0]),
(rest_vertices_real[-1], first_vertex_real))
rest_edges = _vertices_to_edges(rest_vertices_real)
Expand Down
2 changes: 1 addition & 1 deletion tests/planar_tests/test_segments_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from hypothesis import given

from bentley_ottmann.core.linear import (find_intersections)
from bentley_ottmann.core.linear import find_intersections
from bentley_ottmann.hints import Segment
from bentley_ottmann.planar import segments_intersect
from tests.utils import (reverse_segment,
Expand Down
4 changes: 2 additions & 2 deletions tests/planar_tests/test_segments_intersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from hypothesis import given

from bentley_ottmann.core.linear import (Segment,
find_intersections)
from bentley_ottmann.core.linear import find_intersections
from bentley_ottmann.hints import Segment
from bentley_ottmann.planar import segments_intersections
from tests.utils import is_point
from . import strategies
Expand Down

0 comments on commit 514414c

Please sign in to comment.