00001 #include "OSDLPoint2D.h" 00002 00003 00004 00005 00006 using std::string ; 00007 using std::list ; 00008 00009 using namespace OSDL::Video::TwoDimensional ; 00010 00011 00012 const Point2D Point2D::Origin( static_cast<Coordinate>( 0 ), 0 ) ; 00013 00014 00015 Point2D::Point2D( Coordinate x, Coordinate y ) throw() 00016 { 00017 00018 _coord[0] = x ; 00019 _coord[1] = y ; 00020 00021 } 00022 00023 00024 Point2D::Point2D( const Point2D & source ) throw() : 00025 Point() 00026 { 00027 00028 _coord[0] = source._coord[0] ; 00029 _coord[1] = source._coord[1] ; 00030 00031 } 00032 00033 00034 Point2D::Point2D( const Ceylan::Maths::Linear::Bipoint & source ) throw() 00035 { 00036 00037 _coord[0] = static_cast<Coordinate>( source.getX() ) ; 00038 _coord[1] = static_cast<Coordinate>( source.getY() ) ; 00039 00040 } 00041 00042 00043 Point2D::Point2D( const Ceylan::Maths::Linear::Vector2 & source ) throw() 00044 { 00045 00046 _coord[0] = static_cast<Coordinate>( source.getX() ) ; 00047 _coord[1] = static_cast<Coordinate>( source.getY() ) ; 00048 00049 } 00050 00051 00052 00053 Point2D & Point2D::CreateFrom( FloatingPointCoordinate x, 00054 FloatingPointCoordinate y ) throw() 00055 { 00056 00057 return * new Point2D( static_cast<Coordinate>( x ), 00058 static_cast<Coordinate>( y ) ) ; 00059 } 00060 00061 00062 Point2D::~Point2D() throw() 00063 { 00064 00065 } 00066 00067 00068 void Point2D::setTo( Coordinate x, Coordinate y ) throw() 00069 { 00070 00071 _coord[0] = x ; 00072 _coord[1] = y ; 00073 00074 } 00075 00076 00077 void Point2D::setTo( FloatingPointCoordinate x, FloatingPointCoordinate y ) 00078 throw() 00079 { 00080 00081 _coord[0] = static_cast<Coordinate>( x ) ; 00082 _coord[1] = static_cast<Coordinate>( y ) ; 00083 00084 } 00085 00086 00087 00088 void Point2D::setFrom( const Point2D & source ) throw() 00089 { 00090 00091 _coord[0] = source._coord[0] ; 00092 _coord[1] = source._coord[1] ; 00093 00094 } 00095 00096 00097 void Point2D::setFrom( const Ceylan::Maths::Linear::Vector2 & source ) throw() 00098 { 00099 00100 _coord[0] = static_cast<Coordinate>( source.getElementAt( 0 ) ) ; 00101 _coord[1] = static_cast<Coordinate>( source.getElementAt( 1 ) ) ; 00102 00103 } 00104 00105 00106 const string Point2D::toString( Ceylan::VerbosityLevels level ) const throw() 00107 { 00108 00109 return ( string( " ( " ) 00110 + _coord[0] 00111 + string( " ; " ) 00112 + _coord[1] 00113 + string( " )" ) ) ; 00114 00115 } 00116 00117 00118 void Point2D::translate( Offset x, Offset y ) throw() 00119 { 00120 00121 _coord[0] += x ; 00122 _coord[1] += y ; 00123 00124 } 00125 00126 00127 void Point2D::flip() throw() 00128 { 00129 00130 _coord[0] = - _coord[0] ; 00131 _coord[1] = - _coord[1] ; 00132 00133 } 00134 00135 00136 void Point2D::flipX() throw() 00137 { 00138 00139 _coord[0] = - _coord[0] ; 00140 00141 } 00142 00143 00144 void Point2D::flipY() throw() 00145 { 00146 00147 _coord[1] = - _coord[1] ; 00148 00149 } 00150 00151 00152 00153 void Point2D::Translate( list<Point2D *> & pointList, Offset x, Offset y ) 00154 throw() 00155 { 00156 00157 for ( list<Point2D *>::iterator it = pointList.begin(); 00158 it != pointList.end(); it++ ) 00159 (*it)->translate( x, y ) ; 00160 00161 } 00162 00163 00164 std::ostream & operator << ( std::ostream & os, const Point2D & p ) 00165 { 00166 00167 return os << p.toString() ; 00168 00169 } 00170 00171