libosmscout 1.1.1
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/*
2 * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
3 * http://code.google.com/p/poly2tri/
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * * Neither the name of Poly2Tri nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without specific
17 * prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef UTILS_H
33#define UTILS_H
34
35#include <exception>
36#include <cmath>
37
38namespace p2t {
39
40const double PI_3div4 = 3 * M_PI / 4;
41const double PI_div2 = 1.57079632679489661923;
42const double EPSILON = 1e-12;
43
45
56Orientation Orient2d(const Point& pa, const Point& pb, const Point& pc)
57{
58 double detleft = (pa.x - pc.x) * (pb.y - pc.y);
59 double detright = (pa.y - pc.y) * (pb.x - pc.x);
60 double val = detleft - detright;
61 if (val > -EPSILON && val < EPSILON) {
62 return COLLINEAR;
63 } else if (val > 0) {
64 return CCW;
65 }
66 return CW;
67}
68
69/*
70bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
71{
72 double pdx = pd.x;
73 double pdy = pd.y;
74 double adx = pa.x - pdx;
75 double ady = pa.y - pdy;
76 double bdx = pb.x - pdx;
77 double bdy = pb.y - pdy;
78
79 double adxbdy = adx * bdy;
80 double bdxady = bdx * ady;
81 double oabd = adxbdy - bdxady;
82
83 if (oabd <= EPSILON) {
84 return false;
85 }
86
87 double cdx = pc.x - pdx;
88 double cdy = pc.y - pdy;
89
90 double cdxady = cdx * ady;
91 double adxcdy = adx * cdy;
92 double ocad = cdxady - adxcdy;
93
94 if (ocad <= EPSILON) {
95 return false;
96 }
97
98 return true;
99}
100
101*/
102
103bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
104{
105 double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y);
106 if (oadb >= -EPSILON) {
107 return false;
108 }
109
110 double oadc = (pa.x - pc.x)*(pd.y - pc.y) - (pd.x - pc.x)*(pa.y - pc.y);
111 if (oadc <= EPSILON) {
112 return false;
113 }
114 return true;
115}
116
117}
118
119#endif
120
Definition shapes.h:41
Orientation
Definition utils.h:44
@ CW
Definition utils.h:44
@ CCW
Definition utils.h:44
@ COLLINEAR
Definition utils.h:44
bool InScanArea(Point &pa, Point &pb, Point &pc, Point &pd)
Definition utils.h:103
const double PI_3div4
Definition utils.h:40
Orientation Orient2d(const Point &pa, const Point &pb, const Point &pc)
Definition utils.h:56
const double PI_div2
Definition utils.h:41
const double EPSILON
Definition utils.h:42
Definition shapes.h:45
double x
Definition shapes.h:47
double y
Definition shapes.h:47