Beispiel #1
0
 def _is_clockwise_general(self):
     # Find the point belonging to the zone with the lower x and y values
     half_edge = self.initialHalfEdge
     bottom_left_point = self.initialHalfEdge.init_point
     while half_edge.next is not self.initialHalfEdge:
         half_edge = half_edge.next
         if half_edge.init_point.position.y() < bottom_left_point.position.y() or\
          (half_edge.init_point.position.y() == bottom_left_point.position.y() and half_edge.init_point.position.x() < bottom_left_point.position.x()):
             bottom_left_point = half_edge.init_point
     # If it is the tip of a crack, just go to the next one
     if len(bottom_left_point.connectivity) == 1:
         bottom_left_point = half_edge.twin.init_point
     half_edge = self.initialHalfEdge
     # Find the first half edge which has this point as its destiny
     while half_edge.twin.init_point is not bottom_left_point:
         half_edge = half_edge.next
     # When reaching this half edge during traversal, it is needed to make a
     # right turn to reach the next point
     half_edge_simplified1 = QLineF(half_edge.init_point.position,
                                    half_edge.twin.init_point.position)
     half_edge_simplified2 = QLineF(half_edge.next.init_point.position,
                                    half_edge.next.twin.init_point.position)
     # line1 = QLineF.fromPolar(1, half_edge.angleAtPercent(1.))
     # line2 = QLineF.fromPolar(1, half_edge.next.angleAtPercent(0.))
     line1 = QLineF.fromPolar(1, half_edge_simplified1.angle())
     line2 = QLineF.fromPolar(1, half_edge_simplified2.angle())
     # Equation to get the direction of turn is as follows
     direction_of_turn = line1.x2() * line2.y2() - line2.x2() * line1.y2()
     if direction_of_turn > 0:
         return True
     return False
Beispiel #2
0
 def arrow_line(self):
     # type: () -> Tuple[QLineF, QLineF]
     line = self.line()
     angle = line.angle()
     up_line = QLineF.fromPolar(10, angle + 165)
     down_line = QLineF.fromPolar(10, angle - 165)
     up_line.setP1(self.to_t[1])
     down_line.setP1(self.to_t[1])
     up_line.setP2(self.to_t[1] + up_line.p2())
     down_line.setP2(self.to_t[1] + down_line.p2())
     return up_line, down_line
Beispiel #3
0
 def _is_clockwise_with_1_halfedge(self):
     line1 = QLineF.fromPolar(10000,
                              self.initialHalfEdge.angleAtPercent(0.5) + 90)
     line1.setP1(self.initialHalfEdge.pointAtPercent(0.5))
     line2 = QLineF.fromPolar(
         10000,
         self.initialHalfEdge.angleAtPercent(0.75) + 90)
     line2.setP1(self.initialHalfEdge.pointAtPercent(0.75))
     intersection_type = line1.intersect(line2, QPointF())
     if intersection_type == 1:
         return False
     return True
Beispiel #4
0
def arrow_path_concave(line, width):
    """
    Return a :class:`QPainterPath` of a pretty looking arrow.
    """
    path = QPainterPath()
    p1, p2 = line.p1(), line.p2()

    if p1 == p2:
        return path

    baseline = QLineF(line)
    # Require some minimum length.
    baseline.setLength(max(line.length() - width * 3, width * 3))

    start, end = baseline.p1(), baseline.p2()
    mid = (start + end) / 2.0
    normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2()

    path.moveTo(start)
    path.lineTo(start + (normal * width / 4.0))

    path.quadTo(mid + (normal * width / 4.0), end + (normal * width / 1.5))

    path.lineTo(end - (normal * width / 1.5))
    path.quadTo(mid - (normal * width / 4.0), start - (normal * width / 4.0))
    path.closeSubpath()

    arrow_head_len = width * 4
    arrow_head_angle = 50
    line_angle = line.angle() - 180

    angle_1 = line_angle - arrow_head_angle / 2.0
    angle_2 = line_angle + arrow_head_angle / 2.0

    points = [
        p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
        baseline.p2(), p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2
    ]

    poly = QPolygonF(points)
    path_head = QPainterPath()
    path_head.addPolygon(poly)
    path = path.united(path_head)
    return path
Beispiel #5
0
def arrow_path_plain(line, width):
    """
    Return an :class:`QPainterPath` of a plain looking arrow.
    """
    path = QPainterPath()
    p1, p2 = line.p1(), line.p2()

    if p1 == p2:
        return path

    baseline = QLineF(line)
    # Require some minimum length.
    baseline.setLength(max(line.length() - width * 3, width * 3))
    path.moveTo(baseline.p1())
    path.lineTo(baseline.p2())

    stroker = QPainterPathStroker()
    stroker.setWidth(width)
    path = stroker.createStroke(path)

    arrow_head_len = width * 4
    arrow_head_angle = 50
    line_angle = line.angle() - 180

    angle_1 = line_angle - arrow_head_angle / 2.0
    angle_2 = line_angle + arrow_head_angle / 2.0

    points = [
        p2, p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
        p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(), p2
    ]

    poly = QPolygonF(points)
    path_head = QPainterPath()
    path_head.addPolygon(poly)
    path = path.united(path_head)
    return path