Anti-Grain Geometry - AGG (libagg)  2.5
agg-2.5/include/agg_path_length.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry (AGG) - Version 2.5
00003 // A high quality rendering engine for C++
00004 // Copyright (C) 2002-2006 Maxim Shemanarev
00005 // Contact: mcseem@antigrain.com
00006 //          mcseemagg@yahoo.com
00007 //          http://antigrain.com
00008 // 
00009 // AGG is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 // 
00014 // AGG is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU General Public License
00020 // along with AGG; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00022 // MA 02110-1301, USA.
00023 //----------------------------------------------------------------------------
00024 
00025 #ifndef AGG_PATH_LENGTH_INCLUDED
00026 #define AGG_PATH_LENGTH_INCLUDED
00027 
00028 #include "agg_math.h"
00029 
00030 namespace agg
00031 {
00032     template<class VertexSource> 
00033     double path_length(VertexSource& vs, unsigned path_id = 0)
00034     {
00035         double len = 0.0;
00036         double start_x = 0.0;
00037         double start_y = 0.0;
00038         double x1 = 0.0;
00039         double y1 = 0.0;
00040         double x2 = 0.0;
00041         double y2 = 0.0;
00042         bool first = true;
00043 
00044         unsigned cmd;
00045         vs.rewind(path_id);
00046         while(!is_stop(cmd = vs.vertex(&x2, &y2)))
00047         {
00048             if(is_vertex(cmd))
00049             {
00050                 if(first || is_move_to(cmd))
00051                 {
00052                     start_x = x2;
00053                     start_y = y2;
00054                 }
00055                 else
00056                 {
00057                     len += calc_distance(x1, y1, x2, y2);
00058                 }
00059                 x1 = x2;
00060                 y1 = y2;
00061                 first = false;
00062             }
00063             else
00064             {
00065                 if(is_close(cmd) && !first)
00066                 {
00067                     len += calc_distance(x1, y1, start_x, start_y);
00068                 }
00069             }
00070         }
00071         return len;
00072     }
00073 }
00074 
00075 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines