vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / agg / agg_bounding_rect.h
blobf13b863f0fc86db691b719b7cba2be0bd3367940
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
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.
9 //
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"
24 namespace agg
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)
33 unsigned i;
34 double x;
35 double y;
36 bool first = true;
38 *x1 = CoordT(1);
39 *y1 = CoordT(1);
40 *x2 = CoordT(0);
41 *y2 = CoordT(0);
43 for(i = 0; i < num; i++)
45 vs.rewind(gi[start + i]);
46 unsigned cmd;
47 while(!is_stop(cmd = vs.vertex(&x, &y)))
49 if(is_vertex(cmd))
51 if(first)
53 *x1 = CoordT(x);
54 *y1 = CoordT(y);
55 *x2 = CoordT(x);
56 *y2 = CoordT(y);
57 first = false;
59 else
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)
78 double x;
79 double y;
80 bool first = true;
82 *x1 = CoordT(1);
83 *y1 = CoordT(1);
84 *x2 = CoordT(0);
85 *y2 = CoordT(0);
87 vs.rewind(path_id);
88 unsigned cmd;
89 while(!is_stop(cmd = vs.vertex(&x, &y)))
91 if(is_vertex(cmd))
93 if(first)
95 *x1 = CoordT(x);
96 *y1 = CoordT(y);
97 *x2 = CoordT(x);
98 *y2 = CoordT(y);
99 first = false;
101 else
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;
116 #endif