Beispiel #1
0
    def add_midpoint(self, evt):
        p1 = self._get_point(self.points1)
        p2 = self._get_point(self.points2)

        if p1 and p2:
            line_segment = LineSegment(p1, p2)
            name = self.name.GetValue()
            mid = line_segment.midpoint(), name, "s", self.colours.GetValue()
            self.parent.object_panel.add_point(mid)
Beispiel #2
0
    def add_midpoint(self, evt):
        p1 = self._get_point(self.points1)
        p2 = self._get_point(self.points2)

        if p1 and p2:
            line_segment = LineSegment(p1, p2)
            name = self.name.GetValue()
            mid = line_segment.midpoint(), name, "s", self.colours.GetValue()
            self.parent.object_panel.add_point(mid)
Beispiel #3
0
    def add_quadrola(self, evt):
        k = self.k.GetValue()
        p1 = self._get_point(self.points1)
        p2 = self._get_point(self.points2)

        if p1 and p2:
            line_segment = LineSegment(p1, p2)
            name = self.name.GetValue()
            quadrola = line_segment.quadrola(k), name, "x", self.colours.GetValue()
            self.parent.object_panel.add_conic(quadrola)
Beispiel #4
0
    def add_quadrola(self, evt):
        k = self.k.GetValue()
        p1 = self._get_point(self.points1)
        p2 = self._get_point(self.points2)

        if p1 and p2:
            line_segment = LineSegment(p1, p2)
            name = self.name.GetValue()
            quadrola = line_segment.quadrola(
                k), name, "x", self.colours.GetValue()
            self.parent.object_panel.add_conic(quadrola)
Beispiel #5
0
def test_fuzz_init():
    N = 20
    for data in generate_fuzz_data(N, geoms=2, lines=2, points=2):
        g0, g1 = data.geoms
        l0, l1 = data.lines
        p0, p1 = data.points

        ls0 = LineSegment(p0, p1)
        ls1 = LineSegment(p0, p1)
        assert ls0 == ls1

        v0 = Vertex(l0, l1)
        v1 = Vertex(l1, l0)
        assert v0 == v1

        if g0 != g1:
            l0.geometry = p0.geometry = g0
            l1.geometry = p1.geometry = g1
            assert_raises(GeometryError, Vertex, l0, l1)
            assert_raises(GeometryError, PointLine, p0, l1)
            assert_raises(GeometryError, LineSegment, p0, p1)
Beispiel #6
0
def test_fuzz_midpoint():
    N = 20
    for data in generate_fuzz_data(N, points=2):
        X0, X1 = data.points
        l0 = LineSegment(X0, X1)
        l1 = LineSegment(X1, X0)
        if l0.line.null():
            assert l1.line.null()
            assert_raises(ValueError, l0.midpoint)
            assert_raises(ValueError, l1.midpoint)
            continue

        M0 = l0.midpoint()
        M1 = l1.midpoint()
        quadrance = LineSegment(X0, M0).quadrance()
        
        assert LineSegment(X0, M0).quadrance() == quadrance

        assert LineSegment(X1, M0).quadrance() == quadrance
        assert LineSegment(X0, M1).quadrance() == quadrance
        assert LineSegment(X1, M1).quadrance() == quadrance
Beispiel #7
0
def test_fuzz_quadrola():
    N = 20
    for data in generate_fuzz_data(N, line_segments=1, spreads=1):
        try:
            K = data.spreads[0]
            points = data.line_segments[0]

            quadrola = points.quadrola(K)

            try:
                point = quadrola._point_on()
            except ValueError:
                continue
            except ZeroDivisionError:
                continue

            assert quadrola.through(point)
            Q1 = LineSegment(point, points.point1).quadrance()
            Q2 = LineSegment(point, points.point2).quadrance()
            assert (Q1 + Q2 + K) * (Q1 + Q2 + K) - 2 * (Q1 * Q1 + Q2 * Q2 +
                                                        K * K) == 0

        except NullLineError:
            pass
Beispiel #8
0
def test_fuzz_midpoint():
    N = 20
    for data in generate_fuzz_data(N, points=2):
        X0, X1 = data.points
        l0 = LineSegment(X0, X1)
        l1 = LineSegment(X1, X0)
        if l0.line.null():
            assert l1.line.null()
            assert_raises(ValueError, l0.midpoint)
            assert_raises(ValueError, l1.midpoint)
            continue

        M0 = l0.midpoint()
        M1 = l1.midpoint()
        quadrance = LineSegment(X0, M0).quadrance()

        assert LineSegment(X0, M0).quadrance() == quadrance

        assert LineSegment(X1, M0).quadrance() == quadrance
        assert LineSegment(X0, M1).quadrance() == quadrance
        assert LineSegment(X1, M1).quadrance() == quadrance
