Fixing issue #2208

Problem was rounding that lead to incorrect distance measurements
between parallel edges when one edge was very short.
This commit is contained in:
Matthias Koefferlein
2025-11-08 23:45:09 +01:00
parent 8b010d61d2
commit 89cc79cbbc
14 changed files with 26 additions and 5 deletions
+4 -4
View File
@@ -858,7 +858,7 @@ public:
coord_type distance (const db::point<C> &p) const
{
// the distance is computed from
// d = (a x b) / sqrt (a * a)
// d = (a x b) / |a|
// where b = p - p1, a = p2 - p1
if (is_degenerate ()) {
// for safety handle this case - without a reasonable result
@@ -866,7 +866,7 @@ public:
} else {
// compute the distance as described above
area_type axb = coord_traits::vprod (m_p2.x (), m_p2.y (), p.x (), p.y (), m_p1.x (), m_p1.y ());
double d = double (axb) / double (length ());
double d = double (axb) / double_length ();
// and round
return coord_traits::rounded (d);
}
@@ -929,7 +929,7 @@ public:
distance_type distance_abs (const db::point<C> &p) const
{
// the distance is computed from
// d = (a x b) / sqrt (a * a)
// d = (a x b) / |a|
// where b = p - p1, a = p2 - p1
if (is_degenerate ()) {
// for safety handle this case - without a reasonable result
@@ -937,7 +937,7 @@ public:
} else {
// compute the distance as described above
area_type axb = coord_traits::vprod (m_p2.x (), m_p2.y (), p.x (), p.y (), m_p1.x (), m_p1.y ());
double d = fabs (double (axb)) / double (length ());
double d = fabs (double (axb)) / double_length ();
// and round
return coord_traits::rounded_distance (d);
}
+1 -1
View File
@@ -1327,7 +1327,7 @@ TEST(105)
EXPECT_EQ (smooth (p, 0, false).to_string (), "(0,0;0,1000;100,1000;100,1100;800,1100;800,1000;2000,1000;2000,0)");
EXPECT_EQ (smooth (p, 50, false).to_string (), "(0,0;0,1000;100,1000;100,1100;800,1100;800,1000;2000,1000;2000,0)");
EXPECT_EQ (smooth (p, 80, false).to_string (), "(0,0;0,1000;100,1100;800,1100;800,1000;2000,1000;2000,0)");
EXPECT_EQ (smooth (p, 90, false).to_string (), "(0,0;100,1100;800,1100;800,1000;2000,1000;2000,0)");
EXPECT_EQ (smooth (p, 90, false).to_string (), "(0,0;0,1000;800,1100;800,1000;2000,1000;2000,0)");
EXPECT_EQ (smooth (p, 100, false).to_string (), "(0,0;0,1000;2000,1000;2000,0)");
EXPECT_EQ (smooth (p, 100, true).to_string (), "(0,0;0,1000;100,1000;100,1100;800,1100;800,1000;2000,1000;2000,0)");
}
+21
View File
@@ -2998,3 +2998,24 @@ TEST(issue_909)
EXPECT_EQ (r.to_string (), "(0,0;0,100;100,100;100,0);(0,0;0,300;200,300;200,0)");
}
TEST(issue_2208)
{
db::Point points[] = {
db::Point (-36, -2698),
db::Point (-3226, 492),
db::Point (-2871, 847),
db::Point (-746, -1278),
db::Point (-751, -1283),
db::Point (-746, -1288),
db::Point (-741, -1283),
db::Point (319, -2343)
};
db::Region r;
db::Polygon p;
p.assign_hull (points + 0, points + sizeof (points) / sizeof (points [0]));
r.insert (p);
db::EdgePairs ep = r.width_check (500);
EXPECT_EQ (ep.to_string (), "(-1046,-1688;-1151,-1583)|(-751,-1283;-746,-1288)");
}