headers/libs/agg Fix PVS 11, PVS12

* Replace hard-coded math constants with M_SQRT1_2
	(math.h was already included)

	* also trailing whitespace removal

Change-Id: I5e9511060d2f812830f7621bee3aff9a517576e5
Reviewed-on: https://review.haiku-os.org/c/956
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Rob Gill 2019-01-28 12:26:26 +10:00 committed by waddlesplash
parent cf77ef1857
commit d1f885b435

View File

@ -2,8 +2,8 @@
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
@ -31,32 +31,32 @@ namespace agg
// See Implementation agg_trans_affine.cpp
//
// Affine transformation are linear transformations in Cartesian coordinates
// (strictly speaking not only in Cartesian, but for the beginning we will
// think so). They are rotation, scaling, translation and skewing.
// After any affine transformation a line segment remains a line segment
// and it will never become a curve.
// (strictly speaking not only in Cartesian, but for the beginning we will
// think so). They are rotation, scaling, translation and skewing.
// After any affine transformation a line segment remains a line segment
// 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:
// "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:
//
// 1. Any combination of transformations can be done by only 4 multiplications
// and 4 additions in floating point.
// 2. One matrix transformation is equivalent to the number of consecutive
// discrete transformations, i.e. the matrix "accumulates" all transformations
// in the order of their settings. Suppose we have 4 transformations:
// discrete transformations, i.e. the matrix "accumulates" all transformations
// in the order of their settings. Suppose we have 4 transformations:
// * rotate by 30 degrees,
// * scale X to 2.0,
// * scale Y to 1.5,
// * move to (100, 100).
// The result will depend on the order of these transformations,
// * scale X to 2.0,
// * scale Y to 1.5,
// * move to (100, 100).
// The result will depend on the order of these transformations,
// 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:
//
//
// affine_matrix m;
// m *= rotate_matrix(30);
// m *= rotate_matrix(30);
// m *= scaleX_matrix(2.0);
// m *= scaleY_matrix(1.5);
// m *= move_matrix(100,100);
@ -64,7 +64,7 @@ namespace agg
// 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
// 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.
//
// 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);
//
// 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):
//
//
// 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_translation(100.0, 100.0); // move back to (100,100)
@ -105,14 +105,14 @@ namespace agg
}
// Construct a matrix to transform a 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)
{
rect_to_parl(x1, y1, x2, y2, parl);
}
// Construct a matrix to transform a parallelogram to a rectangle.
trans_affine(const double* parl,
trans_affine(const double* parl,
double x1, double y1, double x2, double y2)
{
parl_to_rect(parl, x1, y1, x2, y2);
@ -121,20 +121,20 @@ namespace agg
//---------------------------------- Parellelogram transformations
// Calculate a matrix to transform a parallelogram to another one.
// src and dst are pointers to arrays of three points
// (double[6], x,y,...) that identify three corners of the
// src and dst are pointers to arrays of three points
// (double[6], x,y,...) that identify three corners of the
// parallelograms assuming implicit fourth points.
// There are also transformations rectangtle to parallelogram and
// There are also transformations rectangtle to parallelogram and
// parellelogram to rectangle
const trans_affine& parl_to_parl(const double* src,
const trans_affine& parl_to_parl(const double* src,
const double* dst);
const trans_affine& rect_to_parl(double x1, double y1,
double x2, double y2,
const trans_affine& rect_to_parl(double x1, double y1,
double x2, double y2,
const double* parl);
const trans_affine& parl_to_rect(const double* parl,
double x1, double y1,
const trans_affine& parl_to_rect(const double* parl,
double x1, double y1,
double x2, double y2);
@ -154,8 +154,8 @@ namespace agg
// Multiply inverse of "m" to "this" and assign the result to "this"
const trans_affine& premultiply_inv(const trans_affine& m);
// Invert matrix. Do not try to invert degenerate matrices,
// there's no check for validity. If you set scale to 0 and
// Invert matrix. Do not try to invert degenerate matrices,
// there's no check for validity. If you set scale to 0 and
// then try to invert matrix, expect unpredictable result.
const trans_affine& invert();
@ -180,7 +180,7 @@ namespace agg
}
//------------------------------------------- Operators
// Multiply current matrix to another one
const trans_affine& operator *= (const trans_affine& m)
{
@ -200,7 +200,7 @@ namespace agg
return trans_affine(*this).multiply(m);
}
// Multiply current matrix to inverse of another one
// Multiply current matrix to inverse of another one
// and return the result in a separete matrix.
trans_affine operator / (const trans_affine& m) const
{
@ -233,8 +233,8 @@ namespace agg
// Direct transformation x and y, 2x2 matrix only, no translation
void transform_2x2(double* x, double* y) const;
// Inverse transformation x and y. It works slower than the
// direct transformation, so if the performance is critical
// Inverse transformation x and y. It works slower than the
// direct transformation, so if the performance is critical
// it's better to invert() the matrix and then use transform()
void inverse_transform(double* x, double* y) const;
@ -245,7 +245,7 @@ namespace agg
return 1.0 / (m0 * m3 - m1 * m2);
}
// Get the average scale (by X and Y).
// Get the average scale (by X and Y).
// Basically used to calculate the approximation_scale when
// decomposinting curves into line segments.
double scale() const;
@ -304,8 +304,8 @@ namespace agg
//------------------------------------------------------------------------
inline double trans_affine::scale() const
{
double x = 0.707106781 * m0 + 0.707106781 * m2;
double y = 0.707106781 * m1 + 0.707106781 * m3;
double x = M_SQRT1_2 * m0 + M_SQRT1_2 * m2;
double y = M_SQRT1_2 * m1 + M_SQRT1_2 * m3;
return sqrt(x*x + y*y);
}
@ -336,12 +336,12 @@ namespace agg
//====================================================trans_affine_rotation
// 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
// 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.
class trans_affine_rotation : public trans_affine
{
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)
{}
};
@ -351,11 +351,11 @@ namespace agg
class trans_affine_scaling : public trans_affine
{
public:
trans_affine_scaling(double sx, double sy) :
trans_affine_scaling(double sx, double sy) :
trans_affine(sx, 0.0, 0.0, sy, 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)
{}
};
@ -365,7 +365,7 @@ namespace agg
class trans_affine_translation : public trans_affine
{
public:
trans_affine_translation(double tx, double ty) :
trans_affine_translation(double tx, double ty) :
trans_affine(1.0, 0.0, 0.0, 1.0, tx, ty)
{}
};
@ -375,19 +375,19 @@ namespace agg
class trans_affine_skewing : public trans_affine
{
public:
trans_affine_skewing(double sx, double sy) :
trans_affine_skewing(double sx, double sy) :
trans_affine(1.0, tan(sy), tan(sx), 1.0, 0.0, 0.0)
{}
};
//===============================================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
class trans_affine_line_segment : public trans_affine
{
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 dx = x2 - x1;