00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanTripoint.h"
00028
00029 #include "CeylanVector3.h"
00030 #include "CeylanMatrix3.h"
00031
00032
00033 #include "CeylanLogPlug.h"
00034 #include "CeylanOperators.h"
00035
00036
00037 #ifdef CEYLAN_USES_CONFIG_H
00038 #include "CeylanConfig.h"
00039 #endif // CEYLAN_USES_CONFIG_H
00040
00041
00042 #include <iostream>
00043 using std::endl ;
00044
00045 #include <sstream>
00046 using std::ostringstream ;
00047
00048 #include <iomanip>
00049
00050
00051
00052 using std::string ;
00053
00054 using namespace Ceylan ;
00055 using namespace Ceylan::Maths ;
00056 using namespace Ceylan::Maths::Linear ;
00057
00058 using Ceylan::Maths::Real ;
00059
00060
00061
00062 Tripoint::Tripoint( Real x0, Real x1, Real x2 )
00063 {
00064
00065 _coordinates[0] = x0 ;
00066 _coordinates[1] = x1 ;
00067 _coordinates[2] = x2 ;
00068
00069 }
00070
00071
00072
00073 Tripoint::~Tripoint() throw()
00074 {
00075
00076 }
00077
00078
00079
00080 void Tripoint::setTo( Real x0, Real x1, Real x2 )
00081 {
00082
00083 _coordinates[0] = x0 ;
00084 _coordinates[1] = x1 ;
00085 _coordinates[2] = x2 ;
00086
00087 }
00088
00089
00090
00091 void Tripoint::setAllElementsTo( Real commonValue )
00092 {
00093
00094 for ( MatrixIndex i = 0; i < Dimensions; i++ )
00095 {
00096 _coordinates[i] = 0 ;
00097 }
00098
00099 }
00100
00101
00102
00103 Real Tripoint::getElementAt( MatrixIndex index ) const
00104 {
00105
00106 #if CEYLAN_DEBUG
00107
00108 if ( index >= Dimensions )
00109 throw MathsException(
00110 "Tripoint::getElementAt: index out of bounds." ) ;
00111
00112 #endif // CEYLAN_DEBUG
00113
00114 return _coordinates[ index ] ;
00115
00116 }
00117
00118
00119
00120 void Tripoint::setElementAt( MatrixIndex index, Real newValue )
00121 {
00122
00123 #if CEYLAN_DEBUG
00124
00125 if ( index >= Dimensions )
00126 throw MathsException(
00127 "Tripoint::setElementAt: index out of bounds." ) ;
00128
00129 #endif // CEYLAN_DEBUG
00130
00131 _coordinates[ index ] = newValue ;
00132
00133 }
00134
00135
00136
00137 const string Tripoint::toString( VerbosityLevels level ) const
00138 {
00139
00140 string res ;
00141
00142 if ( TextDisplayable::GetOutputFormat() == TextDisplayable::html )
00143 {
00144
00145 res = "<table border=1>" ;
00146
00147 res += " <tr>\n" ;
00148
00149 for ( MatrixIndex i = 0; i < Dimensions; i++ )
00150 {
00151 res += " <tr>\n" ;
00152 res += " <td>" + Ceylan::toString( _coordinates[i] ) + "</td>" ;
00153 res += " </tr>\n" ;
00154 }
00155
00156 res += "</table>" ;
00157
00158
00159 return res ;
00160 }
00161
00162
00163
00164 if ( level == high )
00165 {
00166
00167 ostringstream oss ;
00168
00169 oss.precision( Ceylan::DigitOutputPrecision ) ;
00170
00171 oss << endl ;
00172
00173 for ( MatrixIndex i = 0; i < Dimensions; i++ )
00174 {
00175 oss << "[ " << std::setw(5) << _coordinates[i] <<" ]" << endl ;
00176 }
00177
00178 oss << endl ;
00179
00180 res = oss.str() ;
00181
00182 #if CEYLAN_DEBUG
00183
00184 if ( oss.fail() )
00185 {
00186 string message = "Tripoint::toString: conversion error." ;
00187 Log::LogPlug::error( message ) ;
00188 return message ;
00189 }
00190
00191 #endif // CEYLAN_DEBUG
00192
00193 return res ;
00194 }
00195 else
00196 {
00197
00198 res = "Tripoint: [ " ;
00199
00200 for ( MatrixIndex i = 0; i < Dimensions; i++ )
00201 {
00202 res += Ceylan::toString( _coordinates[i] )
00203 + ( ( i == Dimensions-1 ) ? " ]": " ; " ) ;
00204 }
00205
00206 return res ;
00207
00208 }
00209
00210
00211 return res ;
00212
00213 }
00214
00215
00216
00217 bool Ceylan::Maths::Linear::operator == ( const Tripoint & t1,
00218 const Tripoint & t2 )
00219 {
00220
00221 for ( MatrixIndex i = 0; i < Tripoint::Dimensions; i++ )
00222 {
00223
00224
00225
00226
00227
00228
00229 if ( ! AreRelativelyEqual<Real>( t1._coordinates[i],
00230 t2._coordinates[i] ) )
00231 return false ;
00232
00233 }
00234
00235 return true ;
00236
00237 }
00238
00239
00240
00241 bool Ceylan::Maths::Linear::operator != ( const Tripoint & t1,
00242 const Tripoint & t2 )
00243 {
00244
00245 return ( ! ( t1 == t2 ) ) ;
00246
00247 }
00248
00249
00250
00251 Tripoint Ceylan::Maths::Linear::operator + ( const Tripoint & t ,
00252 const Vector3 & v )
00253 {
00254
00255 Tripoint result ;
00256
00257 for ( MatrixIndex i = 0; i < Vector3::Dimensions; i++ )
00258 {
00259 result._coordinates[i] = t._coordinates[i] + v._vec[i] ;
00260 }
00261
00262 return result ;
00263
00264 }
00265
00266
00267
00268 Tripoint Ceylan::Maths::Linear::operator - ( const Tripoint & t ,
00269 const Vector3 & v )
00270 {
00271
00272 Tripoint result ;
00273
00274 for ( MatrixIndex i = 0; i < Vector3::Dimensions; i++ )
00275 {
00276 result._coordinates[i] = t._coordinates[i] - v._vec[i] ;
00277 }
00278
00279 return result ;
00280
00281 }
00282
00283
00284
00285 Vector3 Ceylan::Maths::Linear::vectorize( const Tripoint & t )
00286 {
00287
00288 Vector3 result ;
00289
00290 for ( MatrixIndex i = 0; i < Vector3::Dimensions; i++ )
00291 {
00292 result._vec[i] = t._coordinates[i] ;
00293 }
00294
00295 return result ;
00296
00297 }
00298
00299
00300
00301 Vector3 Ceylan::Maths::Linear::vectorize( const Tripoint & t1,
00302 const Tripoint & t2 )
00303 {
00304
00305 Vector3 result ;
00306
00307 for ( MatrixIndex i = 0; i < Vector3::Dimensions; i++ )
00308 {
00309 result._vec[i] = t2._coordinates[i] - t1._coordinates[i] ;
00310 }
00311
00312 return result ;
00313
00314 }
00315