示例#1
0
    def test_inequality(self):
        a = Vector2(1, 2)
        b = Vector2(3, 2)
        c = Vector2(1, 4)

        self.assertTrue(a != b)
        self.assertTrue(a != c)
示例#2
0
    def test_rotate(self):
        a = Vector2(6, 2)

        self.assertEqual(a.rotate(R0), a)
        self.assertEqual(a.rotate(R90), Vector2(2, -6))
        self.assertEqual(a.rotate(R180), Vector2(-6, -2))
        self.assertEqual(a.rotate(R270), Vector2(-2, 6))
示例#3
0
文件: svg.py 项目: bwhmather/pcdl
    def __init__(self, src: Coordinate2, tgt: Coordinate2) -> None:
        if not isinstance(src, Coordinate2):
            raise TypeError()

        if not isinstance(tgt, Coordinate2):
            raise TypeError()

        direction = {
            Vector2(1, 0): RIGHT,
            Vector2(0, -1): DOWN,
            Vector2(-1, 0): LEFT,
            Vector2(0, 1): UP,
        }.get(tgt - src)

        if direction is None:
            raise ValueError("Source and target are not adjacent")

        self.src = src
        self.tgt = tgt
        self.direction = direction
示例#4
0
    def test_repeat_rotate(self):
        a = Vector2(5, 7)

        self.assertEqual(
            a.rotate(R90).rotate(R90).rotate(R90).rotate(R90),
            a,
        )
        self.assertEqual(
            a.rotate(R270).rotate(R270).rotate(R270).rotate(R270),
            a,
        )
示例#5
0
    def test_subtract_from_vector(self):
        c = Coordinate2(1, 2)
        v = Vector2(3, 5)

        with self.assertRaises(TypeError):
            v - c
示例#6
0
    def test_subtract_vector(self):
        c = Coordinate2(1, 2)
        v = Vector2(3, 5)

        self.assertEqual(c - v, Coordinate2(-2, -3))
示例#7
0
    def test_subtract_coordinate(self):
        a = Coordinate2(1, 2)
        b = Coordinate2(3, 5)

        self.assertEqual(b - a, Vector2(2, 3))
示例#8
0
    def test_add_vector(self):
        a = Coordinate2(100, 50)
        b = Vector2(1, 1)

        self.assertEqual(a + b, Coordinate2(101, 51))
        self.assertEqual(b + a, Coordinate2(101, 51))
示例#9
0
    def test_hash(self):
        a = Vector2(1, 2)
        b = Vector2(1, 2)

        self.assertTrue(hash(a) == hash(b))
示例#10
0
文件: svg.py 项目: bwhmather/pcdl
def _turn_left(half_edge: _HalfEdge) -> _HalfEdge:
    return _HalfEdge(
        half_edge.tgt,
        half_edge.tgt + Vector2.unit_vector(half_edge.direction - R90),
    )
示例#11
0
    def test_equality(self):
        a = Vector2(1, 2)
        b = Vector2(1, 2)

        self.assertTrue(a == b)
示例#12
0
 def test_right_scalar_product(self):
     self.assertEqual(2 * Vector2(2, 3), Vector2(4, 6))
示例#13
0
文件: svg.py 项目: bwhmather/pcdl
def _turn_ahead(half_edge: _HalfEdge) -> _HalfEdge:
    return _HalfEdge(
        half_edge.tgt,
        half_edge.tgt + Vector2.unit_vector(half_edge.direction),
    )
示例#14
0
 def test_left_scalar_product(self):
     self.assertEqual(Vector2(2, 3) * 2, Vector2(4, 6))
示例#15
0
    def test_dot_product(self):
        a = Vector2(2, 3)
        b = Vector2(4, 5)

        self.assertEqual(a * b, Vector2(8, 15))
示例#16
0
    def test_subtract_vector(self):
        a = Vector2(3, 5)
        b = Vector2(7, 11)

        self.assertEqual(b - a, Vector2(4, 6))
示例#17
0
    def test_add_vector(self):
        a = Vector2(1, 2)
        b = Vector2(3, 5)

        self.assertEqual(a + b, Vector2(4, 7))
示例#18
0
 def test_negate(self):
     self.assertEqual(-Vector2(1, 3), Vector2(-1, -3))