1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry (AGG) - Version 2.5 3 // A high quality rendering engine for C++ 4 // Copyright (C) 2002-2006 Maxim Shemanarev 5 // Contact: mcseem@antigrain.com 6 // mcseemagg@yahoo.com 7 // http://antigrain.com 8 // 9 // AGG is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // AGG is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with AGG; if not, write to the Free Software 21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 // MA 02110-1301, USA. 23 //---------------------------------------------------------------------------- 24 25 #ifndef AGG_BOUNDING_RECT_INCLUDED 26 #define AGG_BOUNDING_RECT_INCLUDED 27 28 #include "agg_basics.h" 29 30 namespace agg 31 { 32 33 //-----------------------------------------------------------bounding_rect 34 template<class VertexSource, class GetId, class CoordT> bounding_rect(VertexSource & vs,GetId & gi,unsigned start,unsigned num,CoordT * x1,CoordT * y1,CoordT * x2,CoordT * y2)35 bool bounding_rect(VertexSource& vs, GetId& gi, 36 unsigned start, unsigned num, 37 CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2) 38 { 39 unsigned i; 40 double x; 41 double y; 42 bool first = true; 43 44 *x1 = CoordT(1); 45 *y1 = CoordT(1); 46 *x2 = CoordT(0); 47 *y2 = CoordT(0); 48 49 for(i = 0; i < num; i++) 50 { 51 vs.rewind(gi[start + i]); 52 unsigned cmd; 53 while(!is_stop(cmd = vs.vertex(&x, &y))) 54 { 55 if(is_vertex(cmd)) 56 { 57 if(first) 58 { 59 *x1 = CoordT(x); 60 *y1 = CoordT(y); 61 *x2 = CoordT(x); 62 *y2 = CoordT(y); 63 first = false; 64 } 65 else 66 { 67 if(CoordT(x) < *x1) *x1 = CoordT(x); 68 if(CoordT(y) < *y1) *y1 = CoordT(y); 69 if(CoordT(x) > *x2) *x2 = CoordT(x); 70 if(CoordT(y) > *y2) *y2 = CoordT(y); 71 } 72 } 73 } 74 } 75 return *x1 <= *x2 && *y1 <= *y2; 76 } 77 78 79 //-----------------------------------------------------bounding_rect_single 80 template<class VertexSource, class CoordT> bounding_rect_single(VertexSource & vs,unsigned path_id,CoordT * x1,CoordT * y1,CoordT * x2,CoordT * y2)81 bool bounding_rect_single(VertexSource& vs, unsigned path_id, 82 CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2) 83 { 84 double x; 85 double y; 86 bool first = true; 87 88 *x1 = CoordT(1); 89 *y1 = CoordT(1); 90 *x2 = CoordT(0); 91 *y2 = CoordT(0); 92 93 vs.rewind(path_id); 94 unsigned cmd; 95 while(!is_stop(cmd = vs.vertex(&x, &y))) 96 { 97 if(is_vertex(cmd)) 98 { 99 if(first) 100 { 101 *x1 = CoordT(x); 102 *y1 = CoordT(y); 103 *x2 = CoordT(x); 104 *y2 = CoordT(y); 105 first = false; 106 } 107 else 108 { 109 if(CoordT(x) < *x1) *x1 = CoordT(x); 110 if(CoordT(y) < *y1) *y1 = CoordT(y); 111 if(CoordT(x) > *x2) *x2 = CoordT(x); 112 if(CoordT(y) > *y2) *y2 = CoordT(y); 113 } 114 } 115 } 116 return *x1 <= *x2 && *y1 <= *y2; 117 } 118 119 120 } 121 122 #endif 123