00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_MATHS_FUNCTION_H
00008 #define BALL_MATHS_FUNCTION_H
00009
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013
00014 namespace BALL
00015 {
00016
00021 template <int constant_template>
00022 class ConstantFunction
00023 {
00024 public:
00025
00026 BALL_CREATE(ConstantFunction)
00027
00028
00029
00032
00037 BALL_INLINE
00038 float operator () (float ) const
00039
00040 {
00041 return constant_template;
00042 }
00043
00045
00046 };
00047
00048
00054 template <typename DataType = float>
00055 class MutableConstant
00056 {
00057 public:
00058
00059 BALL_CREATE(MutableConstant)
00060
00061
00064
00067 MutableConstant()
00068 ;
00069
00072 MutableConstant(const MutableConstant<DataType>& constant)
00073 ;
00074
00077 MutableConstant(DataType constant)
00078 ;
00079
00082 virtual ~MutableConstant()
00083 ;
00084
00086
00089
00092 MutableConstant<DataType>& operator = (const MutableConstant<DataType>& constant)
00093 ;
00094
00096
00099
00102 bool operator == (const MutableConstant<DataType>& constant) const
00103 ;
00104
00106
00109
00114 BALL_INLINE
00115 DataType operator () (const DataType& ) const
00116
00117 {
00118 return constant_;
00119 }
00120
00122
00125
00128 void setConstant(DataType constant)
00129
00130 {
00131 constant_ = constant;
00132 }
00133
00137 const DataType& getConstant() const
00138
00139 {
00140 return constant_;
00141 }
00142
00144
00145 protected:
00146
00147
00148
00149 DataType constant_;
00150
00151 };
00152
00153
00157 template <typename First, typename Second, typename DataType = float>
00158 class Addition
00159 {
00160 public:
00161
00162 BALL_CREATE(Addition)
00163
00164
00167
00170 Addition()
00171 ;
00172
00175 Addition(const Addition<First, Second, DataType>& addition)
00176 ;
00177
00180 virtual ~Addition()
00181 ;
00182
00184
00187
00190 Addition<First, Second, DataType>& operator = (const Addition<First, Second, DataType>& addition)
00191 ;
00192
00194
00197
00200 bool operator == (const Addition<First, Second, DataType>& addition) const
00201 ;
00202
00204
00207
00212 BALL_INLINE
00213 DataType operator () (const DataType& x) const
00214
00215 {
00216 return (first_(x) + second_(x));
00217 }
00218
00220
00223
00226 void setFirst(const First& first)
00227
00228 {
00229 first_ = first;
00230 }
00231
00235 First& getFirst()
00236
00237 {
00238 return first_;
00239 }
00240
00243 const First& getFirst() const
00244
00245 {
00246 return first_;
00247 }
00248
00251 void setSecond(const Second& second)
00252
00253 {
00254 second_ = second;
00255 }
00256
00260 Second& getSecond()
00261
00262 {
00263 return second_;
00264 }
00265
00268 const Second& getSecond() const
00269
00270 {
00271 return second_;
00272 }
00273
00275
00276 protected:
00277
00278
00279
00280 First first_;
00281
00282
00283
00284 Second second_;
00285
00286 };
00287
00288
00292 template <typename First, typename Second, typename DataType = float>
00293 class Subtraction
00294 {
00295 public:
00296
00297 BALL_CREATE(Subtraction)
00298
00299
00302
00305 Subtraction()
00306 ;
00307
00310 Subtraction(const Subtraction& subtraction)
00311 ;
00312
00315 virtual ~Subtraction()
00316 ;
00317
00319
00322
00325 Subtraction<First, Second, DataType>& operator = (const Subtraction<First, Second, DataType>& subtraction)
00326 ;
00327
00329
00332
00335 bool operator == (const Subtraction<First, Second, DataType>& subtraction) const
00336 ;
00337
00339
00342
00347 BALL_INLINE
00348 DataType operator () (const DataType& x) const
00349
00350 {
00351 return (first_(x) - second_(x));
00352 }
00353
00355
00358
00361 void setFirst(const First& first)
00362
00363 {
00364 first_ = first;
00365 }
00366
00370 First& getFirst()
00371
00372 {
00373 return first_;
00374 }
00375
00378 void setSecond(const Second& second)
00379
00380 {
00381 second_ = second;
00382 }
00383
00387 Second& getSecond()
00388
00389 {
00390 return second_;
00391 }
00392
00394
00395 protected:
00396
00397
00398
00399 First first_;
00400
00401
00402
00403 Second second_;
00404
00405 };
00406
00407
00411 template <typename First, typename Second, typename DataType = float>
00412 class Product
00413 {
00414 public:
00415
00416 BALL_CREATE(Product)
00417
00418
00421
00424 Product()
00425 ;
00426
00429 Product(const Product& product)
00430 ;
00431
00434 virtual ~Product()
00435 ;
00436
00438
00441
00444 Product<First, Second, DataType>& operator = (const Product<First, Second, DataType>& product)
00445 ;
00446
00448
00451
00454 bool operator == (const Product<First, Second, DataType>& product) const
00455 ;
00456
00458
00461
00466 BALL_INLINE
00467 DataType operator () (const DataType& x) const
00468
00469 {
00470 return (first_(x) * second_(x));
00471 }
00472
00474
00477
00480 void setFirst(const First& first)
00481
00482 {
00483 first_ = first;
00484 }
00485
00489 First& getFirst()
00490
00491 {
00492 return first_;
00493 }
00494
00498 const First& getFirst() const
00499
00500 {
00501 return first_;
00502 }
00503
00507 void setSecond(const Second& second)
00508
00509 {
00510 second_ = second;
00511 }
00512
00516 Second& getSecond()
00517
00518 {
00519 return second_;
00520 }
00521
00523
00524 protected:
00525
00526
00527
00528 First first_;
00529
00530
00531
00532 Second second_;
00533
00534 };
00535
00536
00540 template <typename First, typename Second, typename DataType = float>
00541 class Division
00542 {
00543 public:
00544
00545 BALL_CREATE(Division)
00546
00547
00550
00553 Division()
00554 ;
00555
00558 Division(const Division& division)
00559 ;
00560
00563 virtual ~Division()
00564 ;
00565
00567
00570
00573 Division<First, Second, DataType>& operator = (const Division<First, Second, DataType>& division)
00574 ;
00575
00577
00580
00583 bool operator == (const Division<First, Second, DataType>& division) const
00584 ;
00585
00587
00590
00595 BALL_INLINE
00596 DataType operator () (const DataType& x) const
00597 throw(Exception::DivisionByZero)
00598 {
00599 DataType val = second_(x);
00600 if (val != 0.0)
00601 {
00602 return (first_(x) / val);
00603 }
00604 else
00605 {
00606 throw Exception::DivisionByZero(__FILE__, __LINE__);
00607 }
00608 }
00609
00611
00614
00617 void setFirst(const First& first)
00618
00619 {
00620 first_ = first;
00621 }
00622
00626 First& getFirst()
00627
00628 {
00629 return first_;
00630 }
00631
00634 void setSecond(const Second& second)
00635
00636 {
00637 second_ = second;
00638 }
00639
00643 Second& getSecond()
00644
00645 {
00646 return second_;
00647 }
00648
00650
00651 protected:
00652
00653
00654
00655 First first_;
00656
00657
00658
00659 Second second_;
00660
00661 };
00662
00663
00667 template <typename Function, typename DataType = float>
00668 class Reciprocal
00669 {
00670 public:
00671
00672 BALL_CREATE(Reciprocal)
00673
00674
00677
00680 Reciprocal()
00681 ;
00682
00685 Reciprocal(const Reciprocal& reciprocal)
00686 ;
00687
00690 virtual ~Reciprocal()
00691 ;
00692
00694
00697
00700 Reciprocal<Function, DataType>& operator = (const Reciprocal<Function, DataType>& reciprocal)
00701 ;
00702
00704
00707
00710 bool operator == (const Reciprocal<Function, DataType>& reciprocal) const
00711 ;
00712
00714
00717
00722 BALL_INLINE
00723 DataType operator () (const DataType& x) const
00724 throw(Exception::DivisionByZero)
00725 {
00726 DataType val = function_(x);
00727 if (val != 0)
00728 {
00729 return (1 / val);
00730 }
00731 else
00732 {
00733 throw Exception::DivisionByZero(__FILE__, __LINE__);
00734 }
00735 }
00736
00738
00741
00744 void setFunction(const Function& function)
00745
00746 {
00747 function_ = function;
00748 }
00749
00753 const Function& getFunction() const
00754
00755 {
00756 return function_;
00757 }
00758
00760
00761 protected:
00762
00763
00764
00765 Function function_;
00766
00767 };
00768
00769
00773 template <typename Function, typename DataType = float>
00774 class SquareFunction
00775 {
00776 public:
00777
00778 BALL_CREATE(SquareFunction)
00779
00780
00783
00786 SquareFunction()
00787 ;
00788
00791 SquareFunction(const SquareFunction& square)
00792 ;
00793
00796 virtual ~SquareFunction()
00797 ;
00798
00800
00803
00806 SquareFunction<Function, DataType>& operator = (const SquareFunction<Function, DataType>& square)
00807 ;
00808
00810
00813
00816 bool operator == (const SquareFunction<Function, DataType>& square) const
00817 ;
00818
00820
00823
00828 BALL_INLINE
00829 DataType operator () (const DataType& x) const
00830
00831 {
00832 DataType val = function_(x);
00833 return val * val;
00834 }
00835
00837
00840
00843 void setFunction(const Function& function)
00844
00845 {
00846 function_ = function;
00847 }
00848
00852 const Function& getFunction() const
00853
00854 {
00855 return function_;
00856 }
00857
00859
00860
00861 protected:
00862
00863
00864
00865 Function function_;
00866
00867 };
00868
00869
00873 template <typename Function, typename DataType = float>
00874 class CubicFunction
00875 {
00876 public:
00877
00878 BALL_CREATE(CubicFunction)
00879
00880
00883
00886 CubicFunction()
00887 ;
00888
00891 CubicFunction(const CubicFunction& cubic)
00892 ;
00893
00896 virtual ~CubicFunction()
00897 ;
00898
00900
00903
00906 CubicFunction<Function, DataType>& operator = (const CubicFunction<Function, DataType>& cubic)
00907 ;
00908
00910
00913
00916 bool operator == (const CubicFunction<Function, DataType>& cubic) const
00917 ;
00918
00920
00923
00928 BALL_INLINE
00929 DataType operator () (const DataType& x) const
00930
00931 {
00932 DataType val = function_(x);
00933 return val * val * val;
00934 }
00935
00937
00940
00943 void setFunction(const Function& function)
00944
00945 {
00946 function_ = function;
00947 }
00948
00952 const Function& getFunction() const
00953
00954 {
00955 return function_;
00956 }
00957
00959
00960 protected:
00961
00962
00963
00964 Function function_;
00965
00966 };
00967
00968
00972 template <typename Function, typename DataType = float>
00973 class MutablePower
00974 {
00975 public:
00976
00977 BALL_CREATE(MutablePower)
00978
00979
00982
00985 MutablePower()
00986 ;
00987
00990 MutablePower(const MutablePower& power)
00991 ;
00992
00995 virtual ~MutablePower()
00996 ;
00997
00999
01002
01005 MutablePower<Function, DataType>& operator = (const MutablePower<Function, DataType>& power)
01006 ;
01007
01009
01012
01015 bool operator == (const MutablePower<Function, DataType>& power) const
01016 ;
01017
01019
01022
01027 BALL_INLINE
01028 DataType operator () (const DataType& x) const
01029
01030 {
01031 return pow(function_(x), exponent_);
01032 }
01033
01035
01038
01041 void setFunction(const Function& function)
01042
01043 {
01044 function_ = function;
01045 }
01046
01050 const Function& getFunction() const
01051
01052 {
01053 return function_;
01054 }
01055
01059 void setExponent(DataType exp)
01060 ;
01061
01065 DataType getExponent() const
01066 ;
01067
01069
01070 protected:
01071
01072
01073
01074 Function function_;
01075
01076
01077
01078 DataType exponent_;
01079
01080 };
01081
01082
01083 template <typename DataType>
01084 BALL_INLINE
01085 MutableConstant<DataType>::MutableConstant()
01086
01087 : constant_(0)
01088 {
01089 }
01090
01091 template <typename DataType>
01092 BALL_INLINE
01093 MutableConstant<DataType>::MutableConstant
01094 (const MutableConstant<DataType>& constant)
01095
01096 : constant_(constant.constant_)
01097 {
01098 }
01099
01100 template <typename DataType>
01101 BALL_INLINE
01102 MutableConstant<DataType>::MutableConstant(DataType constant)
01103
01104 : constant_(constant)
01105 {
01106 }
01107
01108 template <typename DataType>
01109 BALL_INLINE
01110 MutableConstant<DataType>::~MutableConstant()
01111
01112 {
01113 }
01114
01115 template <typename DataType>
01116 BALL_INLINE
01117 MutableConstant<DataType>& MutableConstant<DataType>::operator =
01118 (const MutableConstant<DataType>& constant)
01119
01120 {
01121 constant_ = constant.constant_;
01122 return *this;
01123 }
01124
01125 template <typename DataType>
01126 BALL_INLINE
01127 bool MutableConstant<DataType>::operator ==
01128 (const MutableConstant<DataType>& constant) const
01129
01130 {
01131 return (constant_ == constant.constant_);
01132 }
01133
01134
01135 template <typename First, typename Second, typename DataType>
01136 BALL_INLINE
01137 Addition<First, Second, DataType>::Addition()
01138
01139 : first_(),
01140 second_()
01141 {
01142 }
01143
01144 template <typename First, typename Second, typename DataType>
01145 BALL_INLINE
01146 Addition<First, Second, DataType>::Addition(const Addition& addition)
01147
01148 : first_(addition.first_),
01149 second_(addition.second_)
01150 {
01151 }
01152
01153 template <typename First, typename Second, typename DataType>
01154 BALL_INLINE
01155 Addition<First, Second, DataType>::~Addition()
01156
01157 {
01158 }
01159
01160 template <typename First, typename Second, typename DataType>
01161 BALL_INLINE
01162 Addition<First, Second, DataType>& Addition<First, Second, DataType>::operator = (const Addition<First, Second, DataType>& addition)
01163
01164 {
01165 first_ = addition.first_;
01166 second_ = addition.second_;
01167 return *this;
01168 }
01169
01170 template <typename First, typename Second, typename DataType>
01171 BALL_INLINE
01172 bool Addition<First, Second, DataType>::operator == (const Addition<First, Second, DataType>& addition) const
01173
01174 {
01175 return ((first_ == addition.first_) && (second_ == addition.second_));
01176 }
01177
01178
01179 template <typename First, typename Second, typename DataType>
01180 BALL_INLINE
01181 Subtraction<First, Second, DataType>::Subtraction()
01182
01183 : first_(),
01184 second_()
01185 {
01186 }
01187
01188 template <typename First, typename Second, typename DataType>
01189 BALL_INLINE
01190 Subtraction<First, Second, DataType>::Subtraction(const Subtraction& subtraction)
01191
01192 : first_(subtraction.first_),
01193 second_(subtraction.second_)
01194 {
01195 }
01196
01197 template <typename First, typename Second, typename DataType>
01198 BALL_INLINE
01199 Subtraction<First, Second, DataType>::~Subtraction()
01200
01201 {
01202 }
01203
01204 template <typename First, typename Second, typename DataType>
01205 BALL_INLINE
01206 Subtraction<First, Second, DataType>& Subtraction<First, Second, DataType>::operator = (const Subtraction<First, Second, DataType>& subtraction)
01207
01208 {
01209 first_ = subtraction.first_;
01210 second_ = subtraction.second_;
01211 return *this;
01212 }
01213
01214 template <typename First, typename Second, typename DataType>
01215 BALL_INLINE
01216 bool Subtraction<First, Second, DataType>::operator == (const Subtraction<First, Second, DataType>& subtraction) const
01217
01218 {
01219 return ((first_ == subtraction.first_) && (second_ == subtraction.second_));
01220 }
01221
01222
01223 template <typename First, typename Second, typename DataType>
01224 BALL_INLINE
01225 Product<First, Second, DataType>::Product()
01226
01227 : first_(),
01228 second_()
01229 {
01230 }
01231
01232 template <typename First, typename Second, typename DataType>
01233 BALL_INLINE
01234 Product<First, Second, DataType>::Product(const Product& product)
01235
01236 : first_(product.first_),
01237 second_(product.second_)
01238 {
01239 }
01240
01241 template <typename First, typename Second, typename DataType>
01242 BALL_INLINE
01243 Product<First, Second, DataType>::~Product()
01244
01245 {
01246 }
01247
01248 template <typename First, typename Second, typename DataType>
01249 BALL_INLINE
01250 Product<First, Second, DataType>& Product<First, Second, DataType>::operator = (const Product<First, Second, DataType>& product)
01251
01252 {
01253 first_ = product.first_;
01254 second_ = product.second_;
01255 return *this;
01256 }
01257
01258 template <typename First, typename Second, typename DataType>
01259 BALL_INLINE
01260 bool Product<First, Second, DataType>::operator == (const Product<First, Second, DataType>& product) const
01261
01262 {
01263 return ((first_ == product.first_) && (second_ == product.second_));
01264 }
01265
01266
01267 template <typename First, typename Second, typename DataType>
01268 BALL_INLINE
01269 Division<First, Second, DataType>::Division()
01270
01271 : first_(),
01272 second_()
01273 {
01274 }
01275
01276 template <typename First, typename Second, typename DataType>
01277 BALL_INLINE
01278 Division<First, Second, DataType>::Division(const Division& division)
01279
01280 : first_(division.first_),
01281 second_(division.second_)
01282 {
01283 }
01284
01285 template <typename First, typename Second, typename DataType>
01286 BALL_INLINE
01287 Division<First, Second, DataType>::~Division()
01288
01289 {
01290 }
01291
01292 template <typename First, typename Second, typename DataType>
01293 BALL_INLINE
01294 Division<First, Second, DataType>& Division<First, Second, DataType>::operator = (const Division<First, Second, DataType>& division)
01295
01296 {
01297 first_ = division.first_;
01298 second_ = division.second_;
01299 return *this;
01300 }
01301
01302 template <typename First, typename Second, typename DataType>
01303 BALL_INLINE
01304 bool Division<First, Second, DataType>::operator == (const Division<First, Second, DataType>& division) const
01305
01306 {
01307 return ((first_ == division.first_) && (second_ == division.second_));
01308 }
01309
01310
01311 template <typename Function, typename DataType>
01312 BALL_INLINE
01313 SquareFunction<Function, DataType>::SquareFunction()
01314
01315 : function_()
01316 {
01317 }
01318
01319 template <typename Function, typename DataType>
01320 BALL_INLINE
01321 SquareFunction<Function, DataType>::SquareFunction(const SquareFunction& square)
01322
01323 : function_(square.function_)
01324 {
01325 }
01326
01327 template <typename Function, typename DataType>
01328 BALL_INLINE
01329 SquareFunction<Function, DataType>::~SquareFunction()
01330
01331 {
01332 }
01333
01334 template <typename Function, typename DataType>
01335 BALL_INLINE
01336 SquareFunction<Function, DataType>& SquareFunction<Function, DataType>::operator = (const SquareFunction<Function, DataType>& square)
01337
01338 {
01339 function_ = square.function_;
01340 return *this;
01341 }
01342
01343 template <typename Function, typename DataType>
01344 BALL_INLINE
01345 bool SquareFunction<Function, DataType>::operator == (const SquareFunction& square) const
01346
01347 {
01348 return (function_ == square.function_);
01349 }
01350
01351
01352 template <typename Function, typename DataType>
01353 BALL_INLINE
01354 CubicFunction<Function, DataType>::CubicFunction()
01355
01356 : function_(0)
01357 {
01358 }
01359
01360 template <typename Function, typename DataType>
01361 BALL_INLINE
01362 CubicFunction<Function, DataType>::CubicFunction(const CubicFunction& cubic)
01363
01364 : function_(cubic.function_)
01365 {
01366 }
01367
01368 template <typename Function, typename DataType>
01369 BALL_INLINE
01370 CubicFunction<Function, DataType>::~CubicFunction()
01371
01372 {
01373 }
01374
01375 template <typename Function, typename DataType>
01376 BALL_INLINE
01377 CubicFunction<Function, DataType>& CubicFunction<Function, DataType>::operator = (const CubicFunction<Function, DataType>& cubic)
01378
01379 {
01380 function_ = cubic.function_;
01381 return *this;
01382 }
01383
01384 template <typename Function, typename DataType>
01385 BALL_INLINE
01386 bool CubicFunction<Function, DataType>::operator == (const CubicFunction& cubic) const
01387
01388 {
01389 return (function_ == cubic.function_);
01390 }
01391
01392
01393 template <typename Function, typename DataType>
01394 BALL_INLINE
01395 Reciprocal<Function, DataType>::Reciprocal()
01396
01397 : function_()
01398 {
01399 }
01400
01401 template <typename Function, typename DataType>
01402 BALL_INLINE
01403 Reciprocal<Function, DataType>::Reciprocal(const Reciprocal& reciprocal)
01404
01405 : function_(reciprocal.function_)
01406 {
01407 }
01408
01409 template <typename Function, typename DataType>
01410 BALL_INLINE
01411 Reciprocal<Function, DataType>::~Reciprocal()
01412
01413 {
01414 }
01415
01416 template <typename Function, typename DataType>
01417 BALL_INLINE
01418 Reciprocal<Function, DataType>& Reciprocal<Function, DataType>::operator = (const Reciprocal<Function, DataType>& reciprocal)
01419
01420 {
01421 function_ = reciprocal.function_;
01422 return *this;
01423 }
01424
01425 template <typename Function, typename DataType>
01426 BALL_INLINE
01427 bool Reciprocal<Function, DataType>::operator == (const Reciprocal& reciprocal) const
01428
01429 {
01430 return (function_ == reciprocal.function_);
01431 }
01432
01433
01434 template <typename Function, typename DataType>
01435 BALL_INLINE
01436 MutablePower<Function, DataType>::MutablePower()
01437
01438 : function_(0),
01439 exponent_(0)
01440 {
01441 }
01442
01443 template <typename Function, typename DataType>
01444 BALL_INLINE
01445 MutablePower<Function, DataType>::MutablePower(const MutablePower& power)
01446
01447 : function_(power.function_),
01448 exponent_(power.exponent_)
01449 {
01450 }
01451
01452 template <typename Function, typename DataType>
01453 BALL_INLINE
01454 MutablePower<Function, DataType>::~MutablePower()
01455
01456 {
01457 }
01458
01459 template <typename Function, typename DataType>
01460 BALL_INLINE
01461 MutablePower<Function, DataType>& MutablePower<Function, DataType>::operator = (const MutablePower& power)
01462
01463 {
01464 function_ = power.function_;
01465 exponent_ = power.exponent_;
01466 return *this;
01467 }
01468
01469 template <typename Function, typename DataType>
01470 BALL_INLINE
01471 bool MutablePower<Function, DataType>::operator == (const MutablePower& power) const
01472
01473 {
01474 return ((exponent_ == power.exponent_)
01475 && (function_ == power.function_));
01476 }
01477
01478 template <typename Function, typename DataType>
01479 BALL_INLINE
01480 DataType MutablePower<Function, DataType>::getExponent() const
01481
01482 {
01483 return exponent_;
01484 }
01485
01486 template <typename Function, typename DataType>
01487 BALL_INLINE
01488 void MutablePower<Function, DataType>::setExponent(DataType exp)
01489
01490 {
01491 exponent_ = exp;
01492 }
01493 }
01494
01495 #endif // BALL_MATHS_FUNCTION_H