From 388041f1150b8dbe67bf87d7300ae7d4ac291f78 Mon Sep 17 00:00:00 2001 From: angusj Date: Sat, 16 Sep 2023 20:31:13 +1000 Subject: [PATCH] Fixed a minor bug in ClipperOffset (#593) --- CPP/Clipper2Lib/src/clipper.offset.cpp | 12 +- CPP/Tests/TestOffsets.cpp | 308 ++++++++++++++++++++----- CSharp/Clipper2Lib/Clipper.Offset.cs | 8 +- Delphi/Clipper2Lib/Clipper.Offset.pas | 10 +- 4 files changed, 264 insertions(+), 74 deletions(-) diff --git a/CPP/Clipper2Lib/src/clipper.offset.cpp b/CPP/Clipper2Lib/src/clipper.offset.cpp index c369993d..496ad9a7 100644 --- a/CPP/Clipper2Lib/src/clipper.offset.cpp +++ b/CPP/Clipper2Lib/src/clipper.offset.cpp @@ -1,6 +1,6 @@ /******************************************************************************* * Author : Angus Johnson * -* Date : 9 September 2023 * +* Date : 16 September 2023 * * Website : http://www.angusj.com * * Copyright : Angus Johnson 2010-2023 * * Purpose : Path Offset (Inflate/Shrink) * @@ -327,11 +327,7 @@ void ClipperOffset::OffsetPoint(Group& group, Path64& path, size_t j, size_t k) return; } - if (cos_a > 0.999) // almost straight - less than 2.5 degree (#424, #526) - { - DoMiter(group, path, j, k, cos_a); - } - else if (cos_a > -0.99 && (sin_a * group_delta_ < 0)) + if (cos_a > -0.99 && (sin_a * group_delta_ < 0)) // test for concavity first (#593) { // is concave group.path.push_back(GetPerpendic(path[j], norms[k], group_delta_)); @@ -340,6 +336,10 @@ void ClipperOffset::OffsetPoint(Group& group, Path64& path, size_t j, size_t k) group.path.push_back(path[j]); // (#405) group.path.push_back(GetPerpendic(path[j], norms[j], group_delta_)); } + else if (cos_a > 0.999) // almost straight - less than 2.5 degree (#424, #526) + { + DoMiter(group, path, j, k, cos_a); + } else if (join_type_ == JoinType::Miter) { // miter unless the angle is so acute the miter would exceeds ML diff --git a/CPP/Tests/TestOffsets.cpp b/CPP/Tests/TestOffsets.cpp index 984de03c..dd713364 100644 --- a/CPP/Tests/TestOffsets.cpp +++ b/CPP/Tests/TestOffsets.cpp @@ -88,68 +88,28 @@ TEST(Clipper2Tests, TestOffsets2) { // see #448 & #456 TEST(Clipper2Tests, TestOffsets3) // see #424 { - Paths64 subjects = {{ - {1525311078, 1352369439}, - {1526632284, 1366692987}, - {1519397110, 1367437476}, - {1520246456, 1380177674}, - {1520613458, 1385913385}, - {1517383844, 1386238444}, - {1517771817, 1392099983}, - {1518233190, 1398758441}, - {1518421934, 1401883197}, - {1518694564, 1406612275}, - {1520267428, 1430289121}, - {1520770744, 1438027612}, - {1521148232, 1443438264}, - {1521441833, 1448964260}, - {1521683005, 1452518932}, - {1521819320, 1454374912}, - {1527943004, 1454154711}, - {1527649403, 1448523858}, - {1535901696, 1447989084}, - {1535524209, 1442788147}, - {1538953052, 1442463089}, - {1541553521, 1442242888}, - {1541459149, 1438855987}, - {1538764308, 1439076188}, - {1538575565, 1436832236}, - {1538764308, 1436832236}, - {1536509870, 1405374956}, - {1550497874, 1404347351}, - {1550214758, 1402428457}, - {1543818445, 1402868859}, - {1543734559, 1402124370}, - {1540672717, 1402344571}, - {1540473487, 1399995761}, - {1524996506, 1400981422}, - {1524807762, 1398223667}, - {1530092585, 1397898609}, - {1531675935, 1397783265}, - {1531392819, 1394920653}, - {1529809469, 1395025510}, - {1529348096, 1388880855}, - {1531099218, 1388660654}, - {1530826588, 1385158410}, - {1532955197, 1384938209}, - {1532661596, 1379003269}, - {1532472852, 1376235028}, - {1531277476, 1376350372}, - {1530050642, 1361806623}, - {1599487345, 1352704983}, - {1602758902, 1378489467}, - {1618990858, 1376350372}, - {1615058698, 1344085688}, - {1603230761, 1345700495}, - {1598648484, 1346329641}, - {1598931599, 1348667965}, - {1596698132, 1348993024}, - {1595775386, 1342722540} }}; - - Paths64 solution = InflatePaths(subjects, -209715, - JoinType::Miter, EndType::Polygon); + {1525311078, 1352369439}, {1526632284, 1366692987}, {1519397110, 1367437476}, + {1520246456, 1380177674}, {1520613458, 1385913385}, {1517383844, 1386238444}, + {1517771817, 1392099983}, {1518233190, 1398758441}, {1518421934, 1401883197}, + {1518694564, 1406612275}, {1520267428, 1430289121}, {1520770744, 1438027612}, + {1521148232, 1443438264}, {1521441833, 1448964260}, {1521683005, 1452518932}, + {1521819320, 1454374912}, {1527943004, 1454154711}, {1527649403, 1448523858}, + {1535901696, 1447989084}, {1535524209, 1442788147}, {1538953052, 1442463089}, + {1541553521, 1442242888}, {1541459149, 1438855987}, {1538764308, 1439076188}, + {1538575565, 1436832236}, {1538764308, 1436832236}, {1536509870, 1405374956}, + {1550497874, 1404347351}, {1550214758, 1402428457}, {1543818445, 1402868859}, + {1543734559, 1402124370}, {1540672717, 1402344571}, {1540473487, 1399995761}, + {1524996506, 1400981422}, {1524807762, 1398223667}, {1530092585, 1397898609}, + {1531675935, 1397783265}, {1531392819, 1394920653}, {1529809469, 1395025510}, + {1529348096, 1388880855}, {1531099218, 1388660654}, {1530826588, 1385158410}, + {1532955197, 1384938209}, {1532661596, 1379003269}, {1532472852, 1376235028}, + {1531277476, 1376350372}, {1530050642, 1361806623}, {1599487345, 1352704983}, + {1602758902, 1378489467}, {1618990858, 1376350372}, {1615058698, 1344085688}, + {1603230761, 1345700495}, {1598648484, 1346329641}, {1598931599, 1348667965}, + {1596698132, 1348993024}, {1595775386, 1342722540} }}; + Paths64 solution = InflatePaths(subjects, -209715, JoinType::Miter, EndType::Polygon); EXPECT_LE(solution[0].size() - subjects[0].size(), 1); } @@ -187,3 +147,231 @@ TEST(Clipper2Tests, TestOffsets4) // see #482 EXPECT_GT(solution[0].size(), 6); } + +TEST(Clipper2Tests, TestOffsets5) // see #593 +{ + Paths64 subject = { + {{5243,14829}, {5243,27114}, {6095,27443}, {6926,27822}, {7734,28247}, {8515,28719}, + {9269,29236}, {9990,29795}, {10679,30395}, {11331,31034}, {11945,31710}, {12518,32421}, + {13050,33163}, {13537,33935}, {13979,34734}, {14374,35558}, {14721,36403}, {15017,37266}, + {15263,38146}, {15458,39038}, {15601,39940}, {15691,40848}, {15728,41761}, {15712,42674}, + {15643,43584}, {15521,44489}, {15347,45386}, {15122,46271}, {14845,47141}, {14519,47994}, + {14143,48826}, {13720,49635}, {13250,50418}, {12736,51173}, {12179,51897}, {11581,52587}, + {10944,53241}, {10270,53857}, {9561,54433}, {8820,54966}, {8050,55456}, {7252,55901}, + {6430,56298}, {5586,56647}, {5243,56773}, {5243,69058}, {6095,69387}, {6926,69765}, + {7734,70191}, {8515,70663}, {9269,71179}, {9990,71738}, {10679,72339}, {11331,72978}, + {11945,73654}, {12518,74364}, {13050,75107}, {13537,75879}, {13979,76678}, {14374,77501}, + {14721,78346}, {15017,79210}, {15263,80089}, {15458,80981}, {15601,81883}, {15691,82792}, + {15728,83704}, {15712,84617}, {15643,85528}, {15521,86433}, {15347,87329}, {15122,88214}, + {14845,89084}, {14519,89937}, {14143,90769}, {13720,91579}, {13250,92362}, {12736,93116}, + {12179,93840}, {11581,94530}, {10944,95184}, {10270,95800}, {9561,96376}, {8820,96910}, + {8050,97400}, {7252,97844}, {6430,98241}, {5586,98590}, {5243,98716}, {5243,111001}, + {6095,111330}, {6926,111708}, {7734,112134}, {8515,112606}, {9269,113123}, {9990,113682}, + {10679,114282}, {11331,114921}, {11945,115597}, {12518,116308}, {13050,117050}, {13537,117822}, + {13979,118621}, {14374,119445}, {14721,120290}, {15017,121153}, {15263,122033}, {15458,122925}, + {15601,123827}, {15691,124735}, {15728,125648}, {15712,126561}, {15643,127471}, {15521,128376}, + {15347,129273}, {15122,130158}, {14845,131028}, {14519,131881}, {14143,132713}, {13720,133522}, + {13250,134305}, {12736,135060}, {12179,135783}, {11581,136473}, {10944,137128}, {10270,137744}, + {9561,138320}, {8820,138853}, {8050,139343}, {7252,139788}, {6430,140185}, {5586,140534}, + {5243,140660}, {5243,152945}, {6095,153274}, {6926,153652}, {7734,154078}, {8515,154550}, + {9269,155066}, {9990,155625}, {10679,156225}, {11331,156865}, {11945,157541}, {12518,158251}, + {13050,158993}, {13537,159766}, {13979,160565}, {14374,161388}, {14721,162233}, {15017,163097}, + {15263,163976}, {15458,164868}, {15601,165770}, {15691,166679}, {15728,167591}, {15712,168504}, + {15643,169415}, {15521,170320}, {15347,171216}, {15122,172101}, {14845,172971}, {14519,173824}, + {14143,174656}, {13720,175465}, {13250,176249}, {12736,177003}, {12179,177727}, {11581,178417}, + {10944,179071}, {10270,179687}, {9561,180263}, {8820,180797}, {8050,181287}, {7252,181731}, + {6430,182128}, {5586,182477}, {5243,182603}, {5243,194888}, {6095,195217}, {6926,195595}, + {7734,196021}, {8515,196493}, {9269,197009}, {9990,197569}, {10679,198169}, {11331,198808}, + {11945,199484}, {12518,200194}, {13050,200937}, {13537,201709}, {13979,202508}, {14374,203332}, + {14721,204176}, {15017,205040}, {15263,205919}, {15458,206812}, {15601,207714}, {15691,208622}, + {15728,209535}, {15712,210448}, {15643,211358}, {15521,212263}, {15347,213160}, {15122,214044}, + {14845,214915}, {14519,215767}, {14143,216600}, {13720,217409}, {13250,218192}, {12736,218947}, + {12179,219670}, {11581,220360}, {10944,221014}, {10270,221631}, {9561,222206}, {8820,222740}, + {8050,223230}, {7252,223675}, {6430,224072}, {5586,224421}, {5243,224547}, {5243,236831}, + {6095,237161}, {6926,237539}, {7734,237965}, {8515,238436}, {9269,238953}, {9990,239512}, + {10679,240112}, {11331,240752}, {11945,241427}, {12518,242138}, {13050,242880}, {13537,243653}, + {13979,244452}, {14374,245275}, {14721,246120}, {15017,246984}, {15263,247863}, {15458,248755}, + {15601,249657}, {15691,250566}, {15728,251478}, {15712,252391}, {15643,253302}, {15521,254207}, + {15347,255103}, {15122,255988}, {14845,256858}, {14519,257711}, {14143,258543}, {13720,259352}, + {13250,260136}, {12736,260890}, {12179,261614}, {11581,262304}, {10944,262958}, {10270,263574}, + {9561,264150}, {8820,264684}, {8050,265174}, {7252,265618}, {6430,266015}, {5586,266364}, + {5243,266490}, {5243,278775}, {6095,279104}, {6926,279482}, {7734,279908}, {8515,280380}, + {9269,280896}, {9990,281456}, {10679,282056}, {11331,282695}, {11945,283371}, {12518,284081}, + {13050,284824}, {13537,285596}, {13979,286395}, {14374,287218}, {14721,288063}, {15017,288927}, + {15263,289806}, {15458,290698}, {15601,291600}, {15691,292509}, {15728,293422}, {15712,294335}, + {15643,295245}, {15521,296150}, {15347,297047}, {15122,297931}, {14845,298802}, {14519,299654}, + {14143,300487}, {13720,301296}, {13250,302079}, {12736,302834}, {12179,303557}, {11581,304247}, + {10944,304901}, {10270,305517}, {9561,306093}, {8820,306627}, {8050,307117}, {7252,307561}, + {6430,307959}, {5586,308308}, {5243,308433}, {5243,320718}, {6092,321046}, {6920,321423}, + {7726,321847}, {8505,322317}, {9256,322831}, {9976,323387}, {10662,323984}, {11313,324620}, + {11926,325293}, {12499,326000}, {13031,326739}, {13518,327507}, {13961,328302}, {14356,329122}, + {14704,329963}, {14829,330305}, {31309,330305}, {31638,329453}, {32016,328622}, {32442,327814}, + {32914,327032}, {33430,326279}, {33989,325557}, {34589,324869}, {35229,324217}, {35905,323603}, + {36615,323029}, {37357,322498}, {38130,322010}, {38929,321568}, {39752,321173}, {40597,320827}, + {41461,320530}, {42340,320284}, {43232,320090}, {44134,319947}, {45043,319857}, {45955,319820}, + {46868,319836}, {47779,319905}, {48684,320026}, {49580,320200}, {50465,320426}, {51335,320702}, + {52188,321029}, {53020,321405}, {53829,321828}, {54613,322297}, {55367,322811}, {56091,323369}, + {56781,323967}, {57435,324604}, {58051,325278}, {58627,325986}, {59161,326727}, {59651,327498}, + {60095,328296}, {60492,329118}, {60841,329962}, {60967,330305}, {77446,330305}, {77776,329453}, + {78154,328622}, {78579,327814}, {79051,327032}, {79568,326279}, {80127,325557}, {80727,324869}, + {81366,324217}, {82042,323603}, {82753,323029}, {83495,322498}, {84267,322010}, {85066,321568}, + {85890,321173}, {86735,320827}, {87598,320530}, {88478,320284}, {89370,320090}, {90272,319947}, + {91181,319857}, {92093,319820}, {93006,319836}, {93917,319905}, {94822,320026}, {95718,320200}, + {96603,320426}, {97473,320702}, {98326,321029}, {99158,321405}, {99967,321828}, {100750,322297}, + {101505,322811}, {102229,323369}, {102919,323967}, {103573,324604}, {104189,325278}, {104765,325986}, + {105299,326727}, {105788,327498}, {106233,328296}, {106630,329118}, {106979,329962}, {107105,330305}, + {123584,330305}, {123913,329453}, {124292,328622}, {124717,327814}, {125189,327032}, {125706,326279}, + {126265,325557}, {126865,324869}, {127504,324217}, {128180,323603}, {128891,323029}, {129633,322498}, + {130405,322010}, {131204,321568}, {132028,321173}, {132873,320827}, {133736,320530}, {134616,320284}, + {135508,320090}, {136410,319947}, {137318,319857}, {138231,319820}, {139144,319836}, {140054,319905}, + {140959,320026}, {141856,320200}, {142741,320426}, {143611,320702}, {144464,321029}, {145296,321405}, + {146105,321828}, {146888,322297}, {147643,322811}, {148366,323369}, {149056,323967}, {149711,324604}, + {150327,325278}, {150903,325986}, {151436,326727}, {151926,327498}, {152371,328296}, {152768,329118}, + {153117,329962}, {153243,330305}, {169722,330305}, {170051,329453}, {170429,328622}, {170855,327814}, + {171327,327032}, {171843,326279}, {172403,325557}, {173003,324869}, {173642,324217}, {174318,323603}, + {175028,323029}, {175771,322498}, {176543,322010}, {177342,321568}, {178165,321173}, {179010,320827}, + {179874,320530}, {180753,320284}, {181646,320090}, {182547,319947}, {183456,319857}, {184369,319820}, + {185282,319836}, {186192,319905}, {187097,320026}, {187994,320200}, {188878,320426}, {189749,320702}, + {190601,321029}, {191434,321405}, {192243,321828}, {193026,322297}, {193781,322811}, {194504,323369}, + {195194,323967}, {195848,324604}, {196464,325278}, {197040,325986}, {197574,326727}, {198064,327498}, + {198508,328296}, {198906,329118}, {199255,329962}, {199380,330305}, {215860,330305}, {216189,329453}, + {216567,328622}, {216993,327814}, {217465,327032}, {217981,326279}, {218540,325557}, {219141,324869}, + {219780,324217}, {220456,323603}, {221166,323029}, {221909,322498}, {222681,322010}, {223480,321568}, + {224303,321173}, {225148,320827}, {226012,320530}, {226891,320284}, {227783,320090}, {228685,319947}, + {229594,319857}, {230506,319820}, {231419,319836}, {232330,319905}, {233235,320026}, {234131,320200}, + {235016,320426}, {235886,320702}, {236739,321029}, {237572,321405}, {238381,321828}, {239164,322297}, + {239919,322811}, {240642,323369}, {241332,323967}, {241986,324604}, {242602,325278}, {243178,325986}, + {243712,326727}, {244202,327498}, {244646,328296}, {245044,329118}, {245393,329962}, {245518,330305}, + {261998,330305}, {262327,329453}, {262705,328622}, {263131,327814}, {263603,327032}, {264119,326279}, + {264678,325557}, {265278,324869}, {265918,324217}, {266594,323603}, {267304,323029}, {268046,322498}, + {268819,322010}, {269618,321568}, {270441,321173}, {271286,320827}, {272150,320530}, {273029,320284}, + {273921,320090}, {274823,319947}, {275732,319857}, {276644,319820}, {277557,319836}, {278468,319905}, + {279373,320026}, {280269,320200}, {281154,320426}, {282024,320702}, {282877,321029}, {283709,321405}, + {284518,321828}, {285302,322297}, {286056,322811}, {286780,323369}, {287470,323967}, {288124,324604}, + {288740,325278}, {289316,325986}, {289850,326727}, {290340,327498}, {290784,328296}, {291181,329118}, + {291530,329962}, {291656,330305}, {308135,330305}, {308465,329453}, {308843,328622}, {309268,327814}, + {309740,327032}, {310257,326279}, {310816,325557}, {311416,324869}, {312055,324217}, {312731,323603}, + {313442,323029}, {314184,322498}, {314956,322010}, {315755,321568}, {316579,321173}, {317424,320827}, + {318287,320530}, {319167,320284}, {320059,320090}, {320961,319947}, {321870,319857}, {322782,319820}, + {323695,319836}, {324606,319905}, {325511,320026}, {326407,320200}, {327292,320426}, {328162,320702}, + {329015,321029}, {329847,321405}, {330656,321828}, {331440,322297}, {332194,322811}, {332918,323369}, + {333608,323967}, {334262,324604}, {334878,325278}, {335454,325986}, {335988,326727}, {336477,327498}, + {336922,328296}, {337319,329118}, {337668,329962}, {337794,330305}, {354273,330305}, {354601,329456}, + {354978,328627}, {355402,327822}, {355871,327043}, {356385,326292}, {356942,325572}, {357539,324885}, + {358175,324234}, {358848,323621}, {359555,323048}, {360294,322517}, {361062,322029}, {361857,321587}, + {362677,321191}, {363518,320844}, {363859,320718}, {363859,308433}, {363008,308104}, {362177,307726}, + {361369,307300}, {360587,306828}, {359834,306312}, {359112,305753}, {358424,305153}, {357772,304513}, + {357158,303837}, {356584,303127}, {356052,302385}, {355565,301612}, {355123,300813}, {354728,299990}, + {354382,299145}, {354085,298281}, {353839,297402}, {353644,296510}, {353502,295608}, {353412,294699}, + {353375,293787}, {353391,292874}, {353459,291963}, {353581,291058}, {353755,290162}, {353981,289277}, + {354257,288407}, {354584,287554}, {354959,286722}, {355383,285913}, {355852,285129}, {356366,284375}, + {356923,283651}, {357521,282961}, {358159,282307}, {358833,281691}, {359541,281115}, {360282,280581}, + {361053,280091}, {361850,279647}, {362673,279250}, {363517,278901}, {363859,278775}, {363859,266490}, + {363008,266161}, {362177,265783}, {361369,265357}, {360587,264885}, {359834,264369}, {359112,263809}, + {358424,263209}, {357772,262570}, {357158,261894}, {356584,261184}, {356052,260441}, {355565,259669}, + {355123,258870}, {354728,258046}, {354382,257202}, {354085,256338}, {353839,255459}, {353644,254566}, + {353502,253664}, {353412,252756}, {353375,251843}, {353391,250930}, {353459,250020}, {353581,249115}, + {353755,248218}, {353981,247334}, {354257,246463}, {354584,245611}, {354959,244778}, {355383,243969}, + {355852,243186}, {356366,242431}, {356923,241708}, {357521,241018}, {358159,240364}, {358833,239747}, + {359541,239172}, {360282,238638}, {361053,238148}, {361850,237704}, {362673,237306}, {363517,236957}, + {363859,236831}, {363859,224547}, {363008,224217}, {362177,223839}, {361369,223413}, {360587,222942}, + {359834,222425}, {359112,221866}, {358424,221266}, {357772,220626}, {357158,219951}, {356584,219240}, + {356052,218498}, {355565,217726}, {355123,216926}, {354728,216103}, {354382,215258}, {354085,214395}, + {353839,213515}, {353644,212623}, {353502,211721}, {353412,210812}, {353375,209900}, {353391,208987}, + {353459,208076}, {353581,207171}, {353755,206275}, {353981,205390}, {354257,204520}, {354584,203667}, + {354959,202835}, {355383,202026}, {355852,201242}, {356366,200488}, {356923,199764}, {357521,199074}, + {358159,198420}, {358833,197804}, {359541,197228}, {360282,196694}, {361053,196204}, {361850,195760}, + {362673,195363}, {363517,195014}, {363859,194888}, {363859,182603}, {363008,182274}, {362177,181896}, + {361369,181470}, {360587,180998}, {359834,180482}, {359112,179922}, {358424,179322}, {357772,178683}, + {357158,178007}, {356584,177297}, {356052,176554}, {355565,175782}, {355123,174983}, {354728,174160}, + {354382,173315}, {354085,172451}, {353839,171572}, {353644,170680}, {353502,169778}, {353412,168869}, + {353375,167956}, {353391,167043}, {353459,166133}, {353581,165228}, {353755,164331}, {353981,163447}, + {354257,162576}, {354584,161724}, {354959,160891}, {355383,160082}, {355852,159299}, {356366,158544}, + {356923,157821}, {357521,157131}, {358159,156477}, {358833,155861}, {359541,155285}, {360282,154751}, + {361053,154261}, {361850,153817}, {362673,153419}, {363517,153070}, {363859,152945}, {363859,140660}, + {363008,140330}, {362177,139952}, {361369,139527}, {360587,139055}, {359834,138538}, {359112,137979}, + {358424,137379}, {357772,136740}, {357158,136064}, {356584,135353}, {356052,134611}, {355565,133839}, + {355123,133039}, {354728,132216}, {354382,131371}, {354085,130508}, {353839,129628}, {353644,128736}, + {353502,127834}, {353412,126925}, {353375,126013}, {353391,125100}, {353459,124189}, {353581,123284}, + {353755,122388}, {353981,121503}, {354257,120633}, {354584,119780}, {354959,118948}, {355383,118139}, + {355852,117355}, {356366,116601}, {356923,115877}, {357521,115187}, {358159,114533}, {358833,113917}, + {359541,113341}, {360282,112807}, {361053,112317}, {361850,111873}, {362673,111476}, {363517,111127}, + {363859,111001}, {363859,98716}, {363008,98387}, {362177,98009}, {361369,97583}, {360587,97111}, + {359834,96595}, {359112,96035}, {358424,95435}, {357772,94796}, {357158,94120}, {356584,93410}, + {356052,92667}, {355565,91895}, {355123,91096}, {354728,90273}, {354382,89428}, {354085,88564}, + {353839,87685}, {353644,86793}, {353502,85891}, {353412,84982}, {353375,84070}, {353391,83157}, + {353459,82246}, {353581,81341}, {353755,80445}, {353981,79560}, {354257,78689}, {354584,77837}, + {354959,77004}, {355383,76195}, {355852,75412}, {356366,74657}, {356923,73934}, {357521,73244}, + {358159,72590}, {358833,71974}, {359541,71398}, {360282,70864}, {361053,70374}, {361850,69930}, + {362673,69532}, {363517,69183}, {363859,69058}, {363859,56773}, {363008,56443}, {362177,56065}, + {361369,55640}, {360587,55168}, {359834,54651}, {359112,54092}, {358424,53492}, {357772,52853}, + {357158,52177}, {356584,51466}, {356052,50724}, {355565,49952}, {355123,49153}, {354728,48329}, + {354382,47484}, {354085,46621}, {353839,45741}, {353644,44849}, {353502,43947}, {353412,43039}, + {353375,42126}, {353391,41213}, {353459,40303}, {353581,39398}, {353755,38501}, {353981,37616}, + {354257,36746}, {354584,35893}, {354959,35061}, {355383,34252}, {355852,33469}, {356366,32714}, + {356923,31990}, {357521,31300}, {358159,30646}, {358833,30030}, {359541,29454}, {360282,28920}, + {361053,28431}, {361850,27986}, {362673,27589}, {363517,27240}, {363859,27114}, {363859,14829}, + {363011,14501}, {362182,14125}, {361377,13701}, {360597,13231}, {359847,12717}, {359127,12160}, + {358440,11563}, {357789,10927}, {357176,10255}, {356603,9548}, {356072,8809}, {355584,8041}, + {355142,7245}, {354746,6426}, {354398,5585}, {354273,5243}, {337794,5243}, {337465,6095}, + {337086,6926}, {336661,7734}, {336189,8515}, {335672,9269}, {335113,9990}, {334513,10679}, + {333874,11331}, {333198,11945}, {332487,12518}, {331745,13050}, {330973,13537}, {330174,13979}, + {329350,14374}, {328505,14721}, {327642,15017}, {326762,15263}, {325870,15458}, {324968,15601}, + {324060,15691}, {323147,15728}, {322234,15712}, {321324,15643}, {320419,15521}, {319522,15347}, + {318637,15122}, {317767,14845}, {316914,14519}, {316082,14143}, {315273,13720}, {314490,13250}, + {313735,12736}, {313012,12179}, {312322,11581}, {311667,10944}, {311051,10270}, {310475,9561}, + {309942,8820}, {309452,8050}, {309007,7252}, {308610,6430}, {308261,5586}, {308135,5243}, + {291656,5243}, {291327,6095}, {290949,6926}, {290523,7734}, {290051,8515}, {289535,9269}, + {288975,9990}, {288375,10679}, {287736,11331}, {287060,11945}, {286350,12518}, {285607,13050}, + {284835,13537}, {284036,13979}, {283213,14374}, {282368,14721}, {281504,15017}, {280625,15263}, + {279733,15458}, {278831,15601}, {277922,15691}, {277009,15728}, {276096,15712}, {275186,15643}, + {274281,15521}, {273384,15347}, {272500,15122}, {271629,14845}, {270777,14519}, {269944,14143}, + {269135,13720}, {268352,13250}, {267597,12736}, {266874,12179}, {266184,11581}, {265530,10944}, + {264914,10270}, {264338,9561}, {263804,8820}, {263314,8050}, {262870,7252}, {262472,6430}, + {262123,5586}, {261998,5243}, {245518,5243}, {245189,6095}, {244811,6926}, {244385,7734}, + {243913,8515}, {243397,9269}, {242838,9990}, {242237,10679}, {241598,11331}, {240922,11945}, + {240212,12518}, {239469,13050}, {238697,13537}, {237898,13979}, {237075,14374}, {236230,14721}, + {235366,15017}, {234487,15263}, {233595,15458}, {232693,15601}, {231784,15691}, {230872,15728}, + {229959,15712}, {229048,15643}, {228143,15521}, {227247,15347}, {226362,15122}, {225492,14845}, + {224639,14519}, {223806,14143}, {222997,13720}, {222214,13250}, {221459,12736}, {220736,12179}, + {220046,11581}, {219392,10944}, {218776,10270}, {218200,9561}, {217666,8820}, {217176,8050}, + {216732,7252}, {216334,6430}, {215986,5586}, {215860,5243}, {199380,5243}, {199051,6095}, + {198673,6926}, {198247,7734}, {197775,8515}, {197259,9269}, {196700,9990}, {196100,10679}, + {195460,11331}, {194784,11945}, {194074,12518}, {193332,13050}, {192559,13537}, {191760,13979}, + {190937,14374}, {190092,14721}, {189228,15017}, {188349,15263}, {187457,15458}, {186555,15601}, + {185646,15691}, {184734,15728}, {183821,15712}, {182910,15643}, {182005,15521}, {181109,15347}, + {180224,15122}, {179354,14845}, {178501,14519}, {177669,14143}, {176860,13720}, {176076,13250}, + {175322,12736}, {174598,12179}, {173908,11581}, {173254,10944}, {172638,10270}, {172062,9561}, + {171528,8820}, {171038,8050}, {170594,7252}, {170197,6430}, {169848,5586}, {169722,5243}, + {153243,5243}, {152913,6095}, {152535,6926}, {152110,7734}, {151638,8515}, {151121,9269}, + {150562,9990}, {149962,10679}, {149323,11331}, {148647,11945}, {147936,12518}, {147194,13050}, + {146422,13537}, {145623,13979}, {144799,14374}, {143954,14721}, {143091,15017}, {142211,15263}, + {141319,15458}, {140417,15601}, {139508,15691}, {138596,15728}, {137683,15712}, {136772,15643}, + {135867,15521}, {134971,15347}, {134086,15122}, {133216,14845}, {132363,14519}, {131531,14143}, + {130722,13720}, {129939,13250}, {129184,12736}, {128460,12179}, {127770,11581}, {127116,10944}, + {126500,10270}, {125924,9561}, {125390,8820}, {124901,8050}, {124456,7252}, {124059,6430}, + {123710,5586}, {123584,5243}, {107105,5243}, {106776,6095}, {106397,6926}, {105972,7734}, + {105500,8515}, {104983,9269}, {104424,9990}, {103824,10679}, {103185,11331}, {102509,11945}, + {101798,12518}, {101056,13050}, {100284,13537}, {99485,13979}, {98661,14374}, {97816,14721}, + {96953,15017}, {96073,15263}, {95181,15458}, {94279,15601}, {93371,15691}, {92458,15728}, + {91545,15712}, {90635,15643}, {89730,15521}, {88833,15347}, {87948,15122}, {87078,14845}, + {86225,14519}, {85393,14143}, {84584,13720}, {83801,13250}, {83046,12736}, {82323,12179}, + {81633,11581}, {80978,10944}, {80362,10270}, {79786,9561}, {79253,8820}, {78763,8050}, + {78318,7252}, {77921,6430}, {77572,5586}, {77446,5243}, {60967,5243}, {60638,6095}, + {60260,6926}, {59834,7734}, {59362,8515}, {58846,9269}, {58286,9990}, {57686,10679}, + {57047,11331}, {56371,11945}, {55661,12518}, {54918,13050}, {54146,13537}, {53347,13979}, + {52524,14374}, {51679,14721}, {50815,15017}, {49936,15263}, {49044,15458}, {48142,15601}, + {47233,15691}, {46320,15728}, {45407,15712}, {44497,15643}, {43592,15521}, {42695,15347}, + {41811,15122}, {40940,14845}, {40088,14519}, {39255,14143}, {38446,13720}, {37663,13250}, + {36908,12736}, {36185,12179}, {35495,11581}, {34841,10944}, {34225,10270}, {33649,9561}, + {33115,8820}, {32625,8050}, {32181,7252}, {31783,6430}, {31434,5586}, {31309,5243}, + {14829,5243}, {14501,6092}, {14125,6920}, {13701,7726}, {13231,8505}, {12717,9256}, + {12160,9976}, {11563,10662}, {10927,11313}, {10255,11926}, {9548,12499}, {8809,13031}, + {8041,13518}, {7245,13961}, {6426,14356}, {5585,14704}}, + + {{-478773,-478773}, {847875,-478773}, {847875,814320}, {-478773,814320}} }; + + Paths64 solution = InflatePaths(subject, -43.6e03, JoinType::Round, EndType::Polygon); + EXPECT_EQ(solution.size(), 2); +} + diff --git a/CSharp/Clipper2Lib/Clipper.Offset.cs b/CSharp/Clipper2Lib/Clipper.Offset.cs index d5984e22..d1ce9994 100644 --- a/CSharp/Clipper2Lib/Clipper.Offset.cs +++ b/CSharp/Clipper2Lib/Clipper.Offset.cs @@ -1,6 +1,6 @@ /******************************************************************************* * Author : Angus Johnson * -* Date : 9 September 2023 * +* Date : 16 September 2023 * * Website : http://www.angusj.com * * Copyright : Angus Johnson 2010-2023 * * Purpose : Path Offset (Inflate/Shrink) * @@ -469,9 +469,7 @@ private void OffsetPoint(Group group, Path64 path, int j, ref int k) return; } - if (cosA > 0.999) - DoMiter(group, path, j, k, cosA); - else if (cosA > -0.99 && (sinA * _groupDelta < 0)) + if (cosA > -0.99 && (sinA * _groupDelta < 0)) // test for concavity first (#593) { // is concave group.outPath.Add(GetPerpendic(path[j], _normals[k])); @@ -480,6 +478,8 @@ private void OffsetPoint(Group group, Path64 path, int j, ref int k) group.outPath.Add(path[j]); // (#405) group.outPath.Add(GetPerpendic(path[j], _normals[j])); } + else if (cosA > 0.999) + DoMiter(group, path, j, k, cosA); else if (_joinType == JoinType.Miter) { // miter unless the angle is so acute the miter would exceeds ML diff --git a/Delphi/Clipper2Lib/Clipper.Offset.pas b/Delphi/Clipper2Lib/Clipper.Offset.pas index 1214fa58..69fa73db 100644 --- a/Delphi/Clipper2Lib/Clipper.Offset.pas +++ b/Delphi/Clipper2Lib/Clipper.Offset.pas @@ -2,7 +2,7 @@ (******************************************************************************* * Author : Angus Johnson * -* Date : 9 September 2023 * +* Date : 16 September 2023 * * Website : http://www.angusj.com * * Copyright : Angus Johnson 2010-2023 * * Purpose : Path Offset (Inflate/Shrink) * @@ -892,9 +892,8 @@ procedure TClipperOffset.OffsetPoint(j: Integer; var k: integer); Exit; end; - if (cosA > 0.999) then // almost straight - less than 2.5 degree (#424, #526) - DoMiter(j, k, cosA) - else if (cosA > -0.99) and (sinA * fGroupDelta < 0) then + //test for concavity first (#593) + if (cosA > -0.99) and (sinA * fGroupDelta < 0) then begin // is concave AddPoint(GetPerpendic(fInPath[j], fNorms[k], fGroupDelta)); @@ -903,6 +902,9 @@ procedure TClipperOffset.OffsetPoint(j: Integer; var k: integer); AddPoint(fInPath[j]); // (#405) AddPoint(GetPerpendic(fInPath[j], fNorms[j], fGroupDelta)); end + else if (cosA > 0.999) then + // almost straight - less than 2.5 degree (#424, #526) + DoMiter(j, k, cosA) else if (fJoinType = jtMiter) then begin // miter unless the angle is so acute the miter would exceeds ML