def test_to_from_array():
    """Test to/from array method"""
    test_line = LineSegment2D.from_end_points(Point2D(2, 0), Point2D(2, 2))
    line_array = ((2, 0), (2, 2))

    assert test_line == LineSegment2D.from_array(line_array)

    line_array = ((2, 0), (2, 2))
    test_line = LineSegment2D.from_end_points(Point2D(2, 0), Point2D(2, 2))

    assert test_line.to_array() == line_array

    test_line_2 = LineSegment2D.from_array(test_line.to_array())
    assert test_line == test_line_2
示例#2
0
    def orientation_lines(self):
        """Get the orientation lines for windrose as a LineSegment2D list."""

        # Reset computed graphics to account for changes to cached viz properties
        self._compass = None
        self._container = None

        # Compute x-axis bin boundaries in polar coordinates
        vec_cpt = (0, 0)
        max_bar_radius = self.compass_radius

        # Vector multiplication with max_bar_radius
        segs = []
        for (vec1, vec2) in self.bin_vectors:
            _seg1 = vec_cpt, (max_bar_radius * vec1[0],
                              max_bar_radius * vec1[1])
            _seg2 = vec_cpt, (max_bar_radius * vec2[0],
                              max_bar_radius * vec2[1])
            segs.extend((LineSegment2D.from_array(_seg1),
                         LineSegment2D.from_array(_seg2)))

        return [self._transform(seg) for seg in segs]
示例#3
0
    def _xtick_radial_lines(bin_vecs):
        """X-axis lines for radial histogram as List of lineSegment2Ds.

        Args:
            bin_vecs: Array of histogram bin edge vectors.

        Returns:
            List of LineSegment2Ds.
        """
        # Compute x-axis bin boundaries in polar coordinates
        vec_cpt = (0, 0)
        max_bar_radius = 1.0

        # Vector multiplication with max_bar_radius
        grid_xticks = (((vec_cpt, (max_bar_radius * vec1[0],
                                   max_bar_radius * vec1[1])),
                        (vec_cpt, (max_bar_radius * vec2[0],
                                   max_bar_radius * vec2[1])))
                       for (vec1, vec2) in bin_vecs)

        # Flattened list and return as LineSegment2D
        xtick_array = (xtick for xticks in grid_xticks for xtick in xticks)
        return [LineSegment2D.from_array(vecs) for vecs in xtick_array]
示例#4
0
        if boundary.is_clockwise:
            boundary = boundary.reverse()
        holes, z_height = None, face[0].z
        if face.has_holes:
            holes = []
            for hole in face.holes:
                h_poly = Polygon2D.from_array([(pt.x, pt.y) for pt in hole])
                if not h_poly.is_clockwise:
                    h_poly = h_poly.reverse()
                holes.append(h_poly)
        boundaries.append(boundary)
        hole_polygons.append(holes)
        # compute the skeleton and convert to line segments
        skel_lines = skeleton_as_edge_list(boundary, holes, tolerance)
        skel_lines_rh = [
            from_linesegment2d(LineSegment2D.from_array(line), z_height)
            for line in skel_lines
        ]
        polyskel.append(skel_lines_rh)

    # try to compute core/perimeter polygons if an offset_ is input
    if offset_:
        perim_poly, core_poly = [], []
        for bound, holes in zip(boundaries, hole_polygons):
            try:
                perim, core = perimeter_core_subpolygons(
                    bound, offset_, holes, tolerance)
                perim_poly.append(
                    [polygon_to_brep(p, z_height) for p in perim])
                core_poly.append([polygon_to_brep(p, z_height) for p in core])
            except RuntimeError as e: