Skip to content

Commit 56ff29f

Browse files
Merge pull request #2213 from KLayout/bugfix/issue-2210
Fixing issue #2210 (snap behavior for auto-measure)
2 parents f61e811 + 131a7bd commit 56ff29f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/laybasic/laybasic/laySnap.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class ContourFinder
262262
* "vertex_mode" is:
263263
* 0: no snapping to vertexes
264264
* 1: snapping to edge vertexes
265-
* 2: also snapping to centers
265+
* 2: snapping to edge vertexes with high prio and also snapping to centers
266266
*/
267267
ContourFinder (const db::DPoint &original, const db::DVector &grid, const std::vector <db::DEdge> &cutlines, int vertex_mode = 2, bool directed = false)
268268
: m_any (false), m_any_exact (false),
@@ -449,8 +449,11 @@ class ContourFinder
449449
void
450450
find_closest_exact (const db::DPoint &p, const db::DEdge &e)
451451
{
452-
bool was_vertex = m_edge1_exact.is_degenerate () && m_edge2_exact.is_degenerate ();
453-
bool is_vertex = e.is_degenerate ();
452+
// NOTE: in vertex mode 2, vertices have higher priority than edges, so we capture the nature of the
453+
// object to snap to. In vertex mode 1, "was_vertex" and "is_vertex" is always false and priority
454+
// is given by distance. That mode is used in measurements (aka obj_snap2).
455+
bool was_vertex = m_vertex_mode > 1 && m_edge1_exact.is_degenerate () && m_edge2_exact.is_degenerate ();
456+
bool is_vertex = m_vertex_mode > 1 && e.is_degenerate ();
454457

455458
if (! m_any_exact || (! (was_vertex && ! is_vertex) && (m_original.distance (p) < m_original.distance (m_closest_exact) || (! was_vertex && is_vertex)))) {
456459

@@ -473,8 +476,11 @@ class ContourFinder
473476
void
474477
find_closest (const db::DPoint &p, const db::DEdge &e)
475478
{
476-
bool was_vertex = m_edge1.is_degenerate () && m_edge2.is_degenerate ();
477-
bool is_vertex = e.is_degenerate ();
479+
// NOTE: in vertex mode 2, vertices have higher priority than edges, so we capture the nature of the
480+
// object to snap to. In vertex mode 1, "was_vertex" and "is_vertex" is always false and priority
481+
// is given by distance. That mode is used in measurements (aka obj_snap2).
482+
bool was_vertex = m_vertex_mode > 1 && m_edge1.is_degenerate () && m_edge2.is_degenerate ();
483+
bool is_vertex = m_vertex_mode > 1 && e.is_degenerate ();
478484

479485
if (! m_any || (! (was_vertex && ! is_vertex) && (m_original.distance (p) < m_original.distance (m_closest) || (! was_vertex && is_vertex)))) {
480486

0 commit comments

Comments
 (0)