1

Disclaimer: this is for hobby development - I wouldn't over-engineer this much in a professional endeavor unless asked to do so.

Imagine an N-dimensional surface, such as a line (1D), grid/circle (2D), cube/sphere (3D), etc., where each axis of this surface is finite in that it has a start and end, or wraps around. A good example is the Earth, where there is longitude (wraps around), latitude (starts and ends), and if necessary, height and time (assume a specific start/end for these).

The generalized structure to handle this scenario could be something like this:

typedef NoAxis End;
typedef Axis<End>::NoWrap<0, 365> Time; // one year, if units are in days
typedef Axis<Time>::NoWrap<0, 35000> Height; // sea level to 35k meters
typedef Axis<Height>::NoWrap<-90, 90> Latitude;
typedef Axis<Latitude>::Wrap<-180, 180> Longitude;

The "Axis" class takes a template parameter that is the next axis; this forms a chain of axes, where a special type "NoAxis" begins the chain. Geometric operations, e.g. finding the distance between two points, are performed by accumulating the calculations for each axis.

My question: is there a way, preferably via template metaprogramming, to programatically find the largest order of magnitude that could be multiplied to the extrema of each axis - the idea being to maximize the surface resolution - but not overflow the storage for the type used to contain the values (e.g. don't overflow 32 bits on a 32-bit system, etc.). This order of magnitude must take into account calculating the distance between points on the surface, which involves finding the squared distance.

Once again, the reason to find this order of magnitude is to get the highest resolution possible for a given storage type.

TemplateRex
  • 69,038
  • 19
  • 164
  • 304
jorgander
  • 540
  • 1
  • 4
  • 12
  • I might have misunderstood the question (it is a bit complex), but templates might be a wrong way to implement what you are trying to achieve. – BЈовић Aug 07 '12 at 19:57
  • To explain a bit more: The code example I gave will not provide much resolution, assuming an integral data type. E.g. the degrees of latitude/longitude will only allow whole values. The resolution could be increased by multiplying them all by a positive number, and I am wondering if there is a way to maximize this number without overflowing the storage type. If not templates, do you know of a better way to generalize it? I'd rather not use virtual functions. – jorgander Aug 07 '12 at 20:15

0 Answers0