示例#1
0
def getUnitNormalVector(p1, p2):
    (x1, y1), (x2, y2) = p1, p2
    dx, dy = float(x2 - x1), float(y2 - y1)

    unitNormal = Vec2D(-dy, dx)
    unitNormal.normalize()
    return unitNormal
示例#2
0
def test_vec2_nan():
    nan = float("nan")
    inf = float("inf")
    assert not Vec2F(0, 0).is_nan()
    assert not Vec2F(1, 0).is_nan()
    assert Vec2F(nan, 0).is_nan()
    assert Vec2F(0, nan).is_nan()
    assert Vec2F(nan, nan).is_nan()
    assert Vec2F(-nan, 0).is_nan()
    assert Vec2F(-nan, nan).is_nan()
    assert Vec2F(inf, nan).is_nan()
    assert not Vec2F(inf, 0).is_nan()
    assert not Vec2F(inf, inf).is_nan()
    assert not Vec2F(-inf, 0).is_nan()

    assert not Vec2D(0, 0).is_nan()
    assert not Vec2D(1, 0).is_nan()
    assert Vec2D(nan, 0).is_nan()
    assert Vec2D(0, nan).is_nan()
    assert Vec2D(nan, nan).is_nan()
    assert Vec2D(-nan, 0).is_nan()
    assert Vec2D(-nan, nan).is_nan()
    assert Vec2D(inf, nan).is_nan()
    assert not Vec2D(inf, 0).is_nan()
    assert not Vec2D(inf, inf).is_nan()
    assert not Vec2D(-inf, 0).is_nan()
示例#3
0
def test_vec2_str():
    assert str(Vec2F(2, 3)) == "LVector2f(2, 3)"
    assert str(Vec2D(2, 3)) == "LVector2d(2, 3)"