Code

avoid code duplication, i.e. use sp_item_snappoints in the object-snapper.cpp
[inkscape.git] / src / sp-item-rm-unsatisfied-cns.cpp
2 #include <approx-equal.h>
3 #include <remove-last.h>
4 #include <sp-guide.h>
5 #include <sp-guide-constraint.h>
6 #include <sp-item.h>
7 using std::vector;
9 void sp_item_rm_unsatisfied_cns(SPItem &item)
10 {
11     if (item.constraints.empty()) {
12         return;
13     }
14     vector<NR::Point> snappoints;
15     sp_item_snappoints(&item, true, SnapPointsIter(snappoints));
16     for (unsigned i = item.constraints.size(); i--;) {
17         g_assert( i < item.constraints.size() );
18         SPGuideConstraint const &cn = item.constraints[i];
19         int const snappoint_ix = cn.snappoint_ix;
20         g_assert( snappoint_ix < int(snappoints.size()) );
21         if (!approx_equal(dot(cn.g->normal, snappoints[snappoint_ix]), cn.g->position)) {
22             remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix));
23             g_assert( i < item.constraints.size() );
24             vector<SPGuideConstraint>::iterator const ei(&item.constraints[i]);
25             item.constraints.erase(ei);
26         }
27     }
28 }
31 /*
32   Local Variables:
33   mode:c++
34   c-file-style:"stroustrup"
35   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
36   indent-tabs-mode:nil
37   fill-column:99
38   End:
39 */
40 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :