S1m.h
Go to the documentation of this file.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
00030
00032
00033
00034
00035 #ifndef __S1M_H_
00036 #define __S1M_H_
00037
00038 #ifdef MIP_HOST_APPLE
00039 #include <applePatch.h>
00040 #endif
00041
00042 #include <stdio.h>
00043 #include <math.h>
00044 #include <vector>
00045 #include <iostream>
00046 #include <string>
00047 #include <sstream>
00048 #include <sys/time.h>
00049 #include <sys/select.h>
00050 #include <assert.h>
00051
00052 #ifdef FOUND_BOOST_SER
00053 #include <boost/serialization/vector.hpp>
00054 #include <boost/archive/text_iarchive.hpp>
00055 #include <boost/archive/text_oarchive.hpp>
00056 #endif
00057
00058 #include <Types.h>
00059 #include <numTools.h>
00060
00061
00062 #define MPIm 18000
00063
00064
00065
00066
00067
00068
00069 inline double cos(UCoordmm a){
00070 return cos((double)a*M_PI/MPIm);
00071 }
00072
00073 inline double sin(UCoordmm a){
00074 return sin((double)a*M_PI/MPIm);
00075 }
00076
00077 using namespace std;
00078
00079
00080
00084 class Anglem{
00085 private:
00086 #ifdef FOUND_BOOST_SER
00087 friend class boost::serialization::access;
00088 template<class Archive>
00089 void serialize(Archive & ar, const unsigned int version){
00090 ar & theta;
00091 }
00092 #endif
00093
00094 UCoordmm theta;
00095 static const UCoordmm M2PIm=2*MPIm;
00096
00098 UCoordmm norm2Pi(UCoordmm a){
00099 if (a >= M2PIm){
00100 a-=M2PIm;
00101 }
00102 return a;
00103 }
00105 UCoordmm norm2Pi(Coordmm a){
00106 if (a >= 0){
00107 return a;
00108 } else {
00109
00110
00111 return (UCoordmm)a;
00112 }
00113 }
00115 UCoordmm norm2Pi(int a){
00116 a = a%M2PIm;
00117 if (a < 0){
00118 a+=M2PIm;
00119 }
00120 return a;
00121 }
00123 Coordmm normPi(Coordmm a){
00124 if (a<=-MPIm) {
00125 a+=MPIm;
00126 a+=MPIm;
00127 }
00128 if (a>MPIm) {
00129 a-=MPIm;
00130 a-=MPIm;
00131 }
00132 return a;
00133 }
00135 Coordmm normPi(UCoordmm a){
00136 UCoordmm b = norm2Pi(a);
00137 if (b>MPIm){
00138 UCoordmm c = b - MPIm;
00139 return -MPIm + c;
00140 } else {
00141 return b;
00142 }
00143 }
00145 Coordmm normPi(int a){
00146 a = norm2Pi(a);
00147 if (a > MPIm){
00148 a-=MPIm;
00149 }
00150 return a;
00151 }
00152 public:
00154 Anglem() {
00155 theta = 0;
00156 };
00158 Anglem(UCoordmm t) {
00159 theta = norm2Pi(t);
00160 };
00162 Anglem(const Anglem& rhs) {
00163 theta = norm2Pi(rhs.dCast());
00164 };
00166 Anglem& operator=(const Anglem& rhs){
00167 if (this != &rhs){
00168 theta = norm2Pi(rhs.dCast());
00169 }
00170 return *this;
00171 }
00173 Anglem& operator+=(const Anglem& a) {
00174 theta = norm2Pi( (int)theta + (int)(a.theta) );
00175 return *this;
00176 }
00178 Anglem& operator-=(const Anglem& a) {
00179 if (theta >= a.theta){
00180 theta = theta - a.theta;
00181 } else {
00182 int th = (int)theta - (int)(a.theta);
00183 theta = th + M2PIm;
00184 }
00185
00186
00187 return *this;
00188 }
00189
00190
00191
00192
00193
00195 Anglem& operator*=(const Coordmm& d) {
00196 theta = norm2Pi( (int)theta*(int)d );
00197 return *this;
00198 }
00200 Anglem& operator*=(const UCoordmm& d) {
00201 theta = norm2Pi( (int)theta*(int)d );
00202 return *this;
00203 }
00205 Anglem& operator*=(const int& d) {
00206 theta = norm2Pi( (int)theta * d);
00207 return *this;
00208 }
00210 const Anglem operator+(const Anglem &other) const {
00211 return Anglem(*this) += other;
00212 }
00214 const Anglem operator-(const Anglem &other) const {
00215 return Anglem(*this) -= other;
00216 }
00217
00218
00219
00220
00222 const Anglem operator*(const Coordmm& d) const {
00223 return (Anglem(*this) *= d);
00224 }
00226 const Anglem operator*(const UCoordmm& d) const {
00227 return (Anglem(*this) *= d);
00228 }
00230 const Anglem operator*(const int& d) const {
00231 return (Anglem(*this) *= d);
00232 }
00234 bool operator==(const Anglem &other) const {
00235 if( (other.dCast()) == theta) return true;
00236 else return false;
00237 }
00239 bool operator!=(const Anglem &other) const {
00240 return !(*this == other);
00241 }
00243 UCoordmm dCast() const {
00244 return theta;
00245 }
00247 Coordmm dCastPi() {
00248 return normPi(theta);
00249 }
00251 Coordmm dCastDeg() {
00252 return ((int)theta*180)/MPIm;
00253 }
00255 Decimal dCastPiDecimal() {
00256 return ((Decimal)theta)/100.0;
00257 }
00258
00263 Coordmm alDiff(const Anglem &other);
00264
00269 Coordmm ccwDiff(const Anglem &other);
00270
00275 Coordmm cwDiff(const Anglem &other);
00276
00281 bool almostEqual(Anglem A, Coordmm toll);
00282
00286 Anglem mean(const Anglem &other);
00287
00292 Anglem ccwMean(const Anglem &other);
00293
00298 Anglem cwMean(const Anglem &other);
00299
00302 string print();
00303 };
00304
00305
00306
00307 #endif
00308
00309
00310
00311