Example #1
0
 def chart_border2d(self):
     """Get a Polyline2D for the border of the plot."""
     base_pt = Point2D(self._base_point.x, self._base_point.y)
     width = self._container.max_point.x - self._container.min_point.x
     height = self._container.max_point.y - self._container.min_point.y
     pgon = Polygon2D.from_rectangle(base_pt, Vector2D(0, 1), width, height)
     return Polyline2D.from_polygon(pgon)
Example #2
0
 def chart_border(self):
     """Get a Polyline2D for the border of the plot."""
     width = self._x_dim * len(self._months_int)
     height = self._y_dim
     pgon = Polygon2D.from_rectangle(self._base_point, Vector2D(0, 1),
                                     width, height)
     return Polyline2D.from_polygon(pgon)
Example #3
0
def test_bounding_rectangle_angle_2d():
    """Test the bounding_rectangle methods with an axis_angle and 2D geometry."""
    pt1 = Point2D(-5, 0)
    pt2 = Point2D(0, -4)
    pt3 = Point2D(2, 2)
    polyface1 = Polygon2D.from_rectangle(pt1, Vector2D(0, 1), 2, 4)
    polyface2 = Polygon2D.from_rectangle(pt2, Vector2D(0, 1), 2, 4)
    polyface3 = Polygon2D.from_rectangle(pt3, Vector2D(0, 1), 2, 4)

    min_pt, max_pt = bounding_rectangle([polyface1, polyface2, polyface3], 45)
    assert min_pt.x == pytest.approx(1.45, rel=1e-2)
    assert min_pt.y == pytest.approx(-4.89, rel=1e-2)
    assert max_pt.x == pytest.approx(-1.62, rel=1e-2)
    assert max_pt.y == pytest.approx(9.47, rel=1e-2)

    x_dom, y_dom = bounding_rectangle_extents(
        [polyface1, polyface2, polyface3], 45)
    assert x_dom == pytest.approx(10.6103, rel=1e-2)
    assert y_dom == pytest.approx(10.1589, rel=1e-2)
