1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // bounding_rect function template
18 //----------------------------------------------------------------------------
19 #ifndef AGG_BOUNDING_RECT_INCLUDED
20 #define AGG_BOUNDING_RECT_INCLUDED
22 #include "agg_basics.h"
27 //-----------------------------------------------------------bounding_rect
28 template<class VertexSource
, class GetId
, class CoordT
>
29 bool bounding_rect(VertexSource
& vs
, GetId
& gi
,
30 unsigned start
, unsigned num
,
31 CoordT
* x1
, CoordT
* y1
, CoordT
* x2
, CoordT
* y2
)
43 for(i
= 0; i
< num
; i
++)
45 vs
.rewind(gi
[start
+ i
]);
47 while(!is_stop(cmd
= vs
.vertex(&x
, &y
)))
61 if(CoordT(x
) < *x1
) *x1
= CoordT(x
);
62 if(CoordT(y
) < *y1
) *y1
= CoordT(y
);
63 if(CoordT(x
) > *x2
) *x2
= CoordT(x
);
64 if(CoordT(y
) > *y2
) *y2
= CoordT(y
);
69 return *x1
<= *x2
&& *y1
<= *y2
;
73 //-----------------------------------------------------bounding_rect_single
74 template<class VertexSource
, class CoordT
>
75 bool bounding_rect_single(VertexSource
& vs
, unsigned path_id
,
76 CoordT
* x1
, CoordT
* y1
, CoordT
* x2
, CoordT
* y2
)
89 while(!is_stop(cmd
= vs
.vertex(&x
, &y
)))
103 if(CoordT(x
) < *x1
) *x1
= CoordT(x
);
104 if(CoordT(y
) < *y1
) *y1
= CoordT(y
);
105 if(CoordT(x
) > *x2
) *x2
= CoordT(x
);
106 if(CoordT(y
) > *y2
) *y2
= CoordT(y
);
110 return *x1
<= *x2
&& *y1
<= *y2
;