@@ -1109,39 +1109,43 @@ bool NodeArea::IsPointInRegion(const ImVec2& Point, const ImVec2& RegionMin, con
11091109 return (Point.x >= RegionMin.x && Point.x <= RegionMax.x && Point.y >= RegionMin.y && Point.y <= RegionMax.y );
11101110}
11111111
1112- int Orientation (const ImVec2& p , const ImVec2& q , const ImVec2& r )
1112+ int Orientation (const ImVec2& FirstPoint , const ImVec2& SecondPoint , const ImVec2& ThirdPoint )
11131113{
1114- float val = (q .y - p .y ) * (r .x - q .x ) - (q .x - p .x ) * (r .y - q .y );
1114+ const float Value = (SecondPoint .y - FirstPoint .y ) * (ThirdPoint .x - SecondPoint .x ) - (SecondPoint .x - FirstPoint .x ) * (ThirdPoint .y - SecondPoint .y );
11151115
1116- if (val == 0 ) return 0 ; // Collinear
1117- return (val > 0 ) ? 1 : 2 ; // Clockwise or Counterclockwise
1116+ // Collinear
1117+ if (Value == 0 )
1118+ return 0 ;
1119+
1120+ return (Value > 0 ) ? 1 : 2 ; // Clockwise or Counterclockwise
11181121}
11191122
1120- bool OnSegment (const ImVec2& p , const ImVec2& q , const ImVec2& r )
1123+ bool OnSegment (const ImVec2& SegmentStart , const ImVec2& SegmentEnd , const ImVec2& PointToCheck )
11211124{
1122- if (q .x <= std::max (p .x , r .x ) && q .x >= std::min (p .x , r .x ) &&
1123- q .y <= std::max (p .y , r .y ) && q .y >= std::min (p .y , r .y ))
1125+ if (PointToCheck .x <= std::max (SegmentStart .x , SegmentEnd .x ) && PointToCheck .x >= std::min (SegmentStart .x , SegmentEnd .x ) &&
1126+ PointToCheck .y <= std::max (SegmentStart .y , SegmentEnd .y ) && PointToCheck .y >= std::min (SegmentStart .y , SegmentEnd .y ))
11241127 return true ;
1128+
11251129 return false ;
11261130}
11271131
1128- bool IsLineSegmentIntersecting (const ImVec2& p1 , const ImVec2& q1 , const ImVec2& p2 , const ImVec2& q2 )
1132+ bool IsLineSegmentIntersecting (const ImVec2& FirstSegmentStart , const ImVec2& FirstSegmentEnd , const ImVec2& SecondSegmentStart , const ImVec2& SecondSegmentEnd )
11291133{
11301134 // Find the four orientations
1131- int o1 = Orientation (p1, q1, p2 );
1132- int o2 = Orientation (p1, q1, q2 );
1133- int o3 = Orientation (p2, q2, p1 );
1134- int o4 = Orientation (p2, q2, q1 );
1135+ int FirstLineToSecondStart = Orientation (FirstSegmentStart, FirstSegmentEnd, SecondSegmentStart );
1136+ int FirstLineToSecondEnd = Orientation (FirstSegmentStart, FirstSegmentEnd, SecondSegmentEnd );
1137+ int SecondLineToFirstStart = Orientation (SecondSegmentStart, SecondSegmentEnd, FirstSegmentStart );
1138+ int SecondLineToFirstEnd = Orientation (SecondSegmentStart, SecondSegmentEnd, FirstSegmentEnd );
11351139
11361140 // General case
1137- if (o1 != o2 && o3 != o4 )
1141+ if (FirstLineToSecondStart != FirstLineToSecondEnd && SecondLineToFirstStart != SecondLineToFirstEnd )
11381142 return true ;
11391143
11401144 // Special cases: check if the segments are collinear and overlap
1141- if (o1 == 0 && OnSegment (p1, p2, q1 )) return true ;
1142- if (o2 == 0 && OnSegment (p1, q2, q1 )) return true ;
1143- if (o3 == 0 && OnSegment (p2, p1, q2 )) return true ;
1144- if (o4 == 0 && OnSegment (p2, q1, q2 )) return true ;
1145+ if (FirstLineToSecondStart == 0 && OnSegment (FirstSegmentStart, SecondSegmentStart, FirstSegmentEnd )) return true ;
1146+ if (FirstLineToSecondEnd == 0 && OnSegment (FirstSegmentStart, SecondSegmentEnd, FirstSegmentEnd )) return true ;
1147+ if (SecondLineToFirstStart == 0 && OnSegment (SecondSegmentStart, FirstSegmentStart, SecondSegmentEnd )) return true ;
1148+ if (SecondLineToFirstEnd == 0 && OnSegment (SecondSegmentStart, FirstSegmentEnd, SecondSegmentEnd )) return true ;
11451149
11461150 return false ; // If none of the above cases, return false
11471151}
@@ -1181,27 +1185,27 @@ bool NodeArea::IsSegmentInRegion(ImVec2 Begin, ImVec2 End, const int Steps)
11811185 float h3 = t * t * t - 2 * t * t + t;
11821186 float h4 = t * t * t - t * t;
11831187
1184- ImVec2 segmentStart = ImVec2 (h1 * Begin.x + h2 * End.x + h3 * t1.x + h4 * t2.x , h1 * Begin.y + h2 * End.y + h3 * t1.y + h4 * t2.y );
1188+ ImVec2 SegmentStart = ImVec2 (h1 * Begin.x + h2 * End.x + h3 * t1.x + h4 * t2.x , h1 * Begin.y + h2 * End.y + h3 * t1.y + h4 * t2.y );
11851189
11861190 t = static_cast <float >(Step + 1 ) / static_cast <float >(Steps); // Update t for the end segment.
11871191 h1 = +2 * t * t * t - 3 * t * t + 1 .0f ;
11881192 h2 = -2 * t * t * t + 3 * t * t;
11891193 h3 = t * t * t - 2 * t * t + t;
11901194 h4 = t * t * t - t * t;
11911195
1192- ImVec2 segmentEnd = ImVec2 (h1 * Begin.x + h2 * End.x + h3 * t1.x + h4 * t2.x , h1 * Begin.y + h2 * End.y + h3 * t1.y + h4 * t2.y );
1196+ ImVec2 SegmentEnd = ImVec2 (h1 * Begin.x + h2 * End.x + h3 * t1.x + h4 * t2.x , h1 * Begin.y + h2 * End.y + h3 * t1.y + h4 * t2.y );
11931197
11941198 // If either of the segment's points are in the region, the connection is in the region.
1195- if (IsPointInRegion (segmentStart , MouseSelectRegionMin, MouseSelectRegionMax) ||
1196- IsPointInRegion (segmentEnd , MouseSelectRegionMin, MouseSelectRegionMax))
1199+ if (IsPointInRegion (SegmentStart , MouseSelectRegionMin, MouseSelectRegionMax) ||
1200+ IsPointInRegion (SegmentEnd , MouseSelectRegionMin, MouseSelectRegionMax))
11971201 {
11981202 return true ;
11991203 }
12001204
12011205 // Check if the segment intersects with any of the region's edges.
12021206 for (int i = 0 ; i < 4 ; i++)
12031207 {
1204- if (IsLineSegmentIntersecting (regionCorners[i], regionCorners[(i + 1 ) % 4 ], segmentStart, segmentEnd ))
1208+ if (IsLineSegmentIntersecting (regionCorners[i], regionCorners[(i + 1 ) % 4 ], SegmentStart, SegmentEnd ))
12051209 {
12061210 return true ;
12071211 }
0 commit comments