mirror of https://github.com/KLayout/klayout.git
Partial edit mode fixes
- do not remove last point of closed paths - fixed removal of redundant points in polygon/path edit - on-grid point insertion in paths and polygons for skew angle edges
This commit is contained in:
parent
2e4153c04a
commit
4afa029297
|
|
@ -243,9 +243,14 @@ insert_point_path (const db::Path &p, const std::set<EdgeWithIndex> &sel, db::Po
|
||||||
ctr.push_back (p1);
|
ctr.push_back (p1);
|
||||||
if (! found && sel.find (EdgeWithIndex (db::Edge (p1, p2), n, n + 1, 0)) != sel.end ()) {
|
if (! found && sel.find (EdgeWithIndex (db::Edge (p1, p2), n, n + 1, 0)) != sel.end ()) {
|
||||||
// project the point onto the edge
|
// project the point onto the edge
|
||||||
std::pair <bool, db::Point> projected = db::Edge (p1, p2).projected (ins);
|
db::Edge e (p1, p2);
|
||||||
|
std::pair <bool, db::Point> projected = e.projected (ins);
|
||||||
if (projected.first) {
|
if (projected.first) {
|
||||||
ins = projected.second;
|
if (e.is_ortho ()) {
|
||||||
|
// NOTE: for skew edges we use the original point as the projected one usually
|
||||||
|
// is off-grid.
|
||||||
|
ins = projected.second;
|
||||||
|
}
|
||||||
ctr.push_back (ins);
|
ctr.push_back (ins);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
@ -262,22 +267,28 @@ insert_point_path (const db::Path &p, const std::set<EdgeWithIndex> &sel, db::Po
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remove_redundant_points (std::vector <db::Point> &ctr)
|
remove_redundant_points (std::vector <db::Point> &ctr, bool cyclic)
|
||||||
{
|
{
|
||||||
// compress contour (remove redundant points)
|
// compress contour (remove redundant points)
|
||||||
// and assign to path
|
// and assign to path
|
||||||
|
|
||||||
std::vector<db::Point>::iterator wp = ctr.begin ();
|
std::vector<db::Point>::iterator wp = ctr.begin ();
|
||||||
std::vector<db::Point>::const_iterator rp = ctr.begin ();
|
std::vector<db::Point>::const_iterator rp = ctr.begin ();
|
||||||
db::Point pm1 = *rp;
|
db::Point pm1;
|
||||||
if (wp != ctr.end ()) {
|
if (rp != ctr.end ()) {
|
||||||
++wp;
|
if (cyclic) {
|
||||||
++rp;
|
pm1 = ctr.back ();
|
||||||
|
} else {
|
||||||
|
pm1 = ctr.front ();
|
||||||
|
++wp;
|
||||||
|
++rp;
|
||||||
|
}
|
||||||
while (rp != ctr.end ()) {
|
while (rp != ctr.end ()) {
|
||||||
db::Point p0 = *rp;
|
db::Point p0 = *rp;
|
||||||
if (p0 != pm1) {
|
if (p0 != pm1) {
|
||||||
*wp++ = p0;
|
*wp++ = p0;
|
||||||
}
|
}
|
||||||
|
pm1 = p0;
|
||||||
++rp;
|
++rp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -304,7 +315,7 @@ del_points_path (const db::Path &p, const std::set<EdgeWithIndex> &sel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_redundant_points (ctr);
|
remove_redundant_points (ctr, false);
|
||||||
new_path.assign (ctr.begin (), ctr.end ());
|
new_path.assign (ctr.begin (), ctr.end ());
|
||||||
|
|
||||||
return new_path;
|
return new_path;
|
||||||
|
|
@ -357,7 +368,7 @@ modify_path (db::Path &p, const std::map <PointWithIndex, db::Point> &new_points
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compress) {
|
if (compress) {
|
||||||
remove_redundant_points (ctr);
|
remove_redundant_points (ctr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
p.assign (ctr.begin (), ctr.end ());
|
p.assign (ctr.begin (), ctr.end ());
|
||||||
|
|
@ -384,10 +395,14 @@ insert_point_poly (const db::Polygon &p, const std::set<EdgeWithIndex> &sel, db:
|
||||||
|
|
||||||
ctr.push_back ((*e).p1 ());
|
ctr.push_back ((*e).p1 ());
|
||||||
if (! found && sel.find (EdgeWithIndex (*e, n, nn, c)) != sel.end ()) {
|
if (! found && sel.find (EdgeWithIndex (*e, n, nn, c)) != sel.end ()) {
|
||||||
// project the point onto the edge
|
// project the point onto the edge - use the first edge the point projects to
|
||||||
std::pair <bool, db::Point> projected = (*e).projected (ins);
|
std::pair <bool, db::Point> projected = (*e).projected (ins);
|
||||||
if (projected.first) {
|
if (projected.first) {
|
||||||
ins = projected.second;
|
if ((*e).is_ortho ()) {
|
||||||
|
// NOTE: for skew edges we use the original point as the projected one usually
|
||||||
|
// is off-grid.
|
||||||
|
ins = projected.second;
|
||||||
|
}
|
||||||
ctr.push_back (ins);
|
ctr.push_back (ins);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
@ -397,7 +412,7 @@ insert_point_poly (const db::Polygon &p, const std::set<EdgeWithIndex> &sel, db:
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
||||||
remove_redundant_points (ctr);
|
remove_redundant_points (ctr, true);
|
||||||
|
|
||||||
new_poly = p;
|
new_poly = p;
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
|
|
@ -433,7 +448,7 @@ del_points_poly (const db::Polygon &p, const std::set<EdgeWithIndex> &sel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_redundant_points (ctr);
|
remove_redundant_points (ctr, true);
|
||||||
|
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
new_poly.assign_hull (ctr.begin (), ctr.end (), false /*compress*/);
|
new_poly.assign_hull (ctr.begin (), ctr.end (), false /*compress*/);
|
||||||
|
|
@ -495,7 +510,7 @@ modify_polygon (db::Polygon &p,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compress) {
|
if (compress) {
|
||||||
remove_redundant_points (ctr);
|
remove_redundant_points (ctr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue