What's wrong with this function for moving nodes?
void move_paths_nodes_to_closest_points(Geom::PathVector &paths, const std::vector<Geom::Point> &points)
{
// not considering edge cases, efficiency, nothing. just want it to work for now.
for (auto &path : paths) {
std::vector<Geom::Curve*> curves;
for (int curve_idx = 0; curve_idx < path.size(); curve_idx++) {
// FIXME are we leaking memory here? should it be deleted after being used?
Geom::Curve *curve_ptr = path.at(curve_idx).duplicate();
auto &curve = *curve_ptr;
Geom::Point initial = curve.initialPoint();
Geom::Point closest = get_closest(initial, points);
curve.setInitial(closest);
if (curve_idx) {
curves[curve_idx-1]->setFinal(closest);
}
curves.push_back(curve_ptr);
}
curves.back()->setFinal(curves[0]->initialPoint());
// FIXME ideally would love to change the curves in the path directly
// but that doesn't work... the program crashes saying that the path
// is not contiguous. This implies that this way is wrong anyways. fix it.
Geom::Path p;
for (auto &curve : curves) {
p.append(curve);
}
path = p;
}
}
What's being done wrong here?
this function takes a PathVector
and a set of points and is supposed to move each node from the PathVector
to the nearest point in the provided set of points.
When I use it, I get this result:
Screencast_2021-05-25_01_20_08
I replaced the behavior of Cut Path
to accept 2 shapes, convert both of them to PathVectors
, then call this function with one as the PathVector
argument and the points of the other PathVector
as the set of points.
After this, draws the result PathVector
.
this presumably should draw a duplicate of one of them. but the result is not what's expected.