X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Fsrc%2Fsynfig%2Frect.h;fp=synfig-core%2Fsrc%2Fsynfig%2Frect.h;h=cc21e1fe6187f496f871c717f7551973b36ad0eb;hb=a095981e18cc37a8ecc7cd237cc22b9c10329264;hp=0000000000000000000000000000000000000000;hpb=9459638ad6797b8139f1e9f0715c96076dbf0890;p=synfig.git diff --git a/synfig-core/src/synfig/rect.h b/synfig-core/src/synfig/rect.h new file mode 100644 index 0000000..cc21e1f --- /dev/null +++ b/synfig-core/src/synfig/rect.h @@ -0,0 +1,182 @@ +/* === 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 +#include "real.h" +#include "vector.h" +#include +#include + +/* === 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 Rect : public etl::rect +{ +public: + + using etl::rect::set_point; + using etl::rect::expand; + using etl::rect::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 + ); + } + + Rect() { } + + 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); } + + bool is_inside(const Point& x) { return x[0]>minx && x[0]miny && x[1]0.00000001 && area()>0.00000001) + etl::set_intersect(*this,*this,rhs); + else + *this=zero(); + return *this; + } + + Rect& operator|=(const Rect& rhs) + { + if(rhs.area()>0.00000001 && area()>0.00000001) + etl::set_union(*this,*this,rhs); + else + { + if(area()