📄 geometry.h
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: wx/geometry.h
// Purpose: Common Geometry Classes
// Author: Stefan Csomor
// Modified by:
// Created: 08/05/99
// RCS-ID:
// Copyright: (c) 1999 Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GEOMETRY_H_
#define _WX_GEOMETRY_H_
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "geometry.cpp"
#endif
#include "wx/defs.h"
#ifndef wxUSE_GEOMETRY
#define wxUSE_GEOMETRY 0
#endif
#if wxUSE_GEOMETRY
#include "wx/utils.h"
#include "wx/gdicmn.h"
#include <math.h>
#ifdef __WXMSW__
#define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
#elif defined( __WXMAC__ )
#define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) )
#else
#define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
#endif
class wxDataInputStream;
class wxDataOutputStream;
// clipping from Cohen-Sutherland
enum wxOutCode
{
wxInside = 0x00 ,
wxOutLeft = 0x01 ,
wxOutRight = 0x02 ,
wxOutTop = 0x08 ,
wxOutBottom = 0x04
};
class WXDLLEXPORT wxPoint2DInt
{
public :
inline wxPoint2DInt();
inline wxPoint2DInt( wxInt32 x , wxInt32 y );
inline wxPoint2DInt( const wxPoint2DInt &pt );
inline wxPoint2DInt( const wxPoint &pt );
// noops for this class, just return the coords
inline void GetFloor( wxInt32 *x , wxInt32 *y ) const;
inline void GetRounded( wxInt32 *x , wxInt32 *y ) const;
inline wxDouble GetVectorLength() const;
wxDouble GetVectorAngle() const;
inline void SetVectorLength( wxDouble length );
void SetVectorAngle( wxDouble degrees );
void SetPolarCoordinates( wxInt32 angle , wxInt32 length );
// set the vector length to 1.0, preserving the angle
inline void Normalize();
inline wxDouble GetDistance( const wxPoint2DInt &pt ) const;
inline wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const;
inline wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const;
inline wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const;
// the reflection of this point
inline wxPoint2DInt operator-();
inline wxPoint2DInt& operator=(const wxPoint2DInt& pt);
inline wxPoint2DInt& operator+=(const wxPoint2DInt& pt);
inline wxPoint2DInt& operator-=(const wxPoint2DInt& pt);
inline wxPoint2DInt& operator*=(const wxPoint2DInt& pt);
inline wxPoint2DInt& operator*=(wxDouble n);
inline wxPoint2DInt& operator*=(wxInt32 n);
inline wxPoint2DInt& operator/=(const wxPoint2DInt& pt);
inline wxPoint2DInt& operator/=(wxDouble n);
inline wxPoint2DInt& operator/=(wxInt32 n);
inline operator wxPoint() const;
inline bool operator==(const wxPoint2DInt& pt) const;
inline bool operator!=(const wxPoint2DInt& pt) const;
void WriteTo( wxDataOutputStream &stream ) const;
void ReadFrom( wxDataInputStream &stream );
wxInt32 m_x;
wxInt32 m_y;
};
inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt::wxPoint2DInt()
{
m_x = 0;
m_y = 0;
}
inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
{
m_x = x;
m_y = y;
}
inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
{
m_x = pt.m_x;
m_y = pt.m_y;
}
inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
{
m_x = pt.x;
m_y = pt.y;
}
inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y ) const
{
if ( x )
*x = m_x;
if ( y )
*y = m_y;
}
inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y ) const
{
GetFloor(x, y);
}
inline wxDouble wxPoint2DInt::GetVectorLength() const
{
// cast needed MIPSpro compiler under SGI
return sqrt( (double)(m_x)*(m_x) + (m_y)*(m_y) );
}
inline void wxPoint2DInt::SetVectorLength( wxDouble length )
{
wxDouble before = GetVectorLength();
m_x = (wxInt32)(m_x * length / before);
m_y = (wxInt32)(m_y * length / before);
}
inline void wxPoint2DInt::Normalize()
{
SetVectorLength( 1 );
}
inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
{
return sqrt( GetDistanceSquare( pt ) );
}
inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const
{
return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) );
}
inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
{
return ( m_x * vec.m_x + m_y * vec.m_y );
}
inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
{
return ( m_x * vec.m_y - vec.m_x * m_y );
}
inline wxPoint2DInt::operator wxPoint() const
{
return wxPoint( m_x, m_y);
}
inline wxPoint2DInt wxPoint2DInt::operator-()
{
return wxPoint2DInt( -m_x, -m_y);
}
inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
{
m_x = pt.m_x;
m_y = pt.m_y;
return *this;
}
inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
{
m_x = m_x + pt.m_x;
m_y = m_y + pt.m_y;
return *this;
}
inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
{
m_x = m_x - pt.m_x;
m_y = m_y - pt.m_y;
return *this;
}
inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
{
m_x = m_x + pt.m_x;
m_y = m_y + pt.m_y;
return *this;
}
inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
{
m_x = m_x - pt.m_x;
m_y = m_y - pt.m_y;
return *this;
}
inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
{
return m_x == pt.m_x && m_y == pt.m_y;
}
inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
{
return m_x != pt.m_x || m_y != pt.m_y;
}
inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
{
return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y );
}
inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
{
return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y );
}
inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
{
return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y );
}
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
{
return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
}
inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
{
return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
}
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
{
return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
}
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -