vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / agg / agg_shorten_path.h
blobdd9929ff9747837aa6a3acb16bf8e33c37f4bb2e
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 #ifndef AGG_SHORTEN_PATH_INCLUDED
17 #define AGG_SHORTEN_PATH_INCLUDED
19 #include "agg_basics.h"
20 #include "agg_vertex_sequence.h"
22 namespace agg
25 //===========================================================shorten_path
26 template<class VertexSequence>
27 void shorten_path(VertexSequence& vs, double s, unsigned closed = 0)
29 typedef typename VertexSequence::value_type vertex_type;
31 if(s > 0.0 && vs.size() > 1)
33 double d;
34 int n = int(vs.size() - 2);
35 while(n)
37 d = vs[n].dist;
38 if(d > s) break;
39 vs.remove_last();
40 s -= d;
41 --n;
43 if(vs.size() < 2)
45 vs.remove_all();
47 else
49 n = vs.size() - 1;
50 vertex_type& prev = vs[n-1];
51 vertex_type& last = vs[n];
52 d = (prev.dist - s) / prev.dist;
53 double x = prev.x + (last.x - prev.x) * d;
54 double y = prev.y + (last.y - prev.y) * d;
55 last.x = x;
56 last.y = y;
57 if(!prev(last)) vs.remove_last();
58 vs.close(closed != 0);
66 #endif