Пример #1
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()
Пример #2
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
Пример #3
0
 def _get_colour(self):
     colour = self.colours.GetValue()
     return {
         "blue": blue(self.field),
         "red": red(self.field),
         "green": green(self.field)
     }[colour]
Пример #4
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
Пример #5
0
def test_repr():
    f = Rational
    blue_ = blue(Rational)
    red_ = red(Rational)
    green_ = green(Rational)

    print blue_, red_, green_
    print Point(f(1), f(2), None)
    print Point(f(1), f(2), blue_)
    print Line(f(1), f(2), f(3), None)
    print Line(f(1), f(2), f(3), blue_)
    print Conic(f(1), f(2), f(3), f(4), f(5), f(6), None)
    print Conic(f(1), f(2), f(3), f(4), f(5), f(6), blue_)
Пример #6
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()
Пример #7
0
def test_repr():
    f = Rational
    blue_ = blue(Rational)
    red_ = red(Rational)
    green_ = green(Rational)

    print blue_, red_, green_
    print Point(f(1), f(2), None)
    print Point(f(1), f(2), blue_)
    print Line(f(1), f(2), f(3), None)
    print Line(f(1), f(2), f(3), blue_)
    print Conic(f(1), f(2), f(3), f(4), f(5), f(6), None)
    print Conic(f(1), f(2), f(3), f(4), f(5), f(6), blue_)
Пример #8
0
def test_construct_quadrance():
    f = FiniteField
    f.base = 37
    geom = blue(f)
    line = Line(f(1), f(1), f(10), geom)
    point = Point(f(0), f(1), geom)

    pl = PointLine(point, line)
    X = pl.construct_quadrance(f(10))

    v = pl.construct_spread(f(1) / f(5))

    N = 20
    for data in generate_fuzz_data(N, pointlines=1, spreads=1):
        pl = data.pointlines[0]
        s = data.spreads[0]
        try:
            ls = pl.construct_quadrance(s)
        except ValueError:
            pass
Пример #9
0
def test_construct_quadrance():
    f = FiniteField
    f.base = 37
    geom = blue(f)
    line = Line(f(1), f(1), f(10), geom)
    point = Point(f(0), f(1), geom)

    pl = PointLine(point, line)
    X = pl.construct_quadrance(f(10))

    v = pl.construct_spread(f(1)/f(5))

    N = 20
    for data in generate_fuzz_data(N, pointlines=1, spreads=1):
        pl = data.pointlines[0]
        s = data.spreads[0]
        try:
            ls = pl.construct_quadrance(s)
        except ValueError:
            pass
Пример #10
0
def test_construct_spread():
    f = FiniteField
    f.base = 7
    geom = blue(f)
    line = Line(f(0), f(1), f(0), geom)
    point = Point(f(1), f(2), geom)

    pl = PointLine(point, line)
    v = pl.construct_spread(f(1) / f(5))

    N = 20
    for data in generate_fuzz_data(N, pointlines=1, spreads=1):
        pl = data.pointlines[0]
        s = data.spreads[0]
        if pl.line.null():
            assert_raises(NullLineError, pl.construct_spread, s)
        else:
            try:
                v = pl.construct_spread(s)
            except ValueError:
                pass
Пример #11
0
def test_construct_spread():
    f = FiniteField
    f.base = 7
    geom = blue(f)
    line = Line(f(0), f(1), f(0), geom)
    point = Point(f(1), f(2), geom)

    pl = PointLine(point, line)
    v = pl.construct_spread(f(1)/f(5))

    N = 20
    for data in generate_fuzz_data(N, pointlines=1, spreads=1):
        pl = data.pointlines[0]
        s = data.spreads[0]
        if pl.line.null():
            assert_raises(NullLineError, pl.construct_spread, s)
        else:
            try:
                v = pl.construct_spread(s)
            except ValueError:
                pass
Пример #12
0
def test_null():
    f = Rational
    blue_ = blue(Rational)
    red_ = red(Rational)
    green_ = green(Rational)

    p0 = Point(f(0), f(0))
    p0b = Point(f(0), f(0), blue_)
    p0r = Point(f(0), f(0), red_)
    p0g = Point(f(0), f(0), green_)

    assert_raises(GeometryError, p0.null)
    assert p0b.null()
    assert p0r.null()
    assert p0g.null()


    p1b = Point(f(1), f(1), blue_)
    p1r = Point(f(1), f(1), red_)
    p1g = Point(f(1), f(1), green_)
    
    assert not p1b.null()
    assert p1r.null()
    assert not p1g.null()

    p1b = Point(f(1), f(0), blue_)
    p1r = Point(f(1), f(0), red_)
    p1g = Point(f(1), f(0), green_)
    
    assert not p1b.null()
    assert not p1r.null()
    assert p1g.null()

    p1b = Point(f(0), f(1), blue_)
    p1r = Point(f(0), f(1), red_)
    p1g = Point(f(0), f(1), green_)
    
    assert not p1b.null()
    assert not p1r.null()
    assert p1g.null()
Пример #13
0
def test_null():
    f = Rational
    blue_ = blue(Rational)
    red_ = red(Rational)
    green_ = green(Rational)

    p0 = Point(f(0), f(0))
    p0b = Point(f(0), f(0), blue_)
    p0r = Point(f(0), f(0), red_)
    p0g = Point(f(0), f(0), green_)

    assert_raises(GeometryError, p0.null)
    assert p0b.null()
    assert p0r.null()
    assert p0g.null()

    p1b = Point(f(1), f(1), blue_)
    p1r = Point(f(1), f(1), red_)
    p1g = Point(f(1), f(1), green_)

    assert not p1b.null()
    assert p1r.null()
    assert not p1g.null()

    p1b = Point(f(1), f(0), blue_)
    p1r = Point(f(1), f(0), red_)
    p1g = Point(f(1), f(0), green_)

    assert not p1b.null()
    assert not p1r.null()
    assert p1g.null()

    p1b = Point(f(0), f(1), blue_)
    p1r = Point(f(0), f(1), red_)
    p1g = Point(f(0), f(1), green_)

    assert not p1b.null()
    assert not p1r.null()
    assert p1g.null()
Пример #14
0
def test_eq():
    f = Rational
    blue_ = blue(Rational)
    red_ = red(Rational)
    green_ = green(Rational)

    p0 = Point(f(0), f(0))
    p0b = Point(f(0), f(0), blue_)
    p0r = Point(f(0), f(0), red_)
    p0g = Point(f(0), f(0), green_)

    assert p0 == p0
    assert p0b == p0b
    assert p0r == p0r
    assert p0g == p0g
    
    assert p0 != p0b
    assert p0 != p0r
    assert p0 != p0g
    assert p0b != p0r
    assert p0b != p0g
    assert p0r != p0g

    p1 = Point(f(1), f(0))
    p1b = Point(f(1), f(0), blue_)
    p1r = Point(f(1), f(0), red_)
    p1g = Point(f(1), f(0), green_)

    assert p1b == p1b
    assert p1r == p1r
    assert p1g == p1g

    assert p0 != p1
    assert p0r != p1r
    assert p0g != p1g
    assert p0b != p1b
Пример #15
0
def test_eq():
    f = Rational
    blue_ = blue(Rational)
    red_ = red(Rational)
    green_ = green(Rational)

    p0 = Point(f(0), f(0))
    p0b = Point(f(0), f(0), blue_)
    p0r = Point(f(0), f(0), red_)
    p0g = Point(f(0), f(0), green_)

    assert p0 == p0
    assert p0b == p0b
    assert p0r == p0r
    assert p0g == p0g

    assert p0 != p0b
    assert p0 != p0r
    assert p0 != p0g
    assert p0b != p0r
    assert p0b != p0g
    assert p0r != p0g

    p1 = Point(f(1), f(0))
    p1b = Point(f(1), f(0), blue_)
    p1r = Point(f(1), f(0), red_)
    p1g = Point(f(1), f(0), green_)

    assert p1b == p1b
    assert p1r == p1r
    assert p1g == p1g

    assert p0 != p1
    assert p0r != p1r
    assert p0g != p1g
    assert p0b != p1b
Пример #16
0
        ax.yaxis.set_minor_formatter(ScalarFormatter())

        ax.set_xticks(range(0, 59), minor=True)
        ax.set_yticks(range(0, 59), minor=True)

        ax.set_xticks([x + 0.5 for x in range(0, 59)])
        ax.set_yticks([x + 0.5 for x in range(0, 59)])

        ax.grid(True)
        plt.figlegend(handles, labels, scatterpoints=1, loc=1)

        plt.show()


if __name__ == "__main__":
    fp = FinitePlot()

    f = FiniteField
    f.base = 59

    l1 = Line(f(1), f(2), f(3))
    l2 = Line(f(1), f(4), f(4))
    c1 = Conic(f(1), f(0), f(-1), f(0), f(0), f(4), blue(f))
    fp.add_object(l1, "foo", "s")
    fp.add_object(l2, "bar", "o")
    fp.add_object(c1, "baz", "x")

    print "====", c1.centre_quadrance()

    fp.plot()
Пример #17
0
 def _get_colour(self):
     colour = self.colours.GetValue()
     return {"blue": blue(self.field),
             "red": red(self.field),
             "green": green(self.field)}[colour]
Пример #18
0
        ax.yaxis.set_minor_formatter(ScalarFormatter())

        ax.set_xticks(range(0, 59), minor=True)
        ax.set_yticks(range(0, 59), minor=True)

        ax.set_xticks([x + 0.5 for x in range(0, 59)])
        ax.set_yticks([x + 0.5 for x in range(0, 59)])

        ax.grid(True)
        plt.figlegend(handles, labels, scatterpoints=1, loc=1)

        plt.show()


if __name__ == '__main__':
    fp = FinitePlot()

    f = FiniteField
    f.base = 59

    l1 = Line(f(1), f(2), f(3))
    l2 = Line(f(1), f(4), f(4))
    c1 = Conic(f(1), f(0), f(-1), f(0), f(0), f(4), blue(f))
    fp.add_object(l1, "foo", "s")
    fp.add_object(l2, "bar", "o")
    fp.add_object(c1, "baz", "x")

    print "====", c1.centre_quadrance()

    fp.plot()