Anti-Grain Geometry - AGG (libagg)  2.5
agg-2.5/include/agg_bezier_arc.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_BEZIER_ARC_INCLUDED
00026 #define AGG_BEZIER_ARC_INCLUDED
00027 
00028 #include "agg_conv_transform.h"
00029 
00030 namespace agg
00031 {
00032 
00033     //-----------------------------------------------------------------------
00034     void arc_to_bezier(double cx, double cy, double rx, double ry, 
00035                        double start_angle, double sweep_angle,
00036                        double* curve);
00037 
00038 
00039     //==============================================================bezier_arc
00040     // 
00041     // See implemantaion agg_bezier_arc.cpp
00042     //
00043     class bezier_arc
00044     {
00045     public:
00046         //--------------------------------------------------------------------
00047         bezier_arc() : m_vertex(26), m_num_vertices(0), m_cmd(path_cmd_line_to) {}
00048         bezier_arc(double x,  double y, 
00049                    double rx, double ry, 
00050                    double start_angle, 
00051                    double sweep_angle)
00052         {
00053             init(x, y, rx, ry, start_angle, sweep_angle);
00054         }
00055 
00056         //--------------------------------------------------------------------
00057         void init(double x,  double y, 
00058                   double rx, double ry, 
00059                   double start_angle, 
00060                   double sweep_angle);
00061 
00062         //--------------------------------------------------------------------
00063         void rewind(unsigned)
00064         {
00065             m_vertex = 0;
00066         }
00067 
00068         //--------------------------------------------------------------------
00069         unsigned vertex(double* x, double* y)
00070         {
00071             if(m_vertex >= m_num_vertices) return path_cmd_stop;
00072             *x = m_vertices[m_vertex];
00073             *y = m_vertices[m_vertex + 1];
00074             m_vertex += 2;
00075             return (m_vertex == 2) ? path_cmd_move_to : m_cmd;
00076         }
00077 
00078         // Supplemantary functions. num_vertices() actually returns doubled 
00079         // number of vertices. That is, for 1 vertex it returns 2.
00080         //--------------------------------------------------------------------
00081         unsigned  num_vertices() const { return m_num_vertices; }
00082         const double* vertices() const { return m_vertices;     }
00083         double*       vertices()       { return m_vertices;     }
00084  
00085     private:
00086         unsigned m_vertex;
00087         unsigned m_num_vertices;
00088         double   m_vertices[26];
00089         unsigned m_cmd;
00090     };
00091 
00092 
00093 
00094     //==========================================================bezier_arc_svg
00095     // Compute an SVG-style bezier arc. 
00096     //
00097     // Computes an elliptical arc from (x1, y1) to (x2, y2). The size and 
00098     // orientation of the ellipse are defined by two radii (rx, ry) 
00099     // and an x-axis-rotation, which indicates how the ellipse as a whole 
00100     // is rotated relative to the current coordinate system. The center 
00101     // (cx, cy) of the ellipse is calculated automatically to satisfy the 
00102     // constraints imposed by the other parameters. 
00103     // large-arc-flag and sweep-flag contribute to the automatic calculations 
00104     // and help determine how the arc is drawn.
00105     class bezier_arc_svg
00106     {
00107     public:
00108         //--------------------------------------------------------------------
00109         bezier_arc_svg() : m_arc(), m_radii_ok(false) {}
00110 
00111         bezier_arc_svg(double x1, double y1, 
00112                        double rx, double ry, 
00113                        double angle,
00114                        bool large_arc_flag,
00115                        bool sweep_flag,
00116                        double x2, double y2) : 
00117             m_arc(), m_radii_ok(false)
00118         {
00119             init(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2);
00120         }
00121 
00122         //--------------------------------------------------------------------
00123         void init(double x1, double y1, 
00124                   double rx, double ry, 
00125                   double angle,
00126                   bool large_arc_flag,
00127                   bool sweep_flag,
00128                   double x2, double y2);
00129 
00130         //--------------------------------------------------------------------
00131         bool radii_ok() const { return m_radii_ok; }
00132 
00133         //--------------------------------------------------------------------
00134         void rewind(unsigned)
00135         {
00136             m_arc.rewind(0);
00137         }
00138 
00139         //--------------------------------------------------------------------
00140         unsigned vertex(double* x, double* y)
00141         {
00142             return m_arc.vertex(x, y);
00143         }
00144 
00145         // Supplemantary functions. num_vertices() actually returns doubled 
00146         // number of vertices. That is, for 1 vertex it returns 2.
00147         //--------------------------------------------------------------------
00148         unsigned  num_vertices() const { return m_arc.num_vertices(); }
00149         const double* vertices() const { return m_arc.vertices();     }
00150         double*       vertices()       { return m_arc.vertices();     }
00151 
00152     private:
00153         bezier_arc m_arc;
00154         bool       m_radii_ok;
00155     };
00156 
00157 
00158 
00159 
00160 }
00161 
00162 
00163 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines