mirror of https://github.com/KLayout/klayout.git
Refinement of snap, fixed tests
This commit is contained in:
parent
ea3e1e98b7
commit
25d396023a
|
|
@ -258,13 +258,18 @@ class ContourFinder
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor
|
* @brief Constructor
|
||||||
|
*
|
||||||
|
* "vertex_mode" is:
|
||||||
|
* 0: no snapping to vertexes
|
||||||
|
* 1: snapping to edge vertexes
|
||||||
|
* 2: also snapping to centers
|
||||||
*/
|
*/
|
||||||
ContourFinder (const db::DPoint &original, const db::DVector &grid, const std::vector <db::DEdge> &cutlines, bool with_vertex = true, bool directed = false)
|
ContourFinder (const db::DPoint &original, const db::DVector &grid, const std::vector <db::DEdge> &cutlines, int vertex_mode = 2, bool directed = false)
|
||||||
: m_any (false), m_any_exact (false),
|
: m_any (false), m_any_exact (false),
|
||||||
m_original (original), m_is_vertex (false), m_is_vertex_exact (false),
|
m_original (original), m_is_vertex (false), m_is_vertex_exact (false),
|
||||||
m_tests (10000 /* max. number of tests, TODO: make variable? */),
|
m_tests (10000 /* max. number of tests, TODO: make variable? */),
|
||||||
mp_layout (0), m_cutlines (cutlines), mp_prop_sel (0), m_inv_prop_sel (false),
|
mp_layout (0), m_cutlines (cutlines), mp_prop_sel (0), m_inv_prop_sel (false),
|
||||||
m_with_vertex (with_vertex), m_directed (directed)
|
m_vertex_mode (vertex_mode), m_directed (directed)
|
||||||
{
|
{
|
||||||
m_projection_constraint = ! m_cutlines.empty ();
|
m_projection_constraint = ! m_cutlines.empty ();
|
||||||
|
|
||||||
|
|
@ -491,7 +496,7 @@ private:
|
||||||
|
|
||||||
void closest (const db::DPoint &p)
|
void closest (const db::DPoint &p)
|
||||||
{
|
{
|
||||||
if (! m_with_vertex) {
|
if (m_vertex_mode == 0) {
|
||||||
|
|
||||||
// Only edges are considered for snapping.
|
// Only edges are considered for snapping.
|
||||||
|
|
||||||
|
|
@ -668,7 +673,9 @@ private:
|
||||||
test_edge_with_center (t * db::Edge (db::Point (box.right (), box.bottom ()), box.p1 ()));
|
test_edge_with_center (t * db::Edge (db::Point (box.right (), box.bottom ()), box.p1 ()));
|
||||||
|
|
||||||
// test for box center
|
// test for box center
|
||||||
test_edge (t * db::Edge (box.center (), box.center ()));
|
if (m_vertex_mode > 1) {
|
||||||
|
test_edge (t * db::Edge (box.center (), box.center ()));
|
||||||
|
}
|
||||||
|
|
||||||
} else if (shape->is_point ()) {
|
} else if (shape->is_point ()) {
|
||||||
|
|
||||||
|
|
@ -710,7 +717,7 @@ private:
|
||||||
void
|
void
|
||||||
test_edge_with_center (const db::DEdge &edg)
|
test_edge_with_center (const db::DEdge &edg)
|
||||||
{
|
{
|
||||||
if (m_with_vertex && ! edg.is_degenerate ()) {
|
if (m_vertex_mode > 1 && ! edg.is_degenerate ()) {
|
||||||
|
|
||||||
db::DPoint c = edg.p1 () + (edg.p2 () - edg.p1 ()) * 0.5;
|
db::DPoint c = edg.p1 () + (edg.p2 () - edg.p1 ()) * 0.5;
|
||||||
|
|
||||||
|
|
@ -726,7 +733,7 @@ private:
|
||||||
void
|
void
|
||||||
test_edge (const db::DEdge &edg)
|
test_edge (const db::DEdge &edg)
|
||||||
{
|
{
|
||||||
if (m_with_vertex) {
|
if (m_vertex_mode > 0) {
|
||||||
|
|
||||||
// vertex snap is just annoying when trying to measure the width of simulation contours ..
|
// vertex snap is just annoying when trying to measure the width of simulation contours ..
|
||||||
// But: when measuring corner-to-corner distances it is very valuable ..
|
// But: when measuring corner-to-corner distances it is very valuable ..
|
||||||
|
|
@ -761,7 +768,7 @@ private:
|
||||||
const std::set<db::properties_id_type> *mp_prop_sel;
|
const std::set<db::properties_id_type> *mp_prop_sel;
|
||||||
bool m_inv_prop_sel;
|
bool m_inv_prop_sel;
|
||||||
bool m_projection_constraint;
|
bool m_projection_constraint;
|
||||||
bool m_with_vertex;
|
int m_vertex_mode;
|
||||||
bool m_directed;
|
bool m_directed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -836,7 +843,7 @@ do_obj_snap2 (lay::LayoutViewBase *view, const db::DPoint &pt1, const db::DPoint
|
||||||
db::DPoint dp1 (pt1);
|
db::DPoint dp1 (pt1);
|
||||||
db::DPoint dp2 (pt2);
|
db::DPoint dp2 (pt2);
|
||||||
|
|
||||||
ContourFinder finder (dp1, grid, cutlines, cutlines.empty () /*vertex snap on "any direction"*/);
|
ContourFinder finder (dp1, grid, cutlines, cutlines.empty () ? 1 : 0 /*vertex snap on "any direction", edge vertexes*/);
|
||||||
|
|
||||||
double sr = min_search_range;
|
double sr = min_search_range;
|
||||||
while (sr < max_search_range + 1e-6) {
|
while (sr < max_search_range + 1e-6) {
|
||||||
|
|
@ -880,7 +887,7 @@ do_obj_snap2 (lay::LayoutViewBase *view, const db::DPoint &pt1, const db::DPoint
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContourFinder finder2 (dp2, grid, cl, false /*no vertex snap*/, true /*directional cutlines*/);
|
ContourFinder finder2 (dp2, grid, cl, 0 /*no vertex snap*/, true /*directional cutlines*/);
|
||||||
|
|
||||||
double sr2 = min_search_range;
|
double sr2 = min_search_range;
|
||||||
while (sr2 < max_search_range + 1e-6) {
|
while (sr2 < max_search_range + 1e-6) {
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ TEST(1)
|
||||||
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectUnspecific); // center point of edge
|
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectUnspecific); // center point of edge
|
||||||
EXPECT_EQ (res.snapped_point.to_string (), "0.5,0.5");
|
EXPECT_EQ (res.snapped_point.to_string (), "0.5,0.5");
|
||||||
|
|
||||||
res = lay::obj_snap (&view, db::DPoint (0.485, 0.505), db::DVector (0.01, 0.01), 0.1);
|
res = lay::obj_snap (&view, db::DPoint (0.385, 0.605), db::DVector (0.01, 0.01), 0.1);
|
||||||
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectEdge);
|
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectEdge);
|
||||||
EXPECT_EQ (res.snapped_point.to_string (), "0.49,0.51");
|
EXPECT_EQ (res.snapped_point.to_string (), "0.39,0.61");
|
||||||
EXPECT_EQ (res.object_ref.to_string (), "(0,1;1,0)");
|
EXPECT_EQ (res.object_ref.to_string (), "(0,1;1,0)");
|
||||||
|
|
||||||
res = lay::obj_snap (&view, db::DPoint (0.205, 0.215), db::DVector (0.01, 0.025), 0.1);
|
res = lay::obj_snap (&view, db::DPoint (0.205, 0.215), db::DVector (0.01, 0.025), 0.1);
|
||||||
|
|
@ -87,7 +87,7 @@ TEST(1)
|
||||||
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectVertex);
|
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectVertex);
|
||||||
EXPECT_EQ (res.snapped_point.to_string (), "0,1");
|
EXPECT_EQ (res.snapped_point.to_string (), "0,1");
|
||||||
|
|
||||||
res = lay::obj_snap (&view, db::DPoint (1.000, 0.605), db::DPoint (0.405, 0.600), db::DVector (), lay::AC_Horizontal, 0.1);
|
res = lay::obj_snap (&view, db::DPoint (1.000, 0.605), db::DPoint (0.405, 0.600), db::DVector (), lay::AC_Horizontal, 0.05);
|
||||||
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectEdge);
|
EXPECT_EQ (res.object_snap, lay::PointSnapToObjectResult::ObjectEdge);
|
||||||
EXPECT_EQ (res.snapped_point.to_string (), "0.395,0.605");
|
EXPECT_EQ (res.snapped_point.to_string (), "0.395,0.605");
|
||||||
|
|
||||||
|
|
@ -136,8 +136,12 @@ TEST(1)
|
||||||
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0.355,0.645;0,0.29)");
|
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0.355,0.645;0,0.29)");
|
||||||
|
|
||||||
res2 = lay::obj_snap2 (&view, db::DPoint (0.5, 0.5), db::DVector (), 0.005, 1.0);
|
res2 = lay::obj_snap2 (&view, db::DPoint (0.5, 0.5), db::DVector (), 0.005, 1.0);
|
||||||
|
EXPECT_EQ (res2.any, false); // on edge -> measurement chooses wrong direction
|
||||||
|
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0;0,0)");
|
||||||
|
|
||||||
|
res2 = lay::obj_snap2 (&view, db::DPoint (0.495, 0.495), db::DVector (), 0.005, 1.0);
|
||||||
EXPECT_EQ (res2.any, true);
|
EXPECT_EQ (res2.any, true);
|
||||||
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0.5,0.5;0.5,0.5)");
|
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0.5,0.5;0,0)");
|
||||||
|
|
||||||
res2 = lay::obj_snap2 (&view, db::DPoint (0.6, 0.4), db::DVector (), 0.005, 1.0);
|
res2 = lay::obj_snap2 (&view, db::DPoint (0.6, 0.4), db::DVector (), 0.005, 1.0);
|
||||||
EXPECT_EQ (res2.any, false);
|
EXPECT_EQ (res2.any, false);
|
||||||
|
|
@ -145,7 +149,7 @@ TEST(1)
|
||||||
|
|
||||||
res2 = lay::obj_snap2 (&view, db::DPoint (0.005, 0.5), db::DVector (), 0.005, 1.0);
|
res2 = lay::obj_snap2 (&view, db::DPoint (0.005, 0.5), db::DVector (), 0.005, 1.0);
|
||||||
EXPECT_EQ (res2.any, true);
|
EXPECT_EQ (res2.any, true);
|
||||||
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0.5;0,0.5)");
|
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0.5;0.5,0.5)");
|
||||||
|
|
||||||
res2 = lay::obj_snap2 (&view, db::DPoint (0.005, 0.4), db::DVector (), 0.005, 1.0);
|
res2 = lay::obj_snap2 (&view, db::DPoint (0.005, 0.4), db::DVector (), 0.005, 1.0);
|
||||||
EXPECT_EQ (res2.any, true);
|
EXPECT_EQ (res2.any, true);
|
||||||
|
|
@ -156,10 +160,6 @@ TEST(1)
|
||||||
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0;0,0)");
|
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0;0,0)");
|
||||||
|
|
||||||
res2 = lay::obj_snap2 (&view, db::DPoint (-0.2, 0.5), db::DVector (), 0.005, 1.0);
|
res2 = lay::obj_snap2 (&view, db::DPoint (-0.2, 0.5), db::DVector (), 0.005, 1.0);
|
||||||
EXPECT_EQ (res2.any, true);
|
|
||||||
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0.5;0,0.5)");
|
|
||||||
|
|
||||||
res2 = lay::obj_snap2 (&view, db::DPoint (-0.2, 0.4), db::DVector (), 0.005, 1.0);
|
|
||||||
EXPECT_EQ (res2.any, false);
|
EXPECT_EQ (res2.any, false);
|
||||||
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0;0,0)");
|
EXPECT_EQ (db::DEdge (res2.first, res2.second).to_string (), "(0,0;0,0)");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue