/usr/include/mapnik/geom_util.hpp is in libmapnik2-dev 2.0.0+ds1-3build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id: geom_util.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef GEOM_UTIL_HPP
#define GEOM_UTIL_HPP
// mapnik
#include <mapnik/box2d.hpp>
#include <mapnik/vertex.hpp>
// boost
#include <boost/tuple/tuple.hpp>
// stl
#include <cmath>
namespace mapnik
{
template <typename T>
bool clip_test(T p,T q,double& tmin,double& tmax)
{
double r;
bool result=true;
if (p<0.0)
{
r=q/p;
if (r>tmax) result=false;
else if (r>tmin) tmin=r;
}
else if (p>0.0)
{
r=q/p;
if (r<tmin) result=false;
else if (r<tmax) tmax=r;
} else if (q<0.0) result=false;
return result;
}
template <typename T,typename Image>
bool clip_line(T& x0,T& y0,T& x1,T& y1,box2d<T> const& box)
{
double tmin=0.0;
double tmax=1.0;
double dx=x1-x0;
if (clip_test<double>(-dx,x0,tmin,tmax))
{
if (clip_test<double>(dx,box.width()-x0,tmin,tmax))
{
double dy=y1-y0;
if (clip_test<double>(-dy,y0,tmin,tmax))
{
if (clip_test<double>(dy,box.height()-y0,tmin,tmax))
{
if (tmax<1.0)
{
x1=static_cast<T>(x0+tmax*dx);
y1=static_cast<T>(y0+tmax*dy);
}
if (tmin>0.0)
{
x0+=static_cast<T>(tmin*dx);
y0+=static_cast<T>(tmin*dy);
}
return true;
}
}
}
}
return false;
}
template <typename Iter>
inline bool point_inside_path(double x,double y,Iter start,Iter end)
{
bool inside=false;
double x0=boost::get<0>(*start);
double y0=boost::get<1>(*start);
double x1,y1;
while (++start!=end)
{
if ( boost::get<2>(*start) == SEG_MOVETO)
{
x0 = boost::get<0>(*start);
y0 = boost::get<1>(*start);
continue;
}
x1=boost::get<0>(*start);
y1=boost::get<1>(*start);
if ((((y1 <= y) && (y < y0)) ||
((y0 <= y) && (y < y1))) &&
( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
inside=!inside;
x0=x1;
y0=y1;
}
return inside;
}
inline bool point_in_circle(double x,double y,double cx,double cy,double r)
{
double dx = x - cx;
double dy = y - cy;
double d2 = dx * dx + dy * dy;
return (d2 <= r * r);
}
template <typename T>
inline T sqr(T x)
{
return x * x;
}
inline double distance2(double x0,double y0,double x1,double y1)
{
double dx = x1 - x0;
double dy = y1 - y0;
return sqr(dx) + sqr(dy);
}
inline double distance(double x0,double y0, double x1,double y1)
{
return std::sqrt(distance2(x0,y0,x1,y1));
}
inline double point_to_segment_distance(double x, double y,
double ax, double ay,
double bx, double by)
{
double len2 = distance2(ax,ay,bx,by);
if (len2 < 1e-14)
{
return distance(x,y,ax,ay);
}
double r = ((x - ax)*(bx - ax) + (y - ay)*(by -ay))/len2;
if ( r < 0 )
{
return distance(x,y,ax,ay);
}
else if (r > 1)
{
return distance(x,y,bx,by);
}
double s = ((ay - y)*(bx - ax) - (ax - x)*(by - ay))/len2;
return std::fabs(s) * std::sqrt(len2);
}
template <typename Iter>
inline bool point_on_path(double x,double y,Iter start,Iter end, double tol)
{
double x0=boost::get<0>(*start);
double y0=boost::get<1>(*start);
double x1,y1;
while (++start != end)
{
if ( boost::get<2>(*start) == SEG_MOVETO)
{
x0 = boost::get<0>(*start);
y0 = boost::get<1>(*start);
continue;
}
x1=boost::get<0>(*start);
y1=boost::get<1>(*start);
double distance = point_to_segment_distance(x,y,x0,y0,x1,y1);
if (distance < tol)
return true;
x0=x1;
y0=y1;
}
return false;
}
// filters
struct filter_in_box
{
box2d<double> box_;
explicit filter_in_box(const box2d<double>& box)
: box_(box) {}
bool pass(const box2d<double>& extent) const
{
return extent.intersects(box_);
}
};
struct filter_at_point
{
coord2d pt_;
explicit filter_at_point(const coord2d& pt)
: pt_(pt) {}
bool pass(const box2d<double>& extent) const
{
return extent.contains(pt_);
}
};
}
#endif //GEOM_UTIL_HPP
|