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 #ifndef AGG_SHORTEN_PATH_INCLUDED
17 #define AGG_SHORTEN_PATH_INCLUDED
19 #include "agg_basics.h"
20 #include "agg_vertex_sequence.h"
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)
34 int n
= int(vs
.size() - 2);
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
;
57 if(!prev(last
)) vs
.remove_last();
58 vs
.close(closed
!= 0);