+ remove legacy 'register' keyword usage from last century
This commit is contained in:
artemp 2013-10-15 15:22:39 +01:00
parent 9280dd8b45
commit 877128d5ec
3 changed files with 147 additions and 149 deletions

View file

@ -2,8 +2,8 @@
// Anti-Grain Geometry - Version 2.4 // Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
// //
// Permission to copy, use, modify, sell and distribute this software // Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies. // is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied // This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose. // warranty, and with no claim as to its suitability for any purpose.
// //
@ -25,25 +25,25 @@
#else #else
namespace agg namespace agg
{ {
// The policy of all AGG containers and memory allocation strategy // The policy of all AGG containers and memory allocation strategy
// in general is that no allocated data requires explicit construction. // in general is that no allocated data requires explicit construction.
// It means that the allocator can be really simple; you can even // It means that the allocator can be really simple; you can even
// replace new/delete to malloc/free. The constructors and destructors // replace new/delete to malloc/free. The constructors and destructors
// won't be called in this case, however everything will remain working. // won't be called in this case, however everything will remain working.
// The second argument of deallocate() is the size of the allocated // The second argument of deallocate() is the size of the allocated
// block. You can use this information if you wish. // block. You can use this information if you wish.
//------------------------------------------------------------pod_allocator //------------------------------------------------------------pod_allocator
template<class T> struct pod_allocator template<class T> struct pod_allocator
{ {
//static T* allocate(unsigned num) { return static_cast<T*>(::operator new(sizeof(T)*num));} //static T* allocate(unsigned num) { return static_cast<T*>(::operator new(sizeof(T)*num));}
//static void deallocate(T* ptr, unsigned) { ::operator delete(ptr) ;} //static void deallocate(T* ptr, unsigned) { ::operator delete(ptr) ;}
static T* allocate(unsigned num) { return new T [num]; } static T* allocate(unsigned num) { return new T [num]; }
static void deallocate(T* ptr, unsigned) { delete [] ptr; } static void deallocate(T* ptr, unsigned) { delete [] ptr; }
}; };
// Single object allocator. It's also can be replaced with your custom // Single object allocator. It's also can be replaced with your custom
// allocator. The difference is that it can only allocate a single // allocator. The difference is that it can only allocate a single
// object and the constructor and destructor must be called. // object and the constructor and destructor must be called.
// In AGG there is no need to allocate an array of objects with // In AGG there is no need to allocate an array of objects with
// calling their constructors (only single ones). So that, if you // calling their constructors (only single ones). So that, if you
// replace these new/delete to malloc/free make sure that the in-place // replace these new/delete to malloc/free make sure that the in-place
@ -205,7 +205,7 @@ namespace agg
{ {
AGG_INLINE static unsigned mul(unsigned a, unsigned b) AGG_INLINE static unsigned mul(unsigned a, unsigned b)
{ {
register unsigned q = a * b + (1 << (Shift-1)); unsigned q = a * b + (1 << (Shift-1));
return (q + (q >> Shift)) >> Shift; return (q + (q >> Shift)) >> Shift;
} }
}; };
@ -215,23 +215,23 @@ namespace agg
enum cover_scale_e enum cover_scale_e
{ {
cover_shift = 8, //----cover_shift cover_shift = 8, //----cover_shift
cover_size = 1 << cover_shift, //----cover_size cover_size = 1 << cover_shift, //----cover_size
cover_mask = cover_size - 1, //----cover_mask cover_mask = cover_size - 1, //----cover_mask
cover_none = 0, //----cover_none cover_none = 0, //----cover_none
cover_full = cover_mask //----cover_full cover_full = cover_mask //----cover_full
}; };
//----------------------------------------------------poly_subpixel_scale_e //----------------------------------------------------poly_subpixel_scale_e
// These constants determine the subpixel accuracy, to be more precise, // These constants determine the subpixel accuracy, to be more precise,
// the number of bits of the fractional part of the coordinates. // the number of bits of the fractional part of the coordinates.
// The possible coordinate capacity in bits can be calculated by formula: // The possible coordinate capacity in bits can be calculated by formula:
// sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and // sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and
// 8-bits fractional part the capacity is 24 bits. // 8-bits fractional part the capacity is 24 bits.
enum poly_subpixel_scale_e enum poly_subpixel_scale_e
{ {
poly_subpixel_shift = 8, //----poly_subpixel_shift poly_subpixel_shift = 8, //----poly_subpixel_shift
poly_subpixel_scale = 1<<poly_subpixel_shift, //----poly_subpixel_scale poly_subpixel_scale = 1<<poly_subpixel_shift, //----poly_subpixel_scale
poly_subpixel_mask = poly_subpixel_scale-1 //----poly_subpixel_mask poly_subpixel_mask = poly_subpixel_scale-1 //----poly_subpixel_mask
}; };
//----------------------------------------------------------filling_rule_e //----------------------------------------------------------filling_rule_e
@ -255,7 +255,7 @@ namespace agg
{ {
return rad * 180.0 / pi; return rad * 180.0 / pi;
} }
//----------------------------------------------------------------rect_base //----------------------------------------------------------------rect_base
template<class T> struct rect_base template<class T> struct rect_base
{ {
@ -267,9 +267,9 @@ namespace agg
rect_base(T x1_, T y1_, T x2_, T y2_) : rect_base(T x1_, T y1_, T x2_, T y2_) :
x1(x1_), y1(y1_), x2(x2_), y2(y2_) {} x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
void init(T x1_, T y1_, T x2_, T y2_) void init(T x1_, T y1_, T x2_, T y2_)
{ {
x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_; x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_;
} }
const self_type& normalize() const self_type& normalize()
@ -301,17 +301,17 @@ namespace agg
}; };
//-----------------------------------------------------intersect_rectangles //-----------------------------------------------------intersect_rectangles
template<class Rect> template<class Rect>
inline Rect intersect_rectangles(const Rect& r1, const Rect& r2) inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
{ {
Rect r = r1; Rect r = r1;
// First process x2,y2 because the other order // First process x2,y2 because the other order
// results in Internal Compiler Error under // results in Internal Compiler Error under
// Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in
// case of "Maximize Speed" optimization option. // case of "Maximize Speed" optimization option.
//----------------- //-----------------
if(r.x2 > r2.x2) r.x2 = r2.x2; if(r.x2 > r2.x2) r.x2 = r2.x2;
if(r.y2 > r2.y2) r.y2 = r2.y2; if(r.y2 > r2.y2) r.y2 = r2.y2;
if(r.x1 < r2.x1) r.x1 = r2.x1; if(r.x1 < r2.x1) r.x1 = r2.x1;
if(r.y1 < r2.y1) r.y1 = r2.y1; if(r.y1 < r2.y1) r.y1 = r2.y1;
@ -320,7 +320,7 @@ namespace agg
//---------------------------------------------------------unite_rectangles //---------------------------------------------------------unite_rectangles
template<class Rect> template<class Rect>
inline Rect unite_rectangles(const Rect& r1, const Rect& r2) inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
{ {
Rect r = r1; Rect r = r1;
@ -338,26 +338,26 @@ namespace agg
//---------------------------------------------------------path_commands_e //---------------------------------------------------------path_commands_e
enum path_commands_e enum path_commands_e
{ {
path_cmd_stop = 0, //----path_cmd_stop path_cmd_stop = 0, //----path_cmd_stop
path_cmd_move_to = 1, //----path_cmd_move_to path_cmd_move_to = 1, //----path_cmd_move_to
path_cmd_line_to = 2, //----path_cmd_line_to path_cmd_line_to = 2, //----path_cmd_line_to
path_cmd_curve3 = 3, //----path_cmd_curve3 path_cmd_curve3 = 3, //----path_cmd_curve3
path_cmd_curve4 = 4, //----path_cmd_curve4 path_cmd_curve4 = 4, //----path_cmd_curve4
path_cmd_curveN = 5, //----path_cmd_curveN path_cmd_curveN = 5, //----path_cmd_curveN
path_cmd_catrom = 6, //----path_cmd_catrom path_cmd_catrom = 6, //----path_cmd_catrom
path_cmd_ubspline = 7, //----path_cmd_ubspline path_cmd_ubspline = 7, //----path_cmd_ubspline
path_cmd_end_poly = 0x0F, //----path_cmd_end_poly path_cmd_end_poly = 0x0F, //----path_cmd_end_poly
path_cmd_mask = 0x0F //----path_cmd_mask path_cmd_mask = 0x0F //----path_cmd_mask
}; };
//------------------------------------------------------------path_flags_e //------------------------------------------------------------path_flags_e
enum path_flags_e enum path_flags_e
{ {
path_flags_none = 0, //----path_flags_none path_flags_none = 0, //----path_flags_none
path_flags_ccw = 0x10, //----path_flags_ccw path_flags_ccw = 0x10, //----path_flags_ccw
path_flags_cw = 0x20, //----path_flags_cw path_flags_cw = 0x20, //----path_flags_cw
path_flags_close = 0x40, //----path_flags_close path_flags_close = 0x40, //----path_flags_close
path_flags_mask = 0xF0 //----path_flags_mask path_flags_mask = 0xF0 //----path_flags_mask
}; };
//---------------------------------------------------------------is_vertex //---------------------------------------------------------------is_vertex
@ -374,7 +374,7 @@ namespace agg
//-----------------------------------------------------------------is_stop //-----------------------------------------------------------------is_stop
inline bool is_stop(unsigned c) inline bool is_stop(unsigned c)
{ {
return c == path_cmd_stop; return c == path_cmd_stop;
} }
@ -418,7 +418,7 @@ namespace agg
inline bool is_close(unsigned c) inline bool is_close(unsigned c)
{ {
return (c & ~(path_flags_cw | path_flags_ccw)) == return (c & ~(path_flags_cw | path_flags_ccw)) ==
(path_cmd_end_poly | path_flags_close); (path_cmd_end_poly | path_flags_close);
} }
//------------------------------------------------------------is_next_poly //------------------------------------------------------------is_next_poly
@ -442,19 +442,19 @@ namespace agg
//-------------------------------------------------------------is_oriented //-------------------------------------------------------------is_oriented
inline bool is_oriented(unsigned c) inline bool is_oriented(unsigned c)
{ {
return (c & (path_flags_cw | path_flags_ccw)) != 0; return (c & (path_flags_cw | path_flags_ccw)) != 0;
} }
//---------------------------------------------------------------is_closed //---------------------------------------------------------------is_closed
inline bool is_closed(unsigned c) inline bool is_closed(unsigned c)
{ {
return (c & path_flags_close) != 0; return (c & path_flags_close) != 0;
} }
//----------------------------------------------------------get_close_flag //----------------------------------------------------------get_close_flag
inline unsigned get_close_flag(unsigned c) inline unsigned get_close_flag(unsigned c)
{ {
return c & path_flags_close; return c & path_flags_close;
} }
//-------------------------------------------------------clear_orientation //-------------------------------------------------------clear_orientation
@ -515,7 +515,7 @@ namespace agg
int x1, x2; int x1, x2;
const T* ptr; const T* ptr;
const_row_info() {} const_row_info() {}
const_row_info(int x1_, int x2_, const T* ptr_) : const_row_info(int x1_, int x2_, const T* ptr_) :
x1(x1_), x2(x2_), ptr(ptr_) {} x1(x1_), x2(x2_), ptr(ptr_) {}
}; };
@ -529,4 +529,3 @@ namespace agg
#endif #endif

View file

@ -2,8 +2,8 @@
// Anti-Grain Geometry - Version 2.4 // Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
// //
// Permission to copy, use, modify, sell and distribute this software // Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies. // is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied // This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose. // warranty, and with no claim as to its suitability for any purpose.
// //
@ -32,8 +32,8 @@ namespace agg
enum pix_width_e { pix_width = pixfmt_type::pix_width }; enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_clip() {} image_accessor_clip() {}
explicit image_accessor_clip(const pixfmt_type& pixf, explicit image_accessor_clip(const pixfmt_type& pixf,
const color_type& bk) : const color_type& bk) :
m_pixf(&pixf) m_pixf(&pixf)
{ {
pixfmt_type::make_pix(m_bk_buf, bk); pixfmt_type::make_pix(m_bk_buf, bk);
@ -85,7 +85,7 @@ namespace agg
{ {
++m_y; ++m_y;
m_x = m_x0; m_x = m_x0;
if(m_pix_ptr && if(m_pix_ptr &&
m_y >= 0 && m_y < (int)m_pixf->height()) m_y >= 0 && m_y < (int)m_pixf->height())
{ {
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y); return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
@ -115,8 +115,8 @@ namespace agg
enum pix_width_e { pix_width = pixfmt_type::pix_width }; enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_no_clip() {} image_accessor_no_clip() {}
explicit image_accessor_no_clip(const pixfmt_type& pixf) : explicit image_accessor_no_clip(const pixfmt_type& pixf) :
m_pixf(&pixf) m_pixf(&pixf)
{} {}
void attach(const pixfmt_type& pixf) void attach(const pixfmt_type& pixf)
@ -162,8 +162,8 @@ namespace agg
enum pix_width_e { pix_width = pixfmt_type::pix_width }; enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_clone() {} image_accessor_clone() {}
explicit image_accessor_clone(const pixfmt_type& pixf) : explicit image_accessor_clone(const pixfmt_type& pixf) :
m_pixf(&pixf) m_pixf(&pixf)
{} {}
void attach(const pixfmt_type& pixf) void attach(const pixfmt_type& pixf)
@ -174,8 +174,8 @@ namespace agg
private: private:
AGG_INLINE const int8u* pixel() const AGG_INLINE const int8u* pixel() const
{ {
register int x = m_x; int x = m_x;
register int y = m_y; int y = m_y;
if(x < 0) x = 0; if(x < 0) x = 0;
if(y < 0) y = 0; if(y < 0) y = 0;
if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1; if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1;
@ -208,7 +208,7 @@ namespace agg
{ {
++m_y; ++m_y;
m_x = m_x0; m_x = m_x0;
if(m_pix_ptr && if(m_pix_ptr &&
m_y >= 0 && m_y < (int)m_pixf->height()) m_y >= 0 && m_y < (int)m_pixf->height())
{ {
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y); return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
@ -238,9 +238,9 @@ namespace agg
enum pix_width_e { pix_width = pixfmt_type::pix_width }; enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_wrap() {} image_accessor_wrap() {}
explicit image_accessor_wrap(const pixfmt_type& pixf) : explicit image_accessor_wrap(const pixfmt_type& pixf) :
m_pixf(&pixf), m_pixf(&pixf),
m_wrap_x(pixf.width()), m_wrap_x(pixf.width()),
m_wrap_y(pixf.height()) m_wrap_y(pixf.height())
{} {}
@ -284,15 +284,15 @@ namespace agg
{ {
public: public:
wrap_mode_repeat() {} wrap_mode_repeat() {}
wrap_mode_repeat(unsigned size) : wrap_mode_repeat(unsigned size) :
m_size(size), m_size(size),
m_add(size * (0x3FFFFFFF / size)), m_add(size * (0x3FFFFFFF / size)),
m_value(0) m_value(0)
{} {}
AGG_INLINE unsigned operator() (int v) AGG_INLINE unsigned operator() (int v)
{ {
return m_value = (unsigned(v) + m_add) % m_size; return m_value = (unsigned(v) + m_add) % m_size;
} }
AGG_INLINE unsigned operator++ () AGG_INLINE unsigned operator++ ()
@ -320,7 +320,7 @@ namespace agg
m_mask >>= 1; m_mask >>= 1;
} }
AGG_INLINE unsigned operator() (int v) AGG_INLINE unsigned operator() (int v)
{ {
return m_value = unsigned(v) & m_mask; return m_value = unsigned(v) & m_mask;
} }
AGG_INLINE unsigned operator++ () AGG_INLINE unsigned operator++ ()
@ -347,8 +347,8 @@ namespace agg
m_value(0) m_value(0)
{} {}
AGG_INLINE unsigned operator() (int v) AGG_INLINE unsigned operator() (int v)
{ {
if(m_mask) return m_value = unsigned(v) & m_mask; if(m_mask) return m_value = unsigned(v) & m_mask;
return m_value = (unsigned(v) + m_add) % m_size; return m_value = (unsigned(v) + m_add) % m_size;
} }
@ -372,15 +372,15 @@ namespace agg
{ {
public: public:
wrap_mode_reflect() {} wrap_mode_reflect() {}
wrap_mode_reflect(unsigned size) : wrap_mode_reflect(unsigned size) :
m_size(size), m_size(size),
m_size2(size * 2), m_size2(size * 2),
m_add(m_size2 * (0x3FFFFFFF / m_size2)), m_add(m_size2 * (0x3FFFFFFF / m_size2)),
m_value(0) m_value(0)
{} {}
AGG_INLINE unsigned operator() (int v) AGG_INLINE unsigned operator() (int v)
{ {
m_value = (unsigned(v) + m_add) % m_size2; m_value = (unsigned(v) + m_add) % m_size2;
if(m_value >= m_size) return m_size2 - m_value - 1; if(m_value >= m_size) return m_size2 - m_value - 1;
return m_value; return m_value;
@ -411,14 +411,14 @@ namespace agg
{ {
m_mask = 1; m_mask = 1;
m_size = 1; m_size = 1;
while(m_mask < size) while(m_mask < size)
{ {
m_mask = (m_mask << 1) | 1; m_mask = (m_mask << 1) | 1;
m_size <<= 1; m_size <<= 1;
} }
} }
AGG_INLINE unsigned operator() (int v) AGG_INLINE unsigned operator() (int v)
{ {
m_value = unsigned(v) & m_mask; m_value = unsigned(v) & m_mask;
if(m_value >= m_size) return m_mask - m_value; if(m_value >= m_size) return m_mask - m_value;
return m_value; return m_value;
@ -451,12 +451,12 @@ namespace agg
m_value(0) m_value(0)
{} {}
AGG_INLINE unsigned operator() (int v) AGG_INLINE unsigned operator() (int v)
{ {
m_value = m_mask ? unsigned(v) & m_mask : m_value = m_mask ? unsigned(v) & m_mask :
(unsigned(v) + m_add) % m_size2; (unsigned(v) + m_add) % m_size2;
if(m_value >= m_size) return m_size2 - m_value - 1; if(m_value >= m_size) return m_size2 - m_value - 1;
return m_value; return m_value;
} }
AGG_INLINE unsigned operator++ () AGG_INLINE unsigned operator++ ()
{ {

View file

@ -2,8 +2,8 @@
// Anti-Grain Geometry - Version 2.4 // Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
// //
// Permission to copy, use, modify, sell and distribute this software // Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies. // is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied // This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose. // warranty, and with no claim as to its suitability for any purpose.
// //
@ -24,39 +24,39 @@
namespace agg namespace agg
{ {
const double affine_epsilon = 1e-14; const double affine_epsilon = 1e-14;
//============================================================trans_affine //============================================================trans_affine
// //
// See Implementation agg_trans_affine.cpp // See Implementation agg_trans_affine.cpp
// //
// Affine transformation are linear transformations in Cartesian coordinates // Affine transformation are linear transformations in Cartesian coordinates
// (strictly speaking not only in Cartesian, but for the beginning we will // (strictly speaking not only in Cartesian, but for the beginning we will
// think so). They are rotation, scaling, translation and skewing. // think so). They are rotation, scaling, translation and skewing.
// After any affine transformation a line segment remains a line segment // After any affine transformation a line segment remains a line segment
// and it will never become a curve. // and it will never become a curve.
// //
// There will be no math about matrix calculations, since it has been // There will be no math about matrix calculations, since it has been
// described many times. Ask yourself a very simple question: // described many times. Ask yourself a very simple question:
// "why do we need to understand and use some matrix stuff instead of just // "why do we need to understand and use some matrix stuff instead of just
// rotating, scaling and so on". The answers are: // rotating, scaling and so on". The answers are:
// //
// 1. Any combination of transformations can be done by only 4 multiplications // 1. Any combination of transformations can be done by only 4 multiplications
// and 4 additions in floating point. // and 4 additions in floating point.
// 2. One matrix transformation is equivalent to the number of consecutive // 2. One matrix transformation is equivalent to the number of consecutive
// discrete transformations, i.e. the matrix "accumulates" all transformations // discrete transformations, i.e. the matrix "accumulates" all transformations
// in the order of their settings. Suppose we have 4 transformations: // in the order of their settings. Suppose we have 4 transformations:
// * rotate by 30 degrees, // * rotate by 30 degrees,
// * scale X to 2.0, // * scale X to 2.0,
// * scale Y to 1.5, // * scale Y to 1.5,
// * move to (100, 100). // * move to (100, 100).
// The result will depend on the order of these transformations, // The result will depend on the order of these transformations,
// and the advantage of matrix is that the sequence of discret calls: // and the advantage of matrix is that the sequence of discret calls:
// rotate(30), scaleX(2.0), scaleY(1.5), move(100,100) // rotate(30), scaleX(2.0), scaleY(1.5), move(100,100)
// will have exactly the same result as the following matrix transformations: // will have exactly the same result as the following matrix transformations:
// //
// affine_matrix m; // affine_matrix m;
// m *= rotate_matrix(30); // m *= rotate_matrix(30);
// m *= scaleX_matrix(2.0); // m *= scaleX_matrix(2.0);
// m *= scaleY_matrix(1.5); // m *= scaleY_matrix(1.5);
// m *= move_matrix(100,100); // m *= move_matrix(100,100);
@ -64,7 +64,7 @@ namespace agg
// m.transform_my_point_at_last(x, y); // m.transform_my_point_at_last(x, y);
// //
// What is the good of it? In real life we will set-up the matrix only once // What is the good of it? In real life we will set-up the matrix only once
// and then transform many points, let alone the convenience to set any // and then transform many points, let alone the convenience to set any
// combination of transformations. // combination of transformations.
// //
// So, how to use it? Very easy - literally as it's shown above. Not quite, // So, how to use it? Very easy - literally as it's shown above. Not quite,
@ -77,9 +77,9 @@ namespace agg
// m.transform(&x, &y); // m.transform(&x, &y);
// //
// The affine matrix is all you need to perform any linear transformation, // The affine matrix is all you need to perform any linear transformation,
// but all transformations have origin point (0,0). It means that we need to // but all transformations have origin point (0,0). It means that we need to
// use 2 translations if we want to rotate someting around (100,100): // use 2 translations if we want to rotate someting around (100,100):
// //
// m *= agg::trans_affine_translation(-100.0, -100.0); // move to (0,0) // m *= agg::trans_affine_translation(-100.0, -100.0); // move to (0,0)
// m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0); // rotate // m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0); // rotate
// m *= agg::trans_affine_translation(100.0, 100.0); // move back to (100,100) // m *= agg::trans_affine_translation(100.0, 100.0); // move back to (100,100)
@ -96,7 +96,7 @@ namespace agg
{} {}
// Custom matrix. Usually used in derived classes // Custom matrix. Usually used in derived classes
trans_affine(double v0, double v1, double v2, trans_affine(double v0, double v1, double v2,
double v3, double v4, double v5) : double v3, double v4, double v5) :
sx(v0), shy(v1), shx(v2), sy(v3), tx(v4), ty(v5) sx(v0), shy(v1), shx(v2), sy(v3), tx(v4), ty(v5)
{} {}
@ -107,14 +107,14 @@ namespace agg
{} {}
// Rectangle to a parallelogram. // Rectangle to a parallelogram.
trans_affine(double x1, double y1, double x2, double y2, trans_affine(double x1, double y1, double x2, double y2,
const double* parl) const double* parl)
{ {
rect_to_parl(x1, y1, x2, y2, parl); rect_to_parl(x1, y1, x2, y2, parl);
} }
// Parallelogram to a rectangle. // Parallelogram to a rectangle.
trans_affine(const double* parl, trans_affine(const double* parl,
double x1, double y1, double x2, double y2) double x1, double y1, double x2, double y2)
{ {
parl_to_rect(parl, x1, y1, x2, y2); parl_to_rect(parl, x1, y1, x2, y2);
@ -127,25 +127,25 @@ namespace agg
} }
//---------------------------------- Parellelogram transformations //---------------------------------- Parellelogram transformations
// transform a parallelogram to another one. Src and dst are // transform a parallelogram to another one. Src and dst are
// pointers to arrays of three points (double[6], x1,y1,...) that // pointers to arrays of three points (double[6], x1,y1,...) that
// identify three corners of the parallelograms assuming implicit // identify three corners of the parallelograms assuming implicit
// fourth point. The arguments are arrays of double[6] mapped // fourth point. The arguments are arrays of double[6] mapped
// to x1,y1, x2,y2, x3,y3 where the coordinates are: // to x1,y1, x2,y2, x3,y3 where the coordinates are:
// *-----------------* // *-----------------*
// / (x3,y3)/ // / (x3,y3)/
// / / // / /
// /(x1,y1) (x2,y2)/ // /(x1,y1) (x2,y2)/
// *-----------------* // *-----------------*
const trans_affine& parl_to_parl(const double* src, const trans_affine& parl_to_parl(const double* src,
const double* dst); const double* dst);
const trans_affine& rect_to_parl(double x1, double y1, const trans_affine& rect_to_parl(double x1, double y1,
double x2, double y2, double x2, double y2,
const double* parl); const double* parl);
const trans_affine& parl_to_rect(const double* parl, const trans_affine& parl_to_rect(const double* parl,
double x1, double y1, double x1, double y1,
double x2, double y2); double x2, double y2);
@ -171,8 +171,8 @@ namespace agg
// Multiply inverse of "m" to "this" and assign the result to "this" // Multiply inverse of "m" to "this" and assign the result to "this"
const trans_affine& premultiply_inv(const trans_affine& m); const trans_affine& premultiply_inv(const trans_affine& m);
// Invert matrix. Do not try to invert degenerate matrices, // Invert matrix. Do not try to invert degenerate matrices,
// there's no check for validity. If you set scale to 0 and // there's no check for validity. If you set scale to 0 and
// then try to invert matrix, expect unpredictable result. // then try to invert matrix, expect unpredictable result.
const trans_affine& invert(); const trans_affine& invert();
@ -197,7 +197,7 @@ namespace agg
} }
//------------------------------------------- Operators //------------------------------------------- Operators
// Multiply the matrix by another one // Multiply the matrix by another one
const trans_affine& operator *= (const trans_affine& m) const trans_affine& operator *= (const trans_affine& m)
{ {
@ -217,7 +217,7 @@ namespace agg
return trans_affine(*this).multiply(m); return trans_affine(*this).multiply(m);
} }
// Multiply the matrix by inverse of another one // Multiply the matrix by inverse of another one
// and return the result in a separate matrix. // and return the result in a separate matrix.
trans_affine operator / (const trans_affine& m) const trans_affine operator / (const trans_affine& m) const
{ {
@ -250,9 +250,9 @@ namespace agg
// Direct transformation of x and y, 2x2 matrix only, no translation // Direct transformation of x and y, 2x2 matrix only, no translation
void transform_2x2(double* x, double* y) const; void transform_2x2(double* x, double* y) const;
// Inverse transformation of x and y. It works slower than the // Inverse transformation of x and y. It works slower than the
// direct transformation. For massive operations it's better to // direct transformation. For massive operations it's better to
// invert() the matrix and then use direct transformations. // invert() the matrix and then use direct transformations.
void inverse_transform(double* x, double* y) const; void inverse_transform(double* x, double* y) const;
//-------------------------------------------- Auxiliary //-------------------------------------------- Auxiliary
@ -268,7 +268,7 @@ namespace agg
return 1.0 / (sx * sy - shy * shx); return 1.0 / (sx * sy - shy * shx);
} }
// Get the average scale (by X and Y). // Get the average scale (by X and Y).
// Basically used to calculate the approximation_scale when // Basically used to calculate the approximation_scale when
// decomposinting curves into line segments. // decomposinting curves into line segments.
double scale() const; double scale() const;
@ -282,7 +282,7 @@ namespace agg
// Check to see if two matrices are equal // Check to see if two matrices are equal
bool is_equal(const trans_affine& m, double epsilon = affine_epsilon) const; bool is_equal(const trans_affine& m, double epsilon = affine_epsilon) const;
// Determine the major parameters. Use with caution considering // Determine the major parameters. Use with caution considering
// possible degenerate cases. // possible degenerate cases.
double rotation() const; double rotation() const;
void translation(double* dx, double* dy) const; void translation(double* dx, double* dy) const;
@ -293,7 +293,7 @@ namespace agg
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline void trans_affine::transform(double* x, double* y) const inline void trans_affine::transform(double* x, double* y) const
{ {
register double tmp = *x; double tmp = *x;
*x = tmp * sx + *y * shx + tx; *x = tmp * sx + *y * shx + tx;
*y = tmp * shy + *y * sy + ty; *y = tmp * shy + *y * sy + ty;
} }
@ -301,7 +301,7 @@ namespace agg
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline void trans_affine::transform_2x2(double* x, double* y) const inline void trans_affine::transform_2x2(double* x, double* y) const
{ {
register double tmp = *x; double tmp = *x;
*x = tmp * sx + *y * shx; *x = tmp * sx + *y * shx;
*y = tmp * shy + *y * sy; *y = tmp * shy + *y * sy;
} }
@ -309,9 +309,9 @@ namespace agg
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline void trans_affine::inverse_transform(double* x, double* y) const inline void trans_affine::inverse_transform(double* x, double* y) const
{ {
register double d = determinant_reciprocal(); double d = determinant_reciprocal();
register double a = (*x - tx) * d; double a = (*x - tx) * d;
register double b = (*y - ty) * d; double b = (*y - ty) * d;
*x = a * sy - b * shx; *x = a * sy - b * shx;
*y = b * sx - a * shy; *y = b * sx - a * shy;
} }
@ -325,23 +325,23 @@ namespace agg
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline const trans_affine& trans_affine::translate(double x, double y) inline const trans_affine& trans_affine::translate(double x, double y)
{ {
tx += x; tx += x;
ty += y; ty += y;
return *this; return *this;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline const trans_affine& trans_affine::rotate(double a) inline const trans_affine& trans_affine::rotate(double a)
{ {
double ca = cos(a); double ca = cos(a);
double sa = sin(a); double sa = sin(a);
double t0 = sx * ca - shy * sa; double t0 = sx * ca - shy * sa;
double t2 = shx * ca - sy * sa; double t2 = shx * ca - sy * sa;
double t4 = tx * ca - ty * sa; double t4 = tx * ca - ty * sa;
shy = sx * sa + shy * ca; shy = sx * sa + shy * ca;
sy = shx * sa + sy * ca; sy = shx * sa + sy * ca;
ty = tx * sa + ty * ca; ty = tx * sa + ty * ca;
sx = t0; sx = t0;
shx = t2; shx = t2;
@ -350,10 +350,10 @@ namespace agg
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline const trans_affine& trans_affine::scale(double x, double y) inline const trans_affine& trans_affine::scale(double x, double y)
{ {
double mm0 = x; // Possible hint for the optimizer double mm0 = x; // Possible hint for the optimizer
double mm3 = y; double mm3 = y;
sx *= mm0; sx *= mm0;
shx *= mm0; shx *= mm0;
tx *= mm0; tx *= mm0;
@ -364,7 +364,7 @@ namespace agg
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline const trans_affine& trans_affine::scale(double s) inline const trans_affine& trans_affine::scale(double s)
{ {
double m = s; // Possible hint for the optimizer double m = s; // Possible hint for the optimizer
sx *= m; sx *= m;
@ -402,7 +402,7 @@ namespace agg
//------------------------------------------------------------------------ //------------------------------------------------------------------------
inline void trans_affine::scaling_abs(double* x, double* y) const inline void trans_affine::scaling_abs(double* x, double* y) const
{ {
// Used to calculate scaling coefficients in image resampling. // Used to calculate scaling coefficients in image resampling.
// When there is considerable shear this method gives us much // When there is considerable shear this method gives us much
// better estimation than just sx, sy. // better estimation than just sx, sy.
*x = sqrt(sx * sx + shx * shx); *x = sqrt(sx * sx + shx * shx);
@ -412,12 +412,12 @@ namespace agg
//====================================================trans_affine_rotation //====================================================trans_affine_rotation
// Rotation matrix. sin() and cos() are calculated twice for the same angle. // Rotation matrix. sin() and cos() are calculated twice for the same angle.
// There's no harm because the performance of sin()/cos() is very good on all // There's no harm because the performance of sin()/cos() is very good on all
// modern processors. Besides, this operation is not going to be invoked too // modern processors. Besides, this operation is not going to be invoked too
// often. // often.
class trans_affine_rotation : public trans_affine class trans_affine_rotation : public trans_affine
{ {
public: public:
trans_affine_rotation(double a) : trans_affine_rotation(double a) :
trans_affine(cos(a), sin(a), -sin(a), cos(a), 0.0, 0.0) trans_affine(cos(a), sin(a), -sin(a), cos(a), 0.0, 0.0)
{} {}
}; };
@ -427,11 +427,11 @@ namespace agg
class trans_affine_scaling : public trans_affine class trans_affine_scaling : public trans_affine
{ {
public: public:
trans_affine_scaling(double x, double y) : trans_affine_scaling(double x, double y) :
trans_affine(x, 0.0, 0.0, y, 0.0, 0.0) trans_affine(x, 0.0, 0.0, y, 0.0, 0.0)
{} {}
trans_affine_scaling(double s) : trans_affine_scaling(double s) :
trans_affine(s, 0.0, 0.0, s, 0.0, 0.0) trans_affine(s, 0.0, 0.0, s, 0.0, 0.0)
{} {}
}; };
@ -441,7 +441,7 @@ namespace agg
class trans_affine_translation : public trans_affine class trans_affine_translation : public trans_affine
{ {
public: public:
trans_affine_translation(double x, double y) : trans_affine_translation(double x, double y) :
trans_affine(1.0, 0.0, 0.0, 1.0, x, y) trans_affine(1.0, 0.0, 0.0, 1.0, x, y)
{} {}
}; };
@ -451,19 +451,19 @@ namespace agg
class trans_affine_skewing : public trans_affine class trans_affine_skewing : public trans_affine
{ {
public: public:
trans_affine_skewing(double x, double y) : trans_affine_skewing(double x, double y) :
trans_affine(1.0, tan(y), tan(x), 1.0, 0.0, 0.0) trans_affine(1.0, tan(y), tan(x), 1.0, 0.0, 0.0)
{} {}
}; };
//===============================================trans_affine_line_segment //===============================================trans_affine_line_segment
// Rotate, Scale and Translate, associating 0...dist with line segment // Rotate, Scale and Translate, associating 0...dist with line segment
// x1,y1,x2,y2 // x1,y1,x2,y2
class trans_affine_line_segment : public trans_affine class trans_affine_line_segment : public trans_affine
{ {
public: public:
trans_affine_line_segment(double x1, double y1, double x2, double y2, trans_affine_line_segment(double x1, double y1, double x2, double y2,
double dist) double dist)
{ {
double dx = x2 - x1; double dx = x2 - x1;
@ -479,24 +479,24 @@ namespace agg
//============================================trans_affine_reflection_unit //============================================trans_affine_reflection_unit
// Reflection matrix. Reflect coordinates across the line through // Reflection matrix. Reflect coordinates across the line through
// the origin containing the unit vector (ux, uy). // the origin containing the unit vector (ux, uy).
// Contributed by John Horigan // Contributed by John Horigan
class trans_affine_reflection_unit : public trans_affine class trans_affine_reflection_unit : public trans_affine
{ {
public: public:
trans_affine_reflection_unit(double ux, double uy) : trans_affine_reflection_unit(double ux, double uy) :
trans_affine(2.0 * ux * ux - 1.0, trans_affine(2.0 * ux * ux - 1.0,
2.0 * ux * uy, 2.0 * ux * uy,
2.0 * ux * uy, 2.0 * ux * uy,
2.0 * uy * uy - 1.0, 2.0 * uy * uy - 1.0,
0.0, 0.0) 0.0, 0.0)
{} {}
}; };
//=================================================trans_affine_reflection //=================================================trans_affine_reflection
// Reflection matrix. Reflect coordinates across the line through // Reflection matrix. Reflect coordinates across the line through
// the origin at the angle a or containing the non-unit vector (x, y). // the origin at the angle a or containing the non-unit vector (x, y).
// Contributed by John Horigan // Contributed by John Horigan
class trans_affine_reflection : public trans_affine_reflection_unit class trans_affine_reflection : public trans_affine_reflection_unit
@ -516,4 +516,3 @@ namespace agg
#endif #endif