Skip to content

Commit ac8d6bf

Browse files
committed
An update to the way that intersection points are found, hopefully fixing a small bug
1 parent 9edc292 commit ac8d6bf

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

cpp/clipper.cpp

+89
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,28 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip)
704704
y1 = std::ceil(((ip.X - 0.5) / Edge1.Dx + by1) - 0.5);
705705
}
706706
}
707+
else if (Edge1.Bot.Y > ip.Y)
708+
{
709+
if (Edge2.Bot.Y >= Edge1.Bot.Y)
710+
{
711+
y1 = Edge1.Bot.Y;
712+
}
713+
else
714+
{
715+
y1 = Edge2.Bot.Y;
716+
}
717+
}
718+
else if (Edge1.Bot.Y < ip.Y)
719+
{
720+
if (Edge2.Bot.Y <= Edge1.Bot.Y)
721+
{
722+
y1 = Edge1.Bot.Y;
723+
}
724+
else
725+
{
726+
y1 = Edge2.Bot.Y;
727+
}
728+
}
707729
if (ip.Y >= Edge1.Bot.Y && y1 < Edge1.Bot.Y) y1 = Edge1.Bot.Y;
708730
else if (ip.Y <= Edge1.Bot.Y && y1 > Edge1.Bot.Y) y1 = Edge1.Bot.Y;
709731
if (Edge2.Bot.X > ip.X)
@@ -728,6 +750,28 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip)
728750
y2 = std::ceil(((ip.X - 0.5) / Edge2.Dx + by2) - 0.5);
729751
}
730752
}
753+
else if (Edge2.Bot.Y > ip.Y)
754+
{
755+
if (Edge1.Bot.Y >= Edge2.Bot.Y)
756+
{
757+
y2 = Edge2.Bot.Y;
758+
}
759+
else
760+
{
761+
y2 = Edge1.Bot.Y;
762+
}
763+
}
764+
else if (Edge2.Bot.Y < ip.Y)
765+
{
766+
if (Edge1.Bot.Y <= Edge2.Bot.Y)
767+
{
768+
y2 = Edge2.Bot.Y;
769+
}
770+
else
771+
{
772+
y2 = Edge1.Bot.Y;
773+
}
774+
}
731775
if (ip.Y >= Edge2.Bot.Y && y2 < Edge2.Bot.Y) y2 = Edge2.Bot.Y;
732776
else if (ip.Y <= Edge2.Bot.Y && y2 > Edge2.Bot.Y) y2 = Edge2.Bot.Y;
733777
cInt x1 = ip.X;
@@ -754,6 +798,28 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip)
754798
x1 = std::ceil(((ip.Y - 0.5) * Edge1.Dx + bx1) - 0.5);
755799
}
756800
}
801+
else if (Edge1.Bot.X > ip.X)
802+
{
803+
if (Edge2.Bot.X >= Edge1.Bot.X)
804+
{
805+
x1 = Edge1.Bot.X;
806+
}
807+
else
808+
{
809+
x1 = Edge2.Bot.X;
810+
}
811+
}
812+
else if (Edge1.Bot.X < ip.X)
813+
{
814+
if (Edge2.Bot.X <= Edge1.Bot.X)
815+
{
816+
x1 = Edge1.Bot.X;
817+
}
818+
else
819+
{
820+
x1 = Edge2.Bot.X;
821+
}
822+
}
757823
if (ip.X >= Edge1.Bot.X && x1 < Edge1.Bot.X) x1 = Edge1.Bot.X;
758824
else if (ip.X <= Edge1.Bot.X && x1 > Edge1.Bot.X) x1 = Edge1.Bot.X;
759825
if (Edge2.Bot.Y > ip.Y)
@@ -778,6 +844,28 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip)
778844
x2 = std::ceil(((ip.Y - 0.5) * Edge2.Dx + bx2) - 0.5);
779845
}
780846
}
847+
else if (Edge2.Bot.X > ip.X)
848+
{
849+
if (Edge1.Bot.X >= Edge2.Bot.X)
850+
{
851+
x2 = Edge2.Bot.X;
852+
}
853+
else
854+
{
855+
x2 = Edge1.Bot.X;
856+
}
857+
}
858+
else if (Edge2.Bot.X < ip.X)
859+
{
860+
if (Edge1.Bot.X <= Edge2.Bot.X)
861+
{
862+
x2 = Edge2.Bot.X;
863+
}
864+
else
865+
{
866+
x2 = Edge1.Bot.X;
867+
}
868+
}
781869
if (ip.X >= Edge2.Bot.X && x2 < Edge2.Bot.X) x2 = Edge2.Bot.X;
782870
else if (ip.X <= Edge2.Bot.X && x2 > Edge2.Bot.X) x2 = Edge2.Bot.X;
783871
if (y1 > ip.Y && y2 > ip.Y)
@@ -3469,6 +3557,7 @@ int PointCount(OutPt *Pts)
34693557
while (p != Pts);
34703558
return result;
34713559
}
3560+
34723561
//------------------------------------------------------------------------------
34733562

34743563
void Clipper::BuildResult(Paths &polys)

0 commit comments

Comments
 (0)