/usr/include/synfig-1.0/synfig/rect.h is in libsynfig-dev 1.2.1-0ubuntu4.
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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | /* === S Y N F I G ========================================================= */
/*! \file rect.h
** \brief Rectangle Class
**
** $Id$
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
** Copyright (c) 2007, 2008 Chris Moore
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package 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
** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */
/* === S T A R T =========================================================== */
#ifndef __SYNFIG_RECT_H
#define __SYNFIG_RECT_H
/* === H E A D E R S ======================================================= */
#include <ETL/rect>
#include "real.h"
#include "vector.h"
#include <limits>
#include <cmath>
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
/* === C L A S S E S & S T R U C T S ======================================= */
namespace synfig {
class RectInt : public etl::rect<int>
{
public:
typedef etl::rect<int> baserect;
using baserect::set_point;
using baserect::expand;
using baserect::set;
static RectInt zero()
{
return RectInt(
0,
0,
0,
0
);
}
RectInt(): baserect(0, 0, 0, 0) { }
RectInt(const PointInt& x) { set_point(x); }
RectInt(const PointInt& min, const PointInt& max) { set_point(min); expand(max); }
RectInt(const value_type &x1,const value_type &y1) { set_point(x1,y1); }
RectInt(const value_type &x1,const value_type &y1,
const value_type &x2,const value_type &y2)
{
set_point(x1,y1);
expand(x2,y2);
}
void set_point(const PointInt& max) { set_point(max[0],max[1]); }
RectInt& expand(const PointInt& max) { expand(max[0],max[1]); return *this; }
RectInt& expand(const int& r) { minx-=r; miny-=r; maxx+=r; maxy+=r; return *this; }
RectInt& expand_x(const int& r) { minx-=r; maxx+=r; return *this; }
RectInt& expand_y(const int& r) { miny-=r; maxy+=r; return *this; }
RectInt& set(const PointInt& min,const PointInt& max) { set(min[0],min[1],max[0],max[1]); return *this; }
PointInt get_min()const { return PointInt(minx,miny); }
PointInt get_max()const { return PointInt(maxx,maxy); }
VectorInt get_size()const { return get_max() - get_min(); }
value_type get_width()const { return maxx - minx; }
value_type get_height()const { return maxy - miny; }
bool is_inside(const PointInt& x) { return x[0]>=minx && x[0]<maxx && x[1]>=miny && x[1]<maxy; }
int area()const
{
return (maxx-minx)*(maxy-miny);
}
// Operators
RectInt& operator+=(const VectorInt& rhs)
{
minx+=rhs[0]; miny+=rhs[1];
maxx+=rhs[0]; maxy+=rhs[1];
return *this;
}
RectInt& operator-=(const VectorInt& rhs)
{
minx-=rhs[0]; miny-=rhs[1];
maxx-=rhs[0]; maxy-=rhs[1];
return *this;
}
RectInt& operator*=(const int& rhs)
{
minx*=rhs; miny*=rhs;
maxx*=rhs; maxy*=rhs;
return *this;
}
RectInt& operator/=(int rhs)
{
minx/=rhs; miny/=rhs;
maxx/=rhs; maxy/=rhs;
return *this;
}
RectInt& operator&=(const RectInt& rhs)
{
if(rhs.valid() && valid())
etl::set_intersect(*this,*this,rhs);
else
*this=zero();
return *this;
}
RectInt& operator|=(const RectInt& rhs)
{
if(rhs.valid()>0 && valid()>0)
etl::set_union(*this,*this,rhs);
else
{
if(area()<rhs.area())
*this=rhs;
}
return *this;
}
RectInt operator+(const VectorInt& rhs)const { return RectInt(*this)+=rhs; }
RectInt operator-(const VectorInt& rhs)const { return RectInt(*this)-=rhs; }
RectInt operator*(const int& rhs)const { return RectInt(*this)*=rhs; }
RectInt operator/(const int& rhs)const { return RectInt(*this)/=rhs; }
RectInt operator&(const RectInt& rhs)const { return RectInt(*this)&=rhs; }
RectInt operator|(const RectInt& rhs)const { return RectInt(*this)|=rhs; }
bool operator&&(const RectInt& rhs)const { return valid() && rhs.valid() && etl::intersect(*this, rhs); }
bool operator==(const RectInt &rhs)const { return get_min() == rhs.get_min() && get_max() == rhs.get_max(); }
bool operator!=(const RectInt &rhs)const { return get_min() != rhs.get_min() || get_max() != rhs.get_max(); }
bool contains(const RectInt &x)const { return etl::contains(*this, x); }
bool is_valid()const { return valid(); }
template<typename List>
static void merge(List &list)
{ etl::rects_merge(list); }
template<typename List>
void list_add(List &list)
{ etl::rects_add(list, *this); merge(list); }
template<typename List>
void list_subtract(List &list)
{ etl::rects_subtract(list, *this); merge(list); }
RectInt multiply_coords(const VectorInt &rhs) const
{ return RectInt(minx*rhs[0], miny*rhs[1], maxx*rhs[0], maxy*rhs[1]); }
RectInt divide_coords(const VectorInt &rhs) const
{ return RectInt(minx/rhs[0], miny/rhs[1], maxx/rhs[0], maxy/rhs[1]); }
}; // END of class RectInt
class Rect : public etl::rect<Real>
{
public:
typedef etl::rect<Real> baserect;
using baserect::set_point;
using baserect::expand;
using baserect::set;
static Rect full_plane();
static Rect horizontal_strip(const value_type &y1, const value_type &y2);
static Rect vertical_strip(const value_type &x1, const value_type &x2);
static Rect zero()
{
return Rect(
0,
0,
0,
0
);
}
static Rect infinite()
{
return Rect(
-INFINITY,
-INFINITY,
INFINITY,
INFINITY
);
}
Rect(): baserect(0, 0, 0, 0) { }
Rect(const Point& x) { set_point(x); }
Rect(const Point& min, const Point& max) { set_point(min); expand(max); }
Rect(const value_type &x1,const value_type &y1) { set_point(x1,y1); }
Rect(const value_type &x1,const value_type &y1,
const value_type &x2,const value_type &y2)
{
set_point(x1,y1);
expand(x2,y2);
}
void set_point(const Point& max) { set_point(max[0],max[1]); }
Rect& expand(const Point& max) { expand(max[0],max[1]); return *this; }
Rect& expand(const Real& r) { minx-=r; miny-=r; maxx+=r; maxy+=r; return *this; }
Rect& expand_x(const Real& r) { minx-=r; maxx+=r; return *this; }
Rect& expand_y(const Real& r) { miny-=r; maxy+=r; return *this; }
Rect& set(const Point& min,const Point& max) { set(min[0],min[1],max[0],max[1]); return *this; }
Point get_min()const { return Point(minx,miny); }
Point get_max()const { return Point(maxx,maxy); }
Vector get_size()const { return get_max() - get_min(); }
value_type get_width()const { return maxx - minx; }
value_type get_height()const { return maxy - miny; }
bool is_inside(const Point& x)
{
return approximate_less_or_equal(minx, x[0])
&& approximate_less_or_equal(x[0], maxx)
&& approximate_less_or_equal(miny, x[1])
&& approximate_less_or_equal(x[1], maxy);
}
Real area()const
{
return (maxx-minx)*(maxy-miny);
}
// Operators
Rect& operator+=(const Vector& rhs)
{
minx+=rhs[0]; miny+=rhs[1];
maxx+=rhs[0]; maxy+=rhs[1];
return *this;
}
Rect& operator-=(const Vector& rhs)
{
minx-=rhs[0]; miny-=rhs[1];
maxx-=rhs[0]; maxy-=rhs[1];
return *this;
}
Rect& operator*=(const Real& rhs)
{
minx*=rhs; miny*=rhs;
maxx*=rhs; maxy*=rhs;
return *this;
}
Rect& operator/=(Real rhs)
{
rhs=1.0/rhs; // Avoid doing several divisions
minx*=rhs; miny*=rhs;
maxx*=rhs; maxy*=rhs;
return *this;
}
Rect& operator&=(const Rect& rhs)
{
if ( rhs.valid() && valid()
&& rhs.area()>0.00000001 && area()>0.00000001 )
etl::set_intersect(*this,*this,rhs);
else
*this=zero();
return *this;
}
Rect& operator|=(const Rect& rhs)
{
if ( rhs.valid() && valid()
&& rhs.area()>0.00000001 && area()>0.00000001 )
etl::set_union(*this,*this,rhs);
else
{
if(area()<rhs.area())
*this=rhs;
}
return *this;
}
Rect operator+(const Vector& rhs)const { return Rect(*this)+=rhs; }
Rect operator-(const Vector& rhs)const { return Rect(*this)-=rhs; }
Rect operator*(const Real& rhs)const { return Rect(*this)*=rhs; }
Rect operator/(const Real& rhs)const { return Rect(*this)/=rhs; }
Rect operator&(const Rect& rhs)const { return Rect(*this)&=rhs; }
Rect operator|(const Rect& rhs)const { return Rect(*this)|=rhs; }
bool operator&&(const Rect& rhs)const { return valid() && rhs.valid() && etl::intersect(*this, rhs); }
bool operator==(const Rect &rhs)const { return get_min() == rhs.get_min() && get_max() == rhs.get_max(); }
bool operator!=(const Rect &rhs)const { return get_min() != rhs.get_min() || get_max() != rhs.get_max(); }
bool contains(const Rect &x)const { return etl::contains(*this, x, approximate_less<Real>); }
bool valid()const { return etl::rect<value_type>::valid(approximate_less<Real>); }
bool is_valid()const { return valid(); }
bool is_nan_or_inf()const
{
return std::isnan(minx)
|| std::isnan(miny)
|| std::isinf(maxx)
|| std::isinf(maxy);
}
template<typename List>
static void merge(List &list)
{ etl::rects_merge(list, approximate_less<Real>); }
template<typename List>
void list_add(List &list)
{ etl::rects_add(list, *this, approximate_less<Real>); merge(list); }
template<typename List>
void list_subtract(List &list)
{ etl::rects_subtract(list, *this, approximate_less<Real>); merge(list); }
Rect multiply_coords(const Vector &rhs) const
{ return Rect(minx*rhs[0], miny*rhs[1], maxx*rhs[0], maxy*rhs[1]); }
Rect divide_coords(const Vector &rhs) const
{ return Rect(minx/rhs[0], miny/rhs[1], maxx/rhs[0], maxy/rhs[1]); }
}; // END of class Rect
}; // END of namespace synfig
/* === E N D =============================================================== */
#endif
|