~lib2geom-hackers/lib2geom/trunk

« back to all changes in this revision

Viewing changes to convex-hull.h

  • Committer: njh
  • Date: 2006-05-22 11:50:24 UTC
  • Revision ID: svn-v4:4601daaa-0314-0410-9a8b-c964a3c23b6b:trunk/lib2geom:1
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SEEN_Geom_CONVEX_HULL_H
 
2
#define SEEN_Geom_CONVEX_HULL_H
 
3
 
 
4
/* ex:set et ts=4 sw=4: */
 
5
 
 
6
/*
 
7
 * A class representing the convex hull of a set of points.
 
8
 *
 
9
 * Copyright 2004  MenTaLguY <mental@rydia.net>
 
10
 *
 
11
 * This code is licensed under the GNU GPL; see COPYING for more information.
 
12
 */
 
13
 
 
14
#include <libnr/rect.h>
 
15
 
 
16
namespace Geom {
 
17
 
 
18
class ConvexHull {
 
19
public:
 
20
        explicit ConvexHull(Point const &p) : _bounds(p, p) {}
 
21
 
 
22
    Point midpoint() const {
 
23
        return _bounds.midpoint();
 
24
    }
 
25
 
 
26
        void add(Point const &p) {
 
27
                _bounds.expandTo(p);
 
28
        }
 
29
        void add(Rect const &p) {
 
30
                // Note that this is a hack.  when convexhull actually works
 
31
                // you will need to add all four points.
 
32
                _bounds.expandTo(p.min());
 
33
                _bounds.expandTo(p.max());
 
34
        }
 
35
        void add(ConvexHull const &h) {
 
36
                _bounds.expandTo(h._bounds);
 
37
        }
 
38
                
 
39
        Rect const &bounds() const {
 
40
                return _bounds;
 
41
        }
 
42
        
 
43
private:
 
44
        Rect _bounds;
 
45
};
 
46
 
 
47
} /* namespace Geom */
 
48
 
 
49
#endif