Modified edge transformation to maintain the orientation paradigm

When the transformation is mirroring, edges now swap their
points to maintain the right-is-inside paradigm.
This commit is contained in:
Matthias Koefferlein 2019-02-10 16:03:46 +01:00
parent a14ca01bac
commit a81a8cdbc8
4 changed files with 24 additions and 4 deletions

View File

@ -336,7 +336,14 @@ public:
template <class Tr>
edge<C> &transform (const Tr &t)
{
*this = edge<C> (t * m_p1, t * m_p2);
if (t.is_mirror ()) {
// NOTE: in case of mirroring transformations we swap p1 and p2. The reasoning is that
// this way we maintain the orientation semantics: "right" of the edge is "inside" of
// an area.
*this = edge<C> (t * m_p2, t * m_p1);
} else {
*this = edge<C> (t * m_p1, t * m_p2);
}
return *this;
}
@ -353,7 +360,14 @@ public:
template <class Tr>
edge<typename Tr::target_coord_type> transformed (const Tr &t) const
{
return edge<typename Tr::target_coord_type> (t * m_p1, t * m_p2);
if (t.is_mirror ()) {
// NOTE: in case of mirroring transformations we swap p1 and p2. The reasoning is that
// this way we maintain the orientation semantics: "right" of the edge is "inside" of
// an area.
return edge<typename Tr::target_coord_type> (t * m_p2, t * m_p1);
} else {
return edge<typename Tr::target_coord_type> (t * m_p1, t * m_p2);
}
}
/**
@ -914,7 +928,7 @@ public:
}
/**
* @brief Swap the points of the edge
* @brief Swaps the points of the edge
*/
edge<C> &swap_points ()
{

View File

@ -29,6 +29,7 @@
TEST(1)
{
db::Edge e (0, 0, 100, 200);
db::Edge ee;
db::Edge empty;
EXPECT_EQ (empty.is_degenerate (), true);
@ -53,6 +54,12 @@ TEST(1)
EXPECT_EQ (e.to_string (), "(0,0;100,200)");
EXPECT_EQ (e.swapped_points ().to_string (), "(100,200;0,0)");
EXPECT_EQ (e.to_string (), "(0,0;100,200)");
EXPECT_EQ (e.transformed (db::Trans (1)).to_string (), "(0,0;-200,100)");
EXPECT_EQ (e.transformed (db::Trans (5)).to_string (), "(200,100;0,0)"); // mirroring transformations swap points
ee = e;
ee.transform (db::Trans (5));
EXPECT_EQ (ee.to_string (), "(200,100;0,0)");
EXPECT_EQ (e.swapped_points ().to_string (), "(100,200;0,0)");
e.swap_points ();
EXPECT_EQ (e.to_string (), "(100,200;0,0)");
@ -66,7 +73,6 @@ TEST(1)
EXPECT_EQ (e.shifted (2).to_string (), "(0,4;10,12)");
EXPECT_EQ (e.shifted (1).to_string (), "(0,3;10,11)");
db::Edge ee;
ee = e;
ee.shift (2);
EXPECT_EQ (ee.to_string (), "(0,4;10,12)");

BIN
testdata/algo/deep_edges_au1.gds vendored Normal file

Binary file not shown.

BIN
testdata/algo/deep_edges_au2.gds vendored Normal file

Binary file not shown.