def test_angle_from(self) -> None: v1 = k2d.Vector(-2.0, -2.0) v2 = k2d.Vector(0.0, 2.0) assert k2d.is_close(v2.angle_from(v1), k2d.PI * 6 / 8, 1e-3) v3 = k2d.Vector.zeros() v4 = k2d.Vector.zeros() assert k2d.is_close(v3.angle_from(v4), -0.0, 1e-3)
def test_angle(self) -> None: v1 = k2d.Vector(2.0, 0.0) assert k2d.is_close(v1.angle, 0.0, 1e-3) v2 = k2d.Vector(0.0, 2.0) assert k2d.is_close(v2.angle, k2d.PI / 2, 1e-3) v3 = k2d.Vector(-2.0, -2.0) assert k2d.is_close(v3.angle, -k2d.PI * 6 / 8, 1e-3) v4 = k2d.Vector.zeros() assert k2d.is_close(v4.angle, 0.0, 1e-3)
def is_close_to(self, other: "Vector", epsilon: typing.Optional[float] = None) -> bool: return k2d.is_close(self.x, other.x, epsilon) and k2d.is_close( self.y, other.y, epsilon)
def test_abs(self) -> None: v = k2d.Vector(3.33, 4.44) assert k2d.is_close(abs(v), 5.55)
def test_dot(self) -> None: v1 = k2d.Vector(2.0, 3.0) v2 = k2d.Vector(3.0, 2.0) assert k2d.is_close(v1.dot(v2), 12.0)
def test_is_close(self) -> None: assert k2d.is_close(1.0, 1.0 + k2d.EPSILON / 2) assert not k2d.is_close(1.0, 1.0 + k2d.EPSILON * 2) assert k2d.is_close(1.0, 1.1, 0.2) assert not k2d.is_close(1.0, 1.3, 0.2)
def test_angle_diff(self) -> None: assert k2d.is_close(k2d.angle_diff(2.22, 1.11), 1.11) assert k2d.is_close(k2d.angle_diff(1.11, 2.22), -1.11) assert k2d.is_close(k2d.angle_diff(0.11, 2 * k2d.PI - 0.11), 0.22) assert k2d.is_close(k2d.angle_diff(2 * k2d.PI - 0.11, 0.11), -0.22)
def test_angle_cap(self) -> None: assert k2d.is_close(k2d.angle_cap(2.22), 2.22) assert k2d.is_close(k2d.angle_cap(4.44), -2 * k2d.PI + 4.44)
def test_deg_from_rad(self) -> None: assert k2d.is_close(-k2d.PI, k2d.rad_from_deg(-180)) assert k2d.is_close(k2d.PI / 2, k2d.rad_from_deg(90))
def test_rad_from_deg(self) -> None: assert k2d.is_close(k2d.rad_from_deg(180), k2d.PI) assert k2d.is_close(k2d.rad_from_deg(-90), -k2d.PI / 2)