mirror of https://github.com/KLayout/klayout.git
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:
parent
8b010d61d2
commit
89cc79cbbc
|
|
@ -858,7 +858,7 @@ public:
|
||||||
coord_type distance (const db::point<C> &p) const
|
coord_type distance (const db::point<C> &p) const
|
||||||
{
|
{
|
||||||
// the distance is computed from
|
// the distance is computed from
|
||||||
// d = (a x b) / sqrt (a * a)
|
// d = (a x b) / |a|
|
||||||
// where b = p - p1, a = p2 - p1
|
// where b = p - p1, a = p2 - p1
|
||||||
if (is_degenerate ()) {
|
if (is_degenerate ()) {
|
||||||
// for safety handle this case - without a reasonable result
|
// for safety handle this case - without a reasonable result
|
||||||
|
|
@ -866,7 +866,7 @@ public:
|
||||||
} else {
|
} else {
|
||||||
// compute the distance as described above
|
// 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 ());
|
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
|
// and round
|
||||||
return coord_traits::rounded (d);
|
return coord_traits::rounded (d);
|
||||||
}
|
}
|
||||||
|
|
@ -929,7 +929,7 @@ public:
|
||||||
distance_type distance_abs (const db::point<C> &p) const
|
distance_type distance_abs (const db::point<C> &p) const
|
||||||
{
|
{
|
||||||
// the distance is computed from
|
// the distance is computed from
|
||||||
// d = (a x b) / sqrt (a * a)
|
// d = (a x b) / |a|
|
||||||
// where b = p - p1, a = p2 - p1
|
// where b = p - p1, a = p2 - p1
|
||||||
if (is_degenerate ()) {
|
if (is_degenerate ()) {
|
||||||
// for safety handle this case - without a reasonable result
|
// for safety handle this case - without a reasonable result
|
||||||
|
|
@ -937,7 +937,7 @@ public:
|
||||||
} else {
|
} else {
|
||||||
// compute the distance as described above
|
// 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 ());
|
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
|
// and round
|
||||||
return coord_traits::rounded_distance (d);
|
return coord_traits::rounded_distance (d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, 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, 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, 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, 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)");
|
EXPECT_EQ (smooth (p, 100, true).to_string (), "(0,0;0,1000;100,1000;100,1100;800,1100;800,1000;2000,1000;2000,0)");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)");
|
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)");
|
||||||
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue