Goose Management Model ODdox  1.02
ALMaSS_MathFuncs Class Reference

ALMaSS_MathFuncs constructor. More...

#include <Misc.h>

Public Member Functions

 ALMaSS_MathFuncs ()
 ALMaSS_MathFuncs constructor. More...
 
int CalcDistPythagoras (int a_x, int a_y, int a_x1, int a_y1)
 Calculate distance using Pythagoras. More...
 
int CalcDistPythagorasApprox (int a_x, int a_y, int a_x1, int a_y1)
 Calculate distance using the Pythagoras approximation. More...
 
virtual ~ALMaSS_MathFuncs ()
 ALMaSS_MathFuncs deconstructor. More...
 

Detailed Description

ALMaSS_MathFuncs constructor.

Definition at line 28 of file Misc.h.

Constructor & Destructor Documentation

◆ ALMaSS_MathFuncs()

ALMaSS_MathFuncs::ALMaSS_MathFuncs ( )
inline

ALMaSS_MathFuncs constructor.

This class is designed to hold general math functions frequently used in the ALMaSS code. For example distance calculations using either Pythagoras or the approximation of Pythagoras

Definition at line 35 of file Misc.h.

35  {
36  ;
37  }

◆ ~ALMaSS_MathFuncs()

virtual ALMaSS_MathFuncs::~ALMaSS_MathFuncs ( )
inlinevirtual

ALMaSS_MathFuncs deconstructor.

Todo:
Lars: not sure this is needed here

Definition at line 39 of file Misc.h.

39  {
40  ;
41  };

Member Function Documentation

◆ CalcDistPythagoras()

int ALMaSS_MathFuncs::CalcDistPythagoras ( int  a_x,
int  a_y,
int  a_x1,
int  a_y1 
)

Calculate distance using Pythagoras.

Definition at line 42 of file misc.cpp.

42  {
43  int dx = a_x - a_x1;
44  int dy = a_y - a_y1;
45  int dist = (int)sqrt( (double)(dx*dx + dy*dy) );
46  return dist;
47 }

Referenced by Goose_Base::EvaluateForageToHopLoc(), Goose_Population_Manager::FindClosestRoost(), Goose_Population_Manager::GetDistToClosestRoost(), and Goose_Population_Manager::GetForageLocIndex().

◆ CalcDistPythagorasApprox()

int ALMaSS_MathFuncs::CalcDistPythagorasApprox ( int  a_x,
int  a_y,
int  a_x1,
int  a_y1 
)

Calculate distance using the Pythagoras approximation.

The approximation to Pythagorus is accurate to around 6%

Definition at line 49 of file misc.cpp.

49  {
53  int dx = abs( a_x - a_x1 );
54  int dy = abs( a_y - a_y1 );
55  dx++; //To avoid division by zero
56  dy++;
57  int dist;
58  if (dx>dy) {
59  dist = dx + (dy * dy) / (2 * dx);
60  }
61  else dist = dy + (dx * dx) / (2 * dy);
62  return dist;
63 }

Referenced by Goose_Population_Manager::BangAtPoly(), GooseMemoryMap::ChangeSetFoodRes(), GooseMemoryMap::DecayAllMemory(), Goose_Base::EvaluateForageToHopLoc(), Goose_Base::FlyTo(), Goose_Base::On_Bang(), and Goose_Base::st_ChooseForageLocation().


The documentation for this class was generated from the following files: