예제 #1
0
def test_on_poly_edge():
    # type: () -> None
    poly = Polygon3D([(0, 4, 0), (0, 0, 0), (4, 0, 0), (4, 4, 0)])
    edge1 = Segment(Vector3D(0, 1, 0), Vector3D(0, 2, 0))
    edge2 = Segment(Vector3D(1, 1, 0), Vector3D(1, 2, 0))
    assert edge1._on_poly_edge(poly)
    assert not edge2._on_poly_edge(poly)
예제 #2
0
def test_point():
    # type: () -> None
    pt1 = Vector3D(0.0, 0.0, 0.0)
    pt2 = Vector3D(1.0, 1.0, 1.0)

    assert pt2 - pt1 == pt2
    assert pt1 - pt2 == Vector3D(-1, -1, -1)

    assert pt2 + pt2 == Vector3D(2, 2, 2)
예제 #3
0
def test_surface_is_clockwise():
    # type: () -> None
    """Test if a surface is clockwise as seen from a given point.
    """
    poly = Polygon3D(
        reversed(
            [
                Vector3D(0.0, 0.0, 0.0),
                Vector3D(1.0, 0.0, 0.0),
                Vector3D(1.0, 1.0, 0.0),
                Vector3D(0.0, 1.0, 0.0),
            ]
        )
    )
    poly_inv = Polygon3D(
        [
            Vector3D(0.0, 0.0, 0.0),
            Vector3D(1.0, 0.0, 0.0),
            Vector3D(1.0, 1.0, 0.0),
            Vector3D(0.0, 1.0, 0.0),
        ]
    )

    pt = Vector3D(0.5, 0.5, 1.0)  # point above the plane

    assert poly.is_clockwise(pt)
    assert not poly_inv.is_clockwise(pt)
예제 #4
0
        def avg(zone: eppy.bunch_subclass.EpBunch):
            """calculate the zone centroid coordinates"""
            x_, y_, z_, dem = 0, 0, 0, 0
            from geomeppy.geom.polygons import Polygon3D, Vector3D
            from geomeppy.recipes import translate_coords

            ggr = zone.theidf.idfobjects["GLOBALGEOMETRYRULES"][0]

            for surface in zone.zonesurfaces:
                if surface.key.upper() in ["INTERNALMASS", "WINDOWSHADINGCONTROL"]:
                    pass
                else:
                    dem += 1  # Counter for average calc at return
                    if ggr.Coordinate_System.lower() == "relative":
                        # add zone origin to surface coordinates and create
                        # Polygon3D from updated coords.
                        zone = zone.theidf.getobject("ZONE", surface.Zone_Name)
                        poly3d = Polygon3D(surface.coords)
                        origin = (zone.X_Origin, zone.Y_Origin, zone.Z_Origin)
                        coords = translate_coords(poly3d, Vector3D(*origin))
                        poly3d = Polygon3D(coords)
                    else:
                        # Polygon3D from surface coords
                        poly3d = Polygon3D(surface.coords)
                    x, y, z = poly3d.centroid
                    x_ += x
                    y_ += y
                    z_ += z
            return x_ / dem, y_ / dem, z_ / dem
예제 #5
0
def test_add_polygon_to_polygon():
    # type: () -> None
    # 2D
    poly1 = Polygon2D([(1, 0), (0, 0), (0, 1)])
    poly2 = Polygon2D([(1, 0), (1, 0), (1, 0)])
    expected = Polygon2D([(2, 0), (1, 0), (1, 1)])
    result = poly1 + poly2
    assert almostequal(result, expected)

    vector = Vector2D(1, 0)
    result = poly1 + vector
    assert almostequal(result, expected)

    vector = Vector3D(1, 0, 0)
    try:
        result = poly1 + vector  # should fail
        assert False
    except ValueError:
        pass
    # 3D
    poly1 = Polygon2D([(1, 0, 1), (0, 0, 1), (0, 1, 1)])
    poly2 = Polygon2D([(1, 0, 1), (1, 0, 1), (1, 0, 1)])
    expected = Polygon2D([(2, 0, 2), (1, 0, 2), (1, 1, 2)])
    result = poly1 + poly2
    assert almostequal(result, expected)

    vector = Vector3D(1, 0, 1)
    result = poly1 + vector
    assert almostequal(result, expected)

    vector = Vector2D(1, 0)
    try:
        result = poly1 + vector  # should fail
        assert False
    except ValueError:
        pass
예제 #6
0
def test_polygon3d_attributes():
    # type: () -> None
    poly3d = Polygon3D([(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)])
    assert len(poly3d) == 4
    assert poly3d.xs == [0, 0, 1, 1]
    assert poly3d.ys == [0, 1, 1, 0]
    assert poly3d.zs == [0, 1, 1, 0]
    assert poly3d.vertices_list == [(0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 0)]
    assert poly3d.vertices == [Vector3D(*v) for v in poly3d]
    assert poly3d.distance == 0
    assert poly3d.is_horizontal is False
    assert almostequal(poly3d.normal_vector, [0.0, 0.70710678, -0.70710678])
    poly3d_2 = Polygon3D([(0, 1, 1), (0, 2, 2), (1, 2, 2), (1, 1, 1)])
    assert almostequal(poly3d_2.normal_vector, [0.0, 0.70710678, -0.70710678])
    assert poly3d_2.projection_axis == 1
    result = poly3d.is_coplanar(poly3d_2)
    assert result
예제 #7
0
def test_closest():
    # type: () -> None
    pt = Vector3D(0, 0, 0)
    poly = Polygon3D([(1, 1, 1), (2, 2, 3), (3, 4, 5)])
    assert pt.closest(poly) == Vector3D(1, 1, 1)
예제 #8
0
def test_normalize():
    # type: () -> None
    v = Vector3D(1, 1, 1)
    v.normalize()
    for i in v:
        assert almostequal(i, 0.57735026)
예제 #9
0
def test_set_length():
    # type: () -> None
    v = Vector3D(1, 1, 1)
    v.set_length(1)
    for i in v:
        assert almostequal(i, 0.57735026)
예제 #10
0
def test_invert():
    # type: () -> None
    v = Vector3D(1, 2, 3)
    assert v.invert() == Vector3D(-1, -2, -3)
예제 #11
0
def test_surface_normal():
    # type: () -> None
    poly = Polygon3D([
        Vector3D(0.0, 0.0, 0.0),
        Vector3D(1.0, 0.0, 0.0),
        Vector3D(1.0, 1.0, 0.0),
        Vector3D(0.0, 1.0, 0.0),
    ])
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        1.0]  # for a horizontal surface

    poly = Polygon3D(
        reversed([
            Vector3D(0.0, 0.0, 0.0),
            Vector3D(1.0, 0.0, 0.0),
            Vector3D(1.0, 1.0, 0.0),
            Vector3D(0.0, 1.0, 0.0),
        ]))
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        -1.0]  # for a horizontal surface

    poly = Polygon3D([
        Vector3D(0.0, 0.0, 0.0),
        Vector3D(2.0, 1.0, 0.0),
        Vector3D(4.0, 0.0, 0.0),
        Vector3D(4.0, 3.0, 0.0),
        Vector3D(2.0, 2.0, 0.0),
        Vector3D(0.0, 3.0, 0.0),
    ])
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        1.0]  # for a horizontal surface

    poly = Polygon3D(
        reversed([
            Vector3D(0.0, 0.0, 0.0),
            Vector3D(2.0, 1.0, 0.0),
            Vector3D(4.0, 0.0, 0.0),
            Vector3D(4.0, 3.0, 0.0),
            Vector3D(2.0, 2.0, 0.0),
            Vector3D(0.0, 3.0, 0.0),
        ]))
    assert list(poly.normal_vector) == [0.0, 0.0,
                                        -1.0]  # for a horizontal surface

    poly = Polygon3D([[1., 1.1, 0.5], [1., 1.1, 0.], [1., 2.1, 0.],
                      [1., 2.1, 0.5]])
    assert list(poly.normal_vector) == [1.0, 0.0,
                                        0.0]  # for a horizontal surface
예제 #12
0
def test_polygon_index():
    # type: () -> None
    poly = Polygon3D([(0, 4, 0), (0, 0, 0), (4, 0, 0), (4, 4, 0)])
    assert poly[1] == Vector3D(0, 0, 0)
    assert poly.index(Vector3D(0, 0, 0)) == 1