Beispiel #9
0
def test_midpoint():
    f = FiniteField
    f.base = 11
    X0 = Point(f(0), f(0), blue(f))
    X1 = Point(f(2), f(2), blue(f))
    X2 = Point(f(10), f(0), blue(f))

    for (x0, x1) in [(X0, X1), (X1, X0), (X0, X2), (X2, X0), (X1, X2),
                     (X2, X1)]:
        m = LineSegment(x0, x1).midpoint()
        assert LineSegment(x0, m).quadrance() == LineSegment(x1, m).quadrance()
        m = LineSegment(x1, x0).midpoint()
        assert LineSegment(x0, m).quadrance() == LineSegment(x1, m).quadrance()

    X0 = Point(Rational(1), Rational(7), red(Rational))
    X1 = Point(Rational(3), Rational(2), red(Rational))
    X2 = Point(Rational(10), Rational(1), red(Rational))

    for (x0, x1) in [(X0, X1), (X1, X0), (X0, X2), (X2, X0), (X1, X2),
                     (X2, X1)]:
        m = LineSegment(x0, x1).midpoint()
        assert LineSegment(x0, m).quadrance() == LineSegment(x1, m).quadrance()
        m = LineSegment(x1, x0).midpoint()
        assert LineSegment(x0, m).quadrance() == LineSegment(x1, m).quadrance()

    X0 = Point(Rational(3), Rational(0), green(Rational))
    X1 = Point(Rational(2), Rational(5), green(Rational))
    X2 = Point(Rational(10), Rational(1), green(Rational))

    for (x0, x1) in [(X0, X1), (X1, X0), (X0, X2), (X2, X0), (X1, X2),
                     (X2, X1)]:
        m = LineSegment(x0, x1).midpoint()
        assert LineSegment(x0, m).quadrance() == LineSegment(x1, m).quadrance()
        m = LineSegment(x1, x0).midpoint()
        assert LineSegment(x0, m).quadrance() == LineSegment(x1, m).quadrance()
Beispiel #10
0
def test_quadrance():
    f = FiniteField
    f.base = 11

    p0 = Point(f(0), f(0))
    p0b = Point(f(0), f(0), blue(f))
    p0r = Point(f(0), f(0), red(f))
    p0g = Point(f(0), f(0), green(f))

    # FIXME: These should move to a LineSegment constructor test
    # FIXME: This test should move into some kind of test_line_segment
    assert_raises(GeometryError, LineSegment, p0, p0b)
    assert_raises(GeometryError, LineSegment, p0, p0r)
    assert_raises(GeometryError, LineSegment, p0, p0g)

    assert_raises(GeometryError, LineSegment, p0r, p0)
    assert_raises(GeometryError, LineSegment, p0r, p0b)
    assert_raises(GeometryError, LineSegment, p0r, p0g)

    assert_raises(GeometryError, LineSegment, p0b, p0)
    assert_raises(GeometryError, LineSegment, p0b, p0r)
    assert_raises(GeometryError, LineSegment, p0b, p0g)

    assert_raises(GeometryError, LineSegment, p0g, p0)
    assert_raises(GeometryError, LineSegment, p0g, p0r)
    assert_raises(GeometryError, LineSegment, p0g, p0b)

    p1 = Point(f(1), f(1))
    p1b = Point(f(1), f(1), blue(f))
    p1r = Point(f(1), f(1), red(f))
    p1g = Point(f(1), f(1), green(f))

    assert LineSegment(p1b, p0b).quadrance() == LineSegment(
        p0b, p1b).quadrance() == 2
    assert LineSegment(p1r, p0r).quadrance() == LineSegment(
        p0r, p1r).quadrance() == 0
    assert LineSegment(p1g, p0g).quadrance() == LineSegment(
        p0g, p1g).quadrance() == 2

    p1 = Point(f(0), f(1))
    p1b = Point(f(0), f(1), blue(f))
    p1r = Point(f(0), f(1), red(f))
    p1g = Point(f(0), f(1), green(f))

    assert LineSegment(p1b, p0b).quadrance() == LineSegment(
        p0b, p1b).quadrance() == 1
    assert LineSegment(p1r, p0r).quadrance() == LineSegment(
        p0r, p1r).quadrance() == -1
    assert LineSegment(p1g, p0g).quadrance() == LineSegment(
        p0g, p1g).quadrance() == 0
Beispiel #11
0
def random_linesegment(field, geometry):
    return LineSegment(random_point(field, geometry),
                       random_point(field, geometry))
Beispiel #12
0
from pygeom.core import Point
from pygeom.pairs import LineSegment, PointLine, Vertex

# Set up the field
f = FiniteField
f.base = 13

geometry = red(f)

# Create the points
A = Point(f(3), f(7), geometry)
B = Point(f(4), f(12), geometry)
C = Point(f(9), f(2), geometry)

# Create the lines of the triangle
AB = LineSegment(A, B)
AC = LineSegment(A, C)
BC = LineSegment(B, C)

# Create the altitudes
alt_a = PointLine(A, BC.line).altitude().line
alt_b = PointLine(B, AC.line).altitude().line
alt_c = PointLine(C, AB.line).altitude().line

# Calculate the points of intersection of the altitudes
O_ab = Vertex(alt_a, alt_b).point
O_bc = Vertex(alt_b, alt_c).point
O_ca = Vertex(alt_c, alt_a).point

# Check that the points are indeed equal
assert O_ab == O_bc == O_ca