Logo Search packages:      
Sourcecode: inkscape version File versions

GSList* unclump_remove_behind ( SPItem item,
SPItem closest,
GSList *  rest 
)

Removes from the rest list those items that are "behind" closest as seen from item, i.e. those on the other side of the line through closest perpendicular to the direction from item to closest. Returns a newly created list which must be freed.

Definition at line 240 of file unclump.cpp.

References unclump_center().

Referenced by unclump().

{
    Geom::Point it = unclump_center (item);
    Geom::Point p1 = unclump_center (closest);

    // perpendicular through closest to the direction to item:
    Geom::Point perp = Geom::rot90(it - p1);
    Geom::Point p2 = p1 + perp;

    // get the standard Ax + By + C = 0 form for p1-p2:
    double A = p1[Geom::Y] - p2[Geom::Y];
    double B = p2[Geom::X] - p1[Geom::X];
    double C = p2[Geom::Y] * p1[Geom::X] - p1[Geom::Y] * p2[Geom::X];

    // substitute the item into it:
    double val_item = A * it[Geom::X] + B * it[Geom::Y] + C;

    GSList *out = NULL;

    for (GSList *i = rest; i != NULL; i = i->next) {
        SPItem *other = SP_ITEM (i->data);

        if (other == item)
            continue;

        Geom::Point o = unclump_center (other);
        double val_other = A * o[Geom::X] + B * o[Geom::Y] + C;

        if (val_item * val_other <= 1e-6) {
            // different signs, which means item and other are on the different sides of p1-p2 line; skip
        } else {
            out = g_slist_prepend (out, other);
        }
    }

    return out;
}


Generated by  Doxygen 1.6.0   Back to index