root/trunk/clustr/polygon.cpp

Revision 617, 1.7 kB (checked in by aaron, 8 months ago)

update to 0.21: patch from mattb to make multi-tags files work

Line 
1 /*
2 Clustr.  Copyright (c) 2007-2009 Yahoo! Inc.
3
4 All rights reserved.  This code is free software; you can redistribute it
5 and/or modify it under the terms of the GNU General Public License (GPL),
6 version 2 only.  This code is distributed WITHOUT ANY WARRANTY, whether
7 express or implied. See the GNU GPL for more details
8 (http://www.gnu.org/licenses/gpl.html)
9
10 AS A SPECIAL EXCEPTION, YOU HAVE PERMISSION TO LINK THIS PROGRAM WITH THE
11 CGAL LIBRARY AND DISTRIBUTE EXECUTABLES, AS LONG AS YOU FOLLOW THE REQUIREMENTS
12 OF THE GNU GPL VERSION 2 IN REGARD TO ALL OF THE SOFTWARE IN THE EXECUTABLE
13 ASIDE FROM CGAL.
14 */
15
16 # include <numeric>
17 # include <cmath>
18 # include "clustr.h"
19
20 using namespace Clustr;
21 //using std::tr1::sqrt;
22
23 void Ring::push_back (const Point &p2) {
24     if (!is_empty()) {
25         Point p1 = vertex(size()-1);
26         coord_type fx = scale_x((p1.y() + p2.y())/2.0),
27                    dx = p2.x() - p1.x(),
28                    dy = p2.y() - p1.y();
29         perimeter_ += sqrt(dx*dx*fx*fx + dy*dy);
30         area_ += fx*fx*(p1.x() * p2.y() - p2.x() * p1.y()) / 2;
31     }
32     this->Ring_base::push_back(p2);
33 }
34
35 void Polygon::push_back (Ring &ring) {
36     if ((empty() && !ring.is_ccw()) ||
37         (!empty() && ring.is_ccw()))
38         ring.reverse_orientation();
39     this->Polygon_base::push_back(ring);
40 }
41
42 coord_type Polygon::area (void) {
43     coord_type total = 0;
44     for (Polygon::iterator ring = begin(); ring != end(); ring++) {
45         total += ring->area();
46     }
47     return total;
48 }
49
50 coord_type Polygon::perimeter (void) {
51     coord_type total = 0;
52     for (Polygon::iterator ring = begin(); ring != end(); ring++) {
53         total += ring->perimeter();
54     }
55     return total;
56 }
Note: See TracBrowser for help on using the browser.