def test_polar(self): r, t = Vec2(1, 1).polar() assert simeq(r, sqrt(2)) assert simeq(t, 45) r, t = Vec2(1, 1).polar_rad() assert simeq(r, sqrt(2)) assert simeq(t, pi / 4)
def test_rotated_keeps_norm(self, u): for t in range(5): Z1 = u.norm() Z2 = u.rotate(360 * t / 6).norm() assert simeq(Z1, Z2)
def test_rotations(self): v = Vec2(1, 0) assert v.rotate(90) == Vec2(0, 1) assert v.rotate_around(90, Vec2(1, 0)) == v assert simeq(v.rotate_rad(pi / 2), Vec2(0, 1)) assert simeq(v.rotate_around_rad(pi / 2, Vec2(1, 0)), v)
def test_vector_norm_defaults_to_euclidean(self): vec = self.base_cls(*(1 for _ in range(self.size))) assert simeq(vec.norm(), sqrt(self.size)) assert simeq(abs(vec), sqrt(self.size))
def test_conversion_to_normalized(self, unity): assert simeq(unity, unity.normalize())
def test_angle(self, unity): assert simeq(unity.angle_to(unity), 0) assert simeq(unity.angle_to(-unity), 180) assert simeq(unity.angle_to_rad(-unity), pi)
def test_distance(self, unity, null): assert simeq(unity.distance_to(unity), 0) assert simeq(unity.distance_to(null), 1) assert simeq(unity.distance_to(-unity), 2)
def test_middle(self, unity, null): assert simeq(unity.midpoint(null), null.midpoint(unity)) assert simeq(unity.midpoint(null), unity / 2)
def test_clamp_missing_interval(self, unity): assert simeq(unity.clamp(2, 3), 2 * unity) assert simeq(unity.clamp(0.1, 0.5), 0.5 * unity)
def test_clamp_to_value(self, unity): assert simeq(unity.with_length(2), 2 * unity) assert simeq(unity.with_length(0.5), 0.5 * unity)