summaryrefslogtreecommitdiffstats
path: root/src/object/algorithms/bboxsort.h
blob: 6d15c123f8db09f5e730e8da391547b3913517f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_BBOXSORT_H
#define SEEN_BBOXSORT_H

/** @file
 * @brief Simple helper class for sorting objects based on their bounding boxes.
 */
/* Authors:
 *   MenTaLguY
 *   Dmitry Kirsanov
 *   Krzysztof Kosiński
 *
 * Copyright (C) 2007-2012 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
/*
 * Previously part of the Align and Distribute dialog.
 */

class BBoxSort {

public:
    BBoxSort(SPItem *item, Geom::Rect const &bounds, Geom::Dim2 orientation, double begin, double end)
        : item(item)
        , bbox(bounds)
    {
        anchor = begin * bbox.min()[orientation] + end * bbox.max()[orientation];
    }

    BBoxSort(const BBoxSort &rhs) = default; // Should really be vector of pointers to avoid copying class when sorting.
    ~BBoxSort() = default;

    double anchor = 0.0;
    SPItem* item = nullptr;
    Geom::Rect bbox;
};

static bool operator< (const BBoxSort &a, const BBoxSort &b) {
    return a.anchor < b.anchor;
}

#endif // SEEN_BBOXSORT_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :