Logo Search packages:      
Sourcecode: inkscape version File versions

int sp_repr_compare_position ( Inkscape::XML::Node first,
Inkscape::XML::Node second 

Works for different-parent objects, so long as they have a common ancestor. Return value: 0 positions are equivalent 1 first object's position is greater than the second -1 first object's position is less than the second

Rewrite this function's description to be understandable

Definition at line 358 of file repr-util.cpp.

References Inkscape::XML::Node::position(), and sp_repr_parent().

Referenced by sp_object_compare_position().

    int p1, p2;
    if (sp_repr_parent(first) == sp_repr_parent(second)) {
        /* Basic case - first and second have same parent */
        p1 = first->position();
        p2 = second->position();
    } else {
        /* Special case - the two objects have different parents.  They
           could be in different groups or on different layers for
           instance. */

        // Find the lowest common ancestor(LCA)
        Inkscape::XML::Node *ancestor = LCA(first, second);
        g_assert(ancestor != NULL);

        if (ancestor == first) {
            return 1;
        } else if (ancestor == second) {
            return -1;
        } else {
            Inkscape::XML::Node const *to_first = AncetreFils(first, ancestor);
            Inkscape::XML::Node const *to_second = AncetreFils(second, ancestor);
            g_assert(sp_repr_parent(to_second) == sp_repr_parent(to_first));
            p1 = to_first->position();
            p2 = to_second->position();

    if (p1 > p2) return 1;
    if (p1 < p2) return -1;
    return 0;

    /* effic: Assuming that the parent--child relationship is consistent
       (i.e. that the parent really does contain first and second among
       its list of children), it should be equivalent to walk along the
       children and see which we encounter first (returning 0 iff first
       == second).
       Given that this function is used solely for sorting, we can use a
       similar approach to do the sort: gather the things to be sorted,
       into an STL vector (to allow random access and faster
       traversals).  Do a single pass of the parent's children; for each
       child, do a pass on whatever items in the vector we haven't yet
       encountered.  If the child is found, then swap it to the
       beginning of the yet-unencountered elements of the vector.
       Continue until no more than one remains unencountered.  --
       pjrm */

Generated by  Doxygen 1.6.0   Back to index