Esempio n. 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()
Esempio n. 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
Esempio n. 3
0
 def _get_colour(self):
     colour = self.colours.GetValue()
     return {
         "blue": blue(self.field),
         "red": red(self.field),
         "green": green(self.field)
     }[colour]
Esempio n. 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
Esempio n. 5
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()
Esempio n. 6
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_)
Esempio n. 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_)
Esempio n. 8
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()
Esempio n. 9
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()
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
0
 def _get_colour(self):
     colour = self.colours.GetValue()
     return {"blue": blue(self.field),
             "red": red(self.field),
             "green": green(self.field)}[colour]