Example #4
0
def rectangle_plan(width, length, floor_to_floor_height, perimeter_offset, story_count,
                   orientation_angle, outdoor_roof, ground_floor, units, tolerance,
                   output_file):
    """Create a model with a rectangular floor plan.

    Note that the resulting Rooms in the model won't have any windows or solved
    adjacencies. The edit commands should be used for this purpose.

    \b
    Args:
        width: Number for the width of the plan (in the X direction).
        length: Number for the length of the plan (in the Y direction).
        floor_to_floor_height: Number for the height of each floor of the model
            (in the Z direction).
    """
    try:
        # create the geometry of the rooms for the first floor
        tolerance = tolerance if tolerance is not None else UNITS_TOLERANCES[units]
        footprint = [Face3D.from_rectangle(width, length)]
        if perimeter_offset != 0:  # use the straight skeleton methods
            assert perimeter_offset > 0, 'perimeter_offset cannot be less than than 0.'
            try:
                footprint = []
                base = Polygon2D.from_rectangle(Point2D(), Vector2D(0, 1), width, length)
                sub_polys_perim, sub_polys_core = perimeter_core_subpolygons(
                    polygon=base, distance=perimeter_offset, tol=tolerance)
                for s_poly in sub_polys_perim + sub_polys_core:
                    sub_face = Face3D([Point3D(pt.x, pt.y, 0) for pt in s_poly])
                    footprint.append(sub_face)
            except RuntimeError:
                pass

        # create the honeybee rooms
        unique_id = str(uuid.uuid4())[:8]  # unique identifier for the model
        rm_ids = ['Room'] if len(footprint) == 1 else ['Front', 'Right', 'Back', 'Left']
        if len(footprint) == 5:
            rm_ids.append('Core')
        rooms = _rooms_from_footprint(
            footprint, rm_ids, unique_id, floor_to_floor_height, orientation_angle,
            story_count, outdoor_roof, ground_floor)

        # create the model object
        model_id = 'Rectangle_Plan_Model_{}'.format(unique_id)
        model = Model(model_id, rooms, units=units,
                      tolerance=tolerance, angle_tolerance=1)

        # write the model out to the file or stdout
        output_file.write(json.dumps(model.to_dict()))
    except Exception as e:
        _logger.exception('Rectangle plan model creation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
def test_polygon2d_init_from_rectangle():
    """Test the initialization of Polygon2D from_rectangle."""
    polygon = Polygon2D.from_rectangle(Point2D(0, 0), Vector2D(0, 1), 2, 2)

    assert isinstance(polygon.vertices, tuple)
    assert len(polygon.vertices) == 4
    for point in polygon.vertices:
        assert isinstance(point, Point2D)

    assert isinstance(polygon.segments, tuple)
    assert len(polygon.segments) == 4
    for seg in polygon.segments:
        assert isinstance(seg, LineSegment2D)
        assert seg.length == 2

    assert polygon.area == 4
    assert polygon.perimeter == 8
    assert not polygon.is_clockwise
    assert polygon.is_convex
    assert not polygon.is_self_intersecting
Example #6
0
def rectangle_plan(width, length, floor_to_floor_height, perimeter_offset,
                   story_count, orientation_angle, outdoor_roof, ground_floor,
                   units, tolerance, output_file):
    """Create a model with a rectangular floor plan.\n
    Note that the resulting Rooms in the model won't have any windows or solved
    adjacencies and the edit commands should be used for this purpose.\n
    \n
    Args:\n
        width: Number for the width of the plan (in the X direction).\n
        depth: Number for the depth of the plan (in the Y direction).\n
        floor_to_floor_height: Number for the height of each floor of the model
            (in the Z direction).
    """
    try:
        unique_id = str(uuid.uuid4())[:8]  # unique identifier for the rooms

        # create the geometry of the rooms for the first floor
        footprint = Face3D.from_rectangle(width, length)
        if perimeter_offset != 0:  # use the straight skeleton methods
            assert perimeter_offset > 0, 'perimeter_offset cannot be less than than 0.'
            try:
                footprint = []
                base = Polygon2D.from_rectangle(Point2D(), Vector2D(0, 1),
                                                width, length)
                sub_polys_perim, sub_polys_core = perimeter_core_subpolygons(
                    polygon=base, distance=perimeter_offset, tol=tolerance)
                for s_poly in sub_polys_perim + sub_polys_core:
                    sub_face = Face3D(
                        [Point3D(pt.x, pt.y, 0) for pt in s_poly])
                    footprint.append(sub_face)
            except RuntimeError as e:
                footprint = [Face3D.from_rectangle(width, length)]
        else:
            footprint = [Face3D.from_rectangle(width, length)]
        first_floor = [
            Polyface3D.from_offset_face(geo, floor_to_floor_height)
            for geo in footprint
        ]

        # rotate the geometries if an orientation angle is specified
        if orientation_angle != 0:
            angle, origin = math.radians(orientation_angle), Point3D()
            first_floor = [geo.rotate_xy(angle, origin) for geo in first_floor]

        # create the initial rooms for the first floor
        rmids = ['Room'] if len(first_floor) == 1 else [
            'Front', 'Right', 'Back', 'Left'
        ]
        if len(first_floor) == 5:
            rmids.append('Core')
        rooms = []
        for polyface, rmid in zip(first_floor, rmids):
            rooms.append(
                Room.from_polyface3d('{}_{}'.format(rmid, unique_id),
                                     polyface))

        # if there are multiple stories, duplicate the first floor rooms
        if story_count != 1:
            all_rooms = []
            for i in range(story_count):
                for room in rooms:
                    new_room = room.duplicate()
                    new_room.add_prefix('Floor{}'.format(i + 1))
                    m_vec = Vector3D(0, 0, floor_to_floor_height * i)
                    new_room.move(m_vec)
                    all_rooms.append(new_room)
            rooms = all_rooms

        # assign adiabatic boundary conditions if requested
        if not outdoor_roof and ad_bc:
            for room in rooms[-len(first_floor):]:
                room[-1].boundary_condition = ad_bc  # make the roof adiabatic
        if not ground_floor and ad_bc:
            for room in rooms[:len(first_floor)]:
                room[0].boundary_condition = ad_bc  # make the floor adiabatic

        # create the model object
        model_id = 'Rectangle_Plan_Model_{}'.format(unique_id)
        model = Model(model_id,
                      rooms,
                      units=units,
                      tolerance=tolerance,
                      angle_tolerance=1)

        # write the model out to the file or stdout
        output_file.write(json.dumps(model.to_dict()))
    except Exception as e:
        _logger.exception(
            'Rectangle plan model creation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)