Example #1
0
 def __original_shape_without_straight_angles__(self):
     S1 = Shape(self.original_shape)
     S = Shape(S1).remove_straight_angles()
     straight = (numpy.abs(
         numpy.abs((S1.turns_rad() + (0.5 * numpy.pi)) % numpy.pi) -
         0.5 * numpy.pi) < 0.00001)
     if not S1.closed:
         straight[0] = False
         straight[-1] = False
     R = numpy.delete(self.radii, straight.nonzero()[0], 0)
     A = numpy.delete(self.adiabatic_angles_list, straight.nonzero()[0], 0)
     return (S, R, A)
Example #2
0
    def define_points(self, pts):
        alpha = self.angle * DEG2RAD
        c = math.sin(alpha)
        if self.angle == 45.0:
            t = 0.5
        else:
            c2 = c**2
            t = math.sin(math.atan(((1.0 - c2) / c2)**0.125))**2

        a2 = (1 - t)**2 * (t**4 + (1 - t)**4)

        L = self.radius * 2 * t * (1 - t) / (
            3 * (t**4 + (1 - t)**4)**1.5
        )  # characteristic length of the full natural spline of a right angle

        # control points of full natural spline (right angle)
        q0_0 = Coord2(-L, 0)
        q0_1 = Coord2(0, 0)
        q0_2 = Coord2(0, 0)
        q0_3 = Coord2(0, L)

        # control points of first section of the spline
        q1_0 = t * q0_0 + (1 - t) * q0_1
        q2_0 = t**2 * q0_0 + 2 * t * (1 - t) * q0_1 + (1 - t)**2 * q0_2
        q3_0 = t**3 * q0_0 + 3 * t**2 * (1 - t) * q0_1 + 3 * t * (
            1 - t)**2 * q0_2 + (1 - t)**3 * q0_3

        S_control = Shape(points=[q0_0, q1_0, q2_0, q3_0])

        steps = int(math.ceil(2.0 * self.angle / self.angle_step))
        return ShapeBezier(original_shape=S_control,
                           steps=steps).points  # add angle step as a parameter
Example #3
0
 def __poly_to_shape_list__(self, poly):
     """Convert a Shapely polygon to a list of IPKISS shapes"""
     from dependencies.shapely_wrapper import shapely_geom_to_shape
     result_shapes = []
     if poly.is_empty:
         result_shapes.append(Shape())
     else:
         if isinstance(poly, MultiPolygon):
             for g in poly.geoms:
                 s = shapely_geom_to_shape(g)
                 result_shapes.append(s)
         else:
             s = shapely_geom_to_shape(poly)
             result_shapes.append(s)
     return result_shapes
Example #4
0
 def map_coordinate(self, coordinate):
     s = Shape(points=[coordinate])
     return self.__get_scaled_points(s)
Example #5
0
 def map_shape(self, shape):
     return Shape(
         numpy.asarray(self.__get_scaled_points(shape),
                       dtype=numpy.integer))
Example #6
0
    def define_points(self, pts):
        alpha_in = self.adiabatic_angles[0]
        alpha_out = self.adiabatic_angles[1]
        turn_angle = turn_deg(self.start_point, self.turn_point,
                              self.end_point)

        if (alpha_in + alpha_out) > abs(turn_angle):
            alpha_in = alpha_out = 0.5 * abs(turn_angle)

        bend_angle = abs(turn_angle) - alpha_in - alpha_out

        # first section
        if alpha_in > 0.0:
            S5 = OneEndedNaturalSpline(radius=self.radius,
                                       angle=alpha_in,
                                       angle_step=self.angle_step)
        else:
            S5 = Shape((-self.radius, 0))

        # middle section
        if bend_angle > 0.0:
            S5 += ShapeBendRelative(
                start_point=S5[-1],
                input_angle=alpha_in,
                angle_amount=bend_angle,
                radius=self.radius,
                angle_step=self.angle_step,
            )

        # last section
        if alpha_out > 0.0:
            S6 = Shape(
                OneEndedNaturalSpline(radius=self.radius,
                                      angle=alpha_out,
                                      angle_step=self.angle_step))
        else:
            S6 = Shape((-self.radius, 0))
        S6.h_mirror()
        S6.rotate((0, 0), abs(turn_angle))
        S6.reverse()
        S6.move(S5[-1] - S6[0])

        # transform to match the right position

        S = S5 + S6

        if turn_angle < 0:
            S.v_mirror()

        L = straight_line_from_point_angle((0.0, 0.0), turn_angle)
        d = L.distance(S[-1])

        ep = S[-1]
        if abs(turn_angle) == 90.0:
            d = ep.x
        else:
            d = ep.x - ep.y * math.cos(turn_angle * DEG2RAD) / math.sin(
                turn_angle * DEG2RAD)

        S.move((-d, 0.0))
        S.rotate((0.0, 0.0), angle_deg(self.turn_point, self.start_point))
        S.move(self.turn_point)
        S.remove_identicals()

        return S.points
Example #7
0
        if poly.is_empty:
            result_shapes.append(Shape())
        else:
            if isinstance(poly, MultiPolygon):
                for g in poly.geoms:
                    s = shapely_geom_to_shape(g)
                    result_shapes.append(s)
            else:
                s = shapely_geom_to_shape(poly)
                result_shapes.append(s)
        return result_shapes


from ipkiss.geometry.shape import Shape

Shape.mixin_first(__ShapeBooleanOpsWithShapelyAspect__)

########## boolean operations on __ShapeElement__ ##########

from ipkiss.primitives.elements.shape import Boundary
from ipkiss.primitives.elements.basic import ElementList
from .boolean_ops import __BoundaryBooleanOpsAspect__


class __BoundaryBooleanOpsWithShapelyAspect__(__BoundaryBooleanOpsAspect__):
    def __sub__(self, elem):
        if (self.layer != elem.layer):
            return ElementList([self])
        else:
            result_shapes = self.shape.__sub__(elem.shape)
            result_elems = [