65 int balloonSegment = -1;
66 QPointF balloonSegmentPoint1;
67 QPointF balloonSegmentPoint2;
69 const bool invertedY = rect.height() < 0;
71 cornerRadius = std::min( cornerRadius, std::min( std::fabs( rect.height() ), rect.width() ) / 2.0 );
74 if ( rect.contains( origin.
toQPointF() ) )
81 QList<QLineF> segmentList;
82 segmentList <<
segment( 0, rect, cornerRadius );
83 segmentList <<
segment( 1, rect, cornerRadius );
84 segmentList <<
segment( 2, rect, cornerRadius );
85 segmentList <<
segment( 3, rect, cornerRadius );
88 double minEdgeDist = std::numeric_limits<double>::max();
89 int minEdgeIndex = -1;
93 for (
int i = 0; i < 4; ++i )
95 QLineF currentSegment = segmentList.at( i );
97 double currentMinDist = origin.
sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
98 bool isPreferredSegment =
false;
102 const double angle = fmod( origin.
azimuth( currentMinDistPoint ) + 360.0, 360.0 );
103 if ( angle < 45 || angle > 315 )
104 isPreferredSegment = i == 0;
105 else if ( angle < 135 )
106 isPreferredSegment = i == 3;
107 else if ( angle < 225 )
108 isPreferredSegment = i == 2;
110 isPreferredSegment = i == 1;
112 else if ( currentMinDist < minEdgeDist )
113 isPreferredSegment =
true;
115 if ( isPreferredSegment )
118 minEdgePoint = currentMinDistPoint;
119 minEdgeDist = currentMinDist;
120 minEdge = currentSegment;
124 if ( minEdgeIndex >= 0 )
126 balloonSegment = minEdgeIndex;
127 QPointF minEdgeEnd = minEdge.p2();
128 balloonSegmentPoint1 = QPointF( minEdgePoint.
x(), minEdgePoint.
y() );
130 const double segmentLength = minEdge.length();
131 const double clampedWedgeWidth = std::clamp( wedgeWidth, 0.0, segmentLength );
132 if ( std::sqrt( minEdgePoint.
sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < clampedWedgeWidth )
137 balloonSegmentPoint1 = QPointF( x, y );
144 balloonSegmentPoint2 = QPointF( x, y );
152 for (
int i = 0; i < 4; ++i )
154 QLineF currentSegment =
segment( i, rect, cornerRadius );
157 p0 = currentSegment.p1();
158 path.moveTo( currentSegment.p1() );
163 path.arcTo( std::min( p1.x(), currentSegment.p1().x() ),
164 std::min( p1.y(), currentSegment.p1().y() ),
165 cornerRadius, cornerRadius,
166 i == 1 ? -90 : ( i == 2 ? 0 : 90 ),
169 path.arcTo( std::min( p1.x(), currentSegment.p1().x() ),
170 std::min( p1.y(), currentSegment.p1().y() ),
171 cornerRadius, cornerRadius,
172 i == 1 ? 90 : ( i == 2 ? 0 : -90 ),
176 if ( i == balloonSegment )
178 path.lineTo( balloonSegmentPoint1 );
180 path.lineTo( balloonSegmentPoint2 );
183 p1 = currentSegment.p2();
188 path.arcTo( std::min( p1.x(), p0.x() ),
189 std::min( p1.y(), p0.y() ),
190 cornerRadius, cornerRadius,
193 path.arcTo( std::min( p1.x(), p0.x() ),
194 std::min( p1.y(), p0.y() ),
195 cornerRadius, cornerRadius,
static void pointOnLineWithDistance(double x1, double y1, double x2, double y2, double distance, double &x, double &y, double *z1=nullptr, double *z2=nullptr, double *z=nullptr, double *m1=nullptr, double *m2=nullptr, double *m=nullptr)
Calculates the point a specified distance from (x1, y1) toward a second point (x2,...