inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
{
- return m_x == pt.m_x && m_y == pt.m_y;
+ return wxIsSameDouble(m_x, pt.m_x) && wxIsSameDouble(m_y, pt.m_y);
}
inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
{
- return m_x != pt.m_x || m_y != pt.m_y;
+ return !(*this == pt);
}
inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
{ return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
inline bool IsEmpty() const
- { return ( m_width <= 0 || m_height <= 0 ); }
+ { return m_width <= 0 || m_height <= 0; }
inline bool HaveEqualSize( const wxRect2DDouble &rect ) const
- { return ( rect.m_width == m_width && rect.m_height == m_height ); }
+ { return wxIsSameDouble(rect.m_width, m_width) && wxIsSameDouble(rect.m_height, m_height); }
inline void Inset( wxDouble x , wxDouble y )
{ m_x += x; m_y += y; m_width -= 2 * x; m_height -= 2 * y; }
wxRect2DDouble& operator = (const wxRect2DDouble& rect);
inline bool operator == (const wxRect2DDouble& rect) const
- { return (m_x==rect.m_x && m_y==rect.m_y && m_width==rect.m_width && m_height==rect.m_height); }
+ { return wxIsSameDouble(m_x, rect.m_x) && wxIsSameDouble(m_y, rect.m_y) && HaveEqualSize(rect); }
inline bool operator != (const wxRect2DDouble& rect) const
{ return !(*this == rect); }
inline bool wxTransformMatrix::IsIdentity1(void) const
{
return
- (m_matrix[0][0] == 1.0 &&
- m_matrix[1][1] == 1.0 &&
- m_matrix[2][2] == 1.0 &&
- m_matrix[1][0] == 0.0 &&
- m_matrix[2][0] == 0.0 &&
- m_matrix[0][1] == 0.0 &&
- m_matrix[2][1] == 0.0 &&
- m_matrix[0][2] == 0.0 &&
- m_matrix[1][2] == 0.0) ;
+ ( wxIsSameDouble(m_matrix[0][0], 1.0) &&
+ wxIsSameDouble(m_matrix[1][1], 1.0) &&
+ wxIsSameDouble(m_matrix[2][2], 1.0) &&
+ wxIsSameDouble(m_matrix[1][0], 0.0) &&
+ wxIsSameDouble(m_matrix[2][0], 0.0) &&
+ wxIsSameDouble(m_matrix[0][1], 0.0) &&
+ wxIsSameDouble(m_matrix[2][1], 0.0) &&
+ wxIsSameDouble(m_matrix[0][2], 0.0) &&
+ wxIsSameDouble(m_matrix[1][2], 0.0) );
}
// Calculates the determinant of a 2 x 2 matrix
return a11 * a22 - a12 * a21;
}
-#endif
- // _WX_MATRIXH__
+#endif // _WX_MATRIXH__
#endif
#include "wx/dc.h"
+#include "wx/math.h"
// bool wxDCBase::sm_cacheing = false;
{
int totalWidth = 0;
- size_t i, len = text.Length();
+ const size_t len = text.Length();
widths.Empty();
widths.Add(0, len);
- int w, h;
// reset the cache if font or horizontal scale have changed
- if (!s_fontWidthCache.m_widths ||
- (s_fontWidthCache.m_scaleX != m_scaleX) ||
- (s_fontWidthCache.m_font != GetFont()))
+ if ( !s_fontWidthCache.m_widths ||
+ !wxIsSameDouble(s_fontWidthCache.m_scaleX, m_scaleX) ||
+ (s_fontWidthCache.m_font != GetFont()) )
{
s_fontWidthCache.Reset();
s_fontWidthCache.m_font = GetFont();
// Calculate the position of each character based on the widths of
// the previous characters
- for (i=0; i<len; i++)
+ int w, h;
+ for ( size_t i = 0; i < len; i++ )
{
const wxChar c = text[i];
unsigned int c_int = (unsigned int)c;
wxDouble wxPoint2DDouble::GetVectorAngle() const
{
- if ( m_x == 0 )
+ if ( wxIsNullDouble(m_x) )
{
if ( m_y >= 0 )
return 90;
else
return 270;
}
- if ( m_y == 0 )
+ if ( wxIsNullDouble(m_y) )
{
if ( m_x >= 0 )
return 0;
wxImage::HSVValue wxImage::RGBtoHSV(const RGBValue& rgb)
{
- double hue, saturation, value;
-
const double red = rgb.red / 255.0,
green = rgb.green / 255.0,
blue = rgb.blue / 255.0;
+ // find the min and max intensity (and remember which one was it for the
+ // latter)
double minimumRGB = red;
- if (green < minimumRGB)
+ if ( green < minimumRGB )
minimumRGB = green;
-
- if (blue < minimumRGB)
+ if ( blue < minimumRGB )
minimumRGB = blue;
+ enum { RED, GREEN, BLUE } chMax = RED;
double maximumRGB = red;
- if (green > maximumRGB)
+ if ( green > maximumRGB )
+ {
+ chMax = GREEN;
maximumRGB = green;
-
- if (blue > maximumRGB)
+ }
+ if ( blue > maximumRGB )
+ {
+ chMax = BLUE;
maximumRGB = blue;
+ }
- value = maximumRGB;
+ const double value = maximumRGB;
- if (maximumRGB == minimumRGB)
+ double hue, saturation;
+ const double deltaRGB = maximumRGB - minimumRGB;
+ if ( wxIsNullDouble(deltaRGB) )
{
// Gray has no color
hue = 0.0;
}
else
{
- double deltaRGB = maximumRGB - minimumRGB;
+ switch ( chMax )
+ {
+ case RED:
+ hue = (green - blue) / deltaRGB;
+ break;
- saturation = deltaRGB / maximumRGB;
+ case GREEN:
+ hue = 2.0 + (blue - red) / deltaRGB;
+ break;
- if ( red == maximumRGB )
- hue = (green - blue) / deltaRGB;
- else if (green == maximumRGB)
- hue = 2.0 + (blue - red) / deltaRGB;
- else
- hue = 4.0 + (red - green) / deltaRGB;
+ case BLUE:
+ hue = 4.0 + (red - green) / deltaRGB;
+ break;
+ }
+
+ hue /= 6.0;
- hue = hue / 6.0;
+ if ( hue < 0.0 )
+ hue += 1.0;
- if (hue < 0.0)
- hue = hue + 1.0;
+ saturation = deltaRGB / maximumRGB;
}
return HSVValue(hue, saturation, value);
{
double red, green, blue;
- if ( hsv.saturation == 0.0 )
+ if ( wxIsNullDouble(hsv.saturation) )
{
- red = hsv.value; //Grey
+ // Grey
+ red = hsv.value;
green = hsv.value;
- blue = hsv.value;
+ blue = hsv.value;
}
- else
+ else // not grey
{
double hue = hsv.hue * 6.0; // sector 0 to 5
int i = (int)floor(hue);
wxASSERT (angle >= -1.0 && angle <= 1.0);
count = M_IMGDATA->m_width * M_IMGDATA->m_height;
- if (count > 0 && angle != 0.0)
+ if ( count > 0 && !wxIsNullDouble(angle) )
{
srcBytePtr = M_IMGDATA->m_data;
dstBytePtr = srcBytePtr;
{
for (j = 0; j < 3; j++)
{
- if (m_matrix[i][j] != mat.m_matrix[i][j])
+ if ( !wxIsSameDouble(m_matrix[i][j], mat.m_matrix[i][j]) )
return false;
}
}
// now divide by the determinant
double det = m_matrix[0][0] * inverseMatrix[0][0] + m_matrix[0][1] * inverseMatrix[1][0] + m_matrix[0][2] * inverseMatrix[2][0];
- if (det != 0.0)
- {
- inverseMatrix[0][0] /= det; inverseMatrix[1][0] /= det; inverseMatrix[2][0] /= det;
- inverseMatrix[0][1] /= det; inverseMatrix[1][1] /= det; inverseMatrix[2][1] /= det;
- inverseMatrix[0][2] /= det; inverseMatrix[1][2] /= det; inverseMatrix[2][2] /= det;
+ if ( wxIsNullDouble(det) )
+ return false;
+
+ inverseMatrix[0][0] /= det; inverseMatrix[1][0] /= det; inverseMatrix[2][0] /= det;
+ inverseMatrix[0][1] /= det; inverseMatrix[1][1] /= det; inverseMatrix[2][1] /= det;
+ inverseMatrix[0][2] /= det; inverseMatrix[1][2] /= det; inverseMatrix[2][2] /= det;
- int i, j;
- for (i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
{
- for (j = 0; j < 3; j++)
- {
- m_matrix[i][j] = inverseMatrix[i][j];
- }
+ m_matrix[i][j] = inverseMatrix[i][j];
}
- m_isIdentity = IsIdentity1();
- return true;
- }
- else
- {
- return false;
}
+ m_isIdentity = IsIdentity1();
+ return true;
}
// Make into identity matrix
if (m_isIdentity)
{
- double tx =xc*(1-xs);
- double ty =yc*(1-ys);
+ double tx = xc*(1-xs);
+ double ty = yc*(1-ys);
r00 = xs;
r10 = 0;
r20 = tx;
r11 = ys;
r21 = ty;
}
- else if (xc!=0 || yc!=0)
+ else if ( !wxIsNullDouble(xc) || !wxIsNullDouble(yc) )
{
- double tx =xc*(1-xs);
- double ty =yc*(1-ys);
+ double tx = xc*(1-xs);
+ double ty = yc*(1-ys);
r00 = xs * m_matrix[0][0];
r10 = xs * m_matrix[1][0];
r20 = xs * m_matrix[2][0] + tx;
if (m_isIdentity)
{
- double tx = x*(1-c)+y*s;
- double ty = y*(1-c)-x*s;
+ double tx = x*(1-c)+y*s;
+ double ty = y*(1-c)-x*s;
r00 = c ;
r10 = -s;
r20 = tx;
r11 = c;
r21 = ty;
}
- else if (x!=0 || y!=0)
+ else if ( !wxIsNullDouble(x) || !wxIsNullDouble(y) )
{
- double tx = x*(1-c)+y*s;
- double ty = y*(1-c)-x*s;
+ double tx = x*(1-c)+y*s;
+ double ty = y*(1-c)-x*s;
r00 = c * m_matrix[0][0] - s * m_matrix[0][1] + tx * m_matrix[0][2];
r10 = c * m_matrix[1][0] - s * m_matrix[1][1] + tx * m_matrix[1][2];
r20 = c * m_matrix[2][0] - s * m_matrix[2][1] + tx;// * m_matrix[2][2];
{
if (IsIdentity())
{
- tx = x; ty = y; return true;
+ tx = x;
+ ty = y;
+ return true;
}
- double z = (1.0 - m_matrix[0][2] * x - m_matrix[1][2] * y) / m_matrix[2][2];
- if (z == 0.0)
- {
-// z = 0.0000001;
+ const double z = (1.0 - m_matrix[0][2] * x - m_matrix[1][2] * y) / m_matrix[2][2];
+ if ( wxIsNullDouble(z) )
return false;
- }
+
tx = x * m_matrix[0][0] + y * m_matrix[1][0] + z * m_matrix[2][0];
ty = x * m_matrix[0][1] + y * m_matrix[1][1] + z * m_matrix[2][1];
return true;
{
double scale_factor;
double rot_angle = CheckInt(atan2(m_matrix[1][0],m_matrix[0][0])*180/pi);
- if (rot_angle != 90 && rot_angle != -90)
+ if ( !wxIsSameDouble(rot_angle, 90) && !wxIsSameDouble(rot_angle, -90) )
scale_factor = m_matrix[0][0]/cos((rot_angle/180)*pi);
else
scale_factor = m_matrix[0][0]/sin((rot_angle/180)*pi); // er kan nl. niet door 0 gedeeld worden !
{
double scale_factor;
double rot_angle = CheckInt(atan2(m_matrix[1][0],m_matrix[0][0])*180/pi);
- if (rot_angle != 90 && rot_angle != -90)
+ if ( !wxIsSameDouble(rot_angle, 90) && !wxIsSameDouble(rot_angle, -90) )
scale_factor = m_matrix[1][1]/cos((rot_angle/180)*pi);
else
scale_factor = m_matrix[1][1]/sin((rot_angle/180)*pi); // er kan nl. niet door 0 gedeeld worden !
alpha1 = 0.0;
alpha2 = 360.0;
}
- else if (radius == 0.0)
+ else if ( wxIsNullDouble(radius) )
{
- alpha1 = alpha2 = 0.0;
+ alpha1 =
+ alpha2 = 0.0;
}
else
{
{
wxCHECK_RET( m_ok, wxT("invalid postscript dc") );
- if (sa>=360 || sa<=-360) sa=sa-int(sa/360)*360;
- if (ea>=360 || ea<=-360) ea=ea-int(ea/360)*360;
- if (sa<0) sa+=360;
- if (ea<0) ea+=360;
+ if ( sa >= 360 || sa <= -360 )
+ sa -= int(sa/360)*360;
+ if ( ea >= 360 || ea <=- 360 )
+ ea -= int(ea/360)*360;
+ if ( sa < 0 )
+ sa += 360;
+ if ( ea < 0 )
+ ea += 360;
- if (sa==ea)
+ if ( wxIsSameDouble(sa, ea) )
{
DrawEllipse(x,y,w,h);
return;
void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle )
{
- if (angle == 0.0)
+ if ( wxIsNullDouble(angle) )
{
DoDrawText(text, x, y);
return;
#include "wx/combobox.h"
#include "wx/valtext.h"
#include "wx/intl.h"
+ #include "wx/math.h"
#endif
#include "wx/textfile.h"
double value = 0.0;
wxString text(Text()->GetValue());
- if ( (text.empty() || text.ToDouble(&value)) && (value != m_valueOld) )
+ if ( (text.empty() || text.ToDouble(&value)) &&
+ !wxIsSameDouble(value, m_valueOld) )
{
if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT))
grid->GetTable()->SetValueAsDouble(row, col, value);
radius1 = 0.0;
radius2 = 360.0;
}
- else
- if (radius == 0.0)
+ else if ( wxIsNullDouble(radius) )
{
- radius1 = radius2 = 0.0;
+ radius1 =
+ radius2 = 0.0;
}
else
{
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
{
- if (angle == 0.0)
+ if ( wxIsNullDouble(angle) )
{
DrawText(text, x, y);
return;
void wxWindowDC::ComputeScaleAndOrigin()
{
- /* CMB: copy scale to see if it changes */
- double origScaleX = m_scaleX;
- double origScaleY = m_scaleY;
+ const wxRealPoint origScale(m_scaleX, m_scaleY);
wxDC::ComputeScaleAndOrigin();
- /* CMB: if scale has changed call SetPen to recalulate the line width */
- if ((m_scaleX != origScaleX || m_scaleY != origScaleY) &&
- (m_pen.Ok()))
+ // if scale has changed call SetPen to recalulate the line width
+ if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.Ok() )
{
- /* this is a bit artificial, but we need to force wxDC to think
- the pen has changed */
+ // this is a bit artificial, but we need to force wxDC to think the pen
+ // has changed
wxPen pen = m_pen;
m_pen = wxNullPen;
SetPen( pen );
else // wxALIGN_LEFT
xalign = 0.0;
- if ( xalign )
+ if ( style & (wxALIGN_RIGHT | wxALIGN_CENTER) ) // left alignment is default
gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.5);
return TRUE;
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/log.h"
+#include "wx/math.h"
#include "wx/settings.h"
#include "wx/panel.h"
#include "wx/strconv.h"
GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget) );
// Scroll to cursor, but only if scrollbar thumb is at the very bottom
- if ( adj->value == adj->upper - adj->page_size )
+ if ( wxIsSameDouble(adj->value, adj->upper - adj->page_size) )
{
gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text),
gtk_text_buffer_get_insert( m_buffer ), 0.0, FALSE, 0.0, 1.0 );
radius1 = 0.0;
radius2 = 360.0;
}
- else
- if (radius == 0.0)
+ else if ( wxIsNullDouble(radius) )
{
- radius1 = radius2 = 0.0;
+ radius1 =
+ radius2 = 0.0;
}
else
{
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
{
- if (angle == 0.0)
+ if ( wxIsNullDouble(angle) )
{
DrawText(text, x, y);
return;
void wxWindowDC::ComputeScaleAndOrigin()
{
- /* CMB: copy scale to see if it changes */
- double origScaleX = m_scaleX;
- double origScaleY = m_scaleY;
+ const wxRealPoint origScale(m_scaleX, m_scaleY);
wxDC::ComputeScaleAndOrigin();
- /* CMB: if scale has changed call SetPen to recalulate the line width */
- if ((m_scaleX != origScaleX || m_scaleY != origScaleY) &&
- (m_pen.Ok()))
+ // if scale has changed call SetPen to recalulate the line width
+ if ( wxRealPoint(m_scaleX, m_scaleY) != origScale && m_pen.Ok() )
{
- /* this is a bit artificial, but we need to force wxDC to think
- the pen has changed */
+ // this is a bit artificial, but we need to force wxDC to think the pen
+ // has changed
wxPen pen = m_pen;
m_pen = wxNullPen;
SetPen( pen );
else // wxALIGN_LEFT
xalign = 0.0;
- if ( xalign )
+ if ( style & (wxALIGN_RIGHT | wxALIGN_CENTER) ) // left alignment is default
gtk_frame_set_label_align(GTK_FRAME( m_widget ), xalign, 0.5);
return TRUE;
#include "wx/utils.h"
#include "wx/intl.h"
#include "wx/log.h"
+#include "wx/math.h"
#include "wx/settings.h"
#include "wx/panel.h"
#include "wx/strconv.h"
GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget) );
// Scroll to cursor, but only if scrollbar thumb is at the very bottom
- if ( adj->value == adj->upper - adj->page_size )
+ if ( wxIsSameDouble(adj->value, adj->upper - adj->page_size) )
{
gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text),
gtk_text_buffer_get_insert( m_buffer ), 0.0, FALSE, 0.0, 1.0 );