CluE  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
discreteboundedrealspaceprovider.cpp
Go to the documentation of this file.
1 #include <cmath>
2 
4 #include "../exception/invalidargumentexception.h"
5 
6 namespace CluE
7 {
8 
9 
10 DiscreteBoundedRealSpaceProvider::DiscreteBoundedRealSpaceProvider(size_t dimension, unsigned long long n, Point minimum, double length) :
11  _dimension(dimension),
12  _n(n),
13  minimum(minimum),
14  stepSize()
15 {
16  for(size_t i = 0; i < dimension; i++)
17  stepSize.push_back(length / (n-1));
18 }
19 
21 {
22  return new DiscreteBoundedRealSpaceProvider(*this);
23 }
24 
25 Point DiscreteBoundedRealSpaceProvider::getVector(std::vector<unsigned long long> coordinates) const
26 {
27  std::vector<double> coords;
28  for(size_t i = 0; i < dimension(); i++)
29  {
30  unsigned long long c = coordinates[i];
31  if(c < 0 || c >= n())
32  throw InvalidArgumentException(0, "Invalid coordinate: exceeds bounds", "coordinates");
33  coords.push_back(minimum[i] + stepSize[i] * c);
34  }
35  return Point(coords, 1.0);
36 }
37 
38 std::vector<unsigned long long> DiscreteBoundedRealSpaceProvider::getCoordinates(Point const & vector) const
39 {
40  std::vector<unsigned long long> coordinates;
41  for(size_t i = 0; i < dimension(); i++)
42  {
43  double delta = vector[i] - minimum[i];
44  unsigned long long steps = std::floor(delta / stepSize[i] + 0.5);
45  if(steps < 0 || steps >= n())
46  throw InvalidArgumentException(0, "Invalid point: exceeds bounds", "vector");
47  coordinates.push_back(steps);
48  }
49  return coordinates;
50 }
51 
52 }
53 
virtual size_t dimension() const
Space dimension.
DiscreteBoundedRealSpaceProvider(size_t dimension, unsigned long long n, Point minimum, double length)
virtual unsigned long long n() const
Number of discrete coordinates per dimension.
virtual DiscreteBoundedRealSpaceProvider * clone() const
Provides discrete bounded space features for Point.
virtual Point getVector(std::vector< unsigned long long > coordinates) const
Returns the vector represented by the given coordinates.
Weighted point of arbitrary dimension.
Definition: point.h:17
Indicates invalid values of arguments.
virtual std::vector< unsigned long long > getCoordinates(Point const &vector) const
Returns the coordinates of the given vector.