<commit_before># Purpose: test ConstructionRay
# Created: 28.02.2010
# License: MIT License
import pytest
import math
from ezdxf.math.line import ConstructionRay, ParallelRaysError
from ezdxf.math import Vector

HALF_PI = math.pi / 2.


class TestConstructionRay:
    def test_init_with_angle(self):
        point = (10, 10)
        ray = ConstructionRay(point, angle=0)
        ray_normal = ray.orthogonal(point)
        assert ray_normal._is_vertical is True
        ray = ConstructionRay(point, angle=-HALF_PI)
        assert ray._is_horizontal is False
        assert ray._is_vertical is True

    def test_Ray2D_get_x_y(self):
        ray1 = ConstructionRay((10, 1), (20, 10))
        y = ray1.yof(15)
        assert math.isclose(y, 5.5)
        assert math.isclose(ray1.xof(y), 15.)

    def test_ray2d_intersect(self):
        ray1 = ConstructionRay((10, 1), (20, 10))
        ray2 = ConstructionRay((17, -7), (-10, 3))

        point = ray1.intersect(ray2)
        assert point.isclose(Vector(5.7434, -2.8309), abs_tol=1e-4)
        assert ray1.is_parallel(ray2) is False

    def test_ray2d_parallel(self):
        ray1 = ConstructionRay((17, -8), (-10, 2))
        ray2 = ConstructionRay((-10, 3), (17, -7))
        ray3 = ConstructionRay((-10, 4), (17, -6))
        assert ray2.is_parallel(ray3) is True
        assert ray1.is_parallel(ray3) is True
        with pytest.raises(ParallelRaysError):
            _ = ray2.intersect(ray3)

    def test_ray2d_intersect_with_vertical(self):
        ray1 = ConstructionRay((10, 1), (10, -7))
        ray2 = ConstructionRay((-10, 3), (17, -7))
        point = ray1.intersect(ray2)
        assert point.isclose(Vector(10., -4.4074), abs_tol=1e-4)
        with pytest.raises(ArithmeticError):
            _ = ray1.yof(1)

    def test_ray2d_parallel_vertical(self):
        ray1 = ConstructionRay((10, 1), (10, -7))
        ray2 = ConstructionRay((11, 0), angle=HALF_PI)<commit_msg>Update test_641_construction_ray.py<commit_after># Purpose: test ConstructionRay
# Created: 28.02.2010
# License: MIT License
import pytest
import math
from ezdxf.math.line import ConstructionRay, ParallelRaysError
from ezdxf.math import Vector

HALF_PI = math.pi / 2.


class TestConstructionRay:
    def test_init_with_angle(self):
        point = (10, 10)
        ray = ConstructionRay(point, angle=0)
        ray_normal = ray.orthogonal(point)
        assert ray_normal._is_vertical is True
        ray = ConstructionRay(point, angle=-HALF_PI)
        assert ray._is_horizontal is False
        assert ray._is_vertical is True

    def test_Ray2D_get_x_y(self):
        ray1 = ConstructionRay((10, 1), (20, 10))
        y = ray1.yof(15)
        assert math.isclose(y, 5.5)
        assert math.isclose(ray1.xof(y), 15.)

    def test_ray2d_intersect(self):
        ray1 = ConstructionRay((10, 1), (20, 10))
        ray2 = ConstructionRay((17, -7), (-10, 3))

        point = ray1.intersect(ray2)
        assert point.isclose(Vector(5.7434, -2.8309), abs_tol=1e-4)
        assert ray1.is_parallel(ray2) is False

    def test_ray2d_parallel(self):
        ray1 = ConstructionRay((17, -8), (-10, 2))
        ray2 = ConstructionRay((-10, 3), (17, -7))
        ray3 = ConstructionRay((-10, 4), (17, -6))
        assert ray2.is_parallel(ray3) is True
        assert ray1.is_parallel(ray3) is True
        with pytest.raises(ParallelRaysError):
            _ = ray2.intersect(ray3)

    def test_ray2d_intersect_with_vertical(self):
        ray1 = ConstructionRay((10, 1), (10, -7))
        ray2 = ConstructionRay((-10, 3), (17, -7))
        point = ray1.intersect(ray2)
        assert point.x == 10
        assert point.isclose(Vector(10., -4.4074), abs_tol=1e-4)
        with pytest.raises(ArithmeticError):
            _ = ray1.yof(1)
            
    def test_ray2d_intersect_with_horizontal(self):
        ray1 = ConstructionRay((-10, 10), (10, 10))
        ray2 = ConstructionRay((-10, 20), (10, 0))
        point = ray1.intersect(ray2)
        assert point.y == 10
        assert point.isclose(Vector(0.0, 10.0), abs_tol=1e-4)
        with pytest.raises(ArithmeticError):
            _ = ray1.yof(1)
            
    def test_ray2d_intersect_with_vertical_and_horizontal(self):
        ray1 = ConstructionRay((-10, 10), (10, 10))
        ray2 = ConstructionRay((5, 0), (5, 20))
        point = ray1.intersect(ray2)
        assert point.y == 10
        assert point.x == 5
        assert point.isclose(Vector(5.0, 10.0), abs_tol=1e-4)
        with pytest.raises(ArithmeticError):
            _ = ray1.yof(1)

    def test_ray2d_parallel_vertical(self):
        ray1 = ConstructionRay((10, 1), (10, -7))
        ray2 = ConstructionRay((11, 0), angle=HALF_PI)
{'fraction_non_alphanumeric': 0.12699765608352867, 'fraction_numerical': 0.06989132750905604, 'mean_word_length': 2.650077760497667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5555943', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1623, 'n_words': 352}