Anti-Grain Geometry - AGG (libagg)
2.5
|
00001 //---------------------------------------------------------------------------- 00002 // Anti-Grain Geometry (AGG) - Version 2.5 00003 // A high quality rendering engine for C++ 00004 // Copyright (C) 2002-2006 Maxim Shemanarev 00005 // Contact: mcseem@antigrain.com 00006 // mcseemagg@yahoo.com 00007 // http://antigrain.com 00008 // 00009 // AGG is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // AGG is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with AGG; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 // MA 02110-1301, USA. 00023 //---------------------------------------------------------------------------- 00024 00025 #ifndef AGG_BOUNDING_RECT_INCLUDED 00026 #define AGG_BOUNDING_RECT_INCLUDED 00027 00028 #include "agg_basics.h" 00029 00030 namespace agg 00031 { 00032 00033 //-----------------------------------------------------------bounding_rect 00034 template<class VertexSource, class GetId, class CoordT> 00035 bool bounding_rect(VertexSource& vs, GetId& gi, 00036 unsigned start, unsigned num, 00037 CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2) 00038 { 00039 unsigned i; 00040 double x; 00041 double y; 00042 bool first = true; 00043 00044 *x1 = CoordT(1); 00045 *y1 = CoordT(1); 00046 *x2 = CoordT(0); 00047 *y2 = CoordT(0); 00048 00049 for(i = 0; i < num; i++) 00050 { 00051 vs.rewind(gi[start + i]); 00052 unsigned cmd; 00053 while(!is_stop(cmd = vs.vertex(&x, &y))) 00054 { 00055 if(is_vertex(cmd)) 00056 { 00057 if(first) 00058 { 00059 *x1 = CoordT(x); 00060 *y1 = CoordT(y); 00061 *x2 = CoordT(x); 00062 *y2 = CoordT(y); 00063 first = false; 00064 } 00065 else 00066 { 00067 if(CoordT(x) < *x1) *x1 = CoordT(x); 00068 if(CoordT(y) < *y1) *y1 = CoordT(y); 00069 if(CoordT(x) > *x2) *x2 = CoordT(x); 00070 if(CoordT(y) > *y2) *y2 = CoordT(y); 00071 } 00072 } 00073 } 00074 } 00075 return *x1 <= *x2 && *y1 <= *y2; 00076 } 00077 00078 00079 //-----------------------------------------------------bounding_rect_single 00080 template<class VertexSource, class CoordT> 00081 bool bounding_rect_single(VertexSource& vs, unsigned path_id, 00082 CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2) 00083 { 00084 double x; 00085 double y; 00086 bool first = true; 00087 00088 *x1 = CoordT(1); 00089 *y1 = CoordT(1); 00090 *x2 = CoordT(0); 00091 *y2 = CoordT(0); 00092 00093 vs.rewind(path_id); 00094 unsigned cmd; 00095 while(!is_stop(cmd = vs.vertex(&x, &y))) 00096 { 00097 if(is_vertex(cmd)) 00098 { 00099 if(first) 00100 { 00101 *x1 = CoordT(x); 00102 *y1 = CoordT(y); 00103 *x2 = CoordT(x); 00104 *y2 = CoordT(y); 00105 first = false; 00106 } 00107 else 00108 { 00109 if(CoordT(x) < *x1) *x1 = CoordT(x); 00110 if(CoordT(y) < *y1) *y1 = CoordT(y); 00111 if(CoordT(x) > *x2) *x2 = CoordT(x); 00112 if(CoordT(y) > *y2) *y2 = CoordT(y); 00113 } 00114 } 00115 } 00116 return *x1 <= *x2 && *y1 <= *y2; 00117 } 00118 00119 00120 } 00121 00122 #endif