Advertisement
AI_UBI

Part of body

Dec 28th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 KB | None | 0 0
  1. #ifndef SHAPE_H
  2. #define SHAPE_H
  3. #define MAX_VERTICIES_PER_SHAPE 32 //TODO: Drag in a config file.
  4. #include <vector>
  5.  
  6. /*
  7. TODO: For standard primitives use the constructor once for each,
  8. in subsequent uses use copy constructor.
  9. (Quickly select and copy than to isolate and create)
  10. */
  11.  
  12. template<template<typename> class Vector, typename Type>
  13. class Shape
  14. {
  15.  
  16. protected:
  17.    
  18.     std::vector<Vector<Type>> verticies = {};
  19.     Vector<Type> axis = Vector<Type>(1,1);
  20.  
  21.     Shape(const std::vector<Vector<Type>> &);
  22.     Shape(const std::vector<Vector<Type>> &, const Vector<Type> &);
  23.  
  24.     void check_size(const std::vector<Vector<Type>> &) const;
  25.  
  26. public:
  27.    
  28.     Shape() {}
  29.     ~Shape() {}
  30.  
  31.     void setVertex(const size_t &, const Vector<Type> &);
  32.     Vector<Type> & getVertex(const size_t &) const;
  33.  
  34.     void addVertex(const size_t &, const Vector<Type> &);
  35.     void delVertex(const size_t &);
  36.  
  37.     void setAxis(const Vector<Type> &);
  38.     Vector<Type> & getAxis() const;
  39.  
  40.     size_t & getVertexCount() const;
  41. };
  42.  
  43. template<template<typename> class Vector, typename Type>
  44. inline Shape<Vector, Type>::Shape(const std::vector<Vector<Type>> &v)
  45. {
  46.     check_size(v);
  47.     this->verticies = v;
  48. }
  49.  
  50. template<template<typename> class Vector, typename Type>
  51. Shape<Vector, Type>::Shape(const std::vector<Vector<Type>> &v, const Vector<Type> &a)
  52. {
  53.     check_size(v);
  54.     this->verticies = v;
  55.     this->axis = a;
  56. }
  57.  
  58. template<template<typename> class Vector, typename Type>
  59. void Shape<Vector, Type>::check_size(const std::vector<Vector<Type>>& v) const
  60. {
  61.     if(this->verticies.size() < v.size()) this->verticies.resize(v.size());
  62. }
  63.  
  64. template<template<typename> class Vector, typename Type>
  65. void Shape<Vector, Type>::setVertex(const size_t &id, const Vector<Type> &v)
  66. {
  67.     if (id < this->verticies.size()) this->verticies[id] = v;
  68. }
  69.  
  70. template<template<typename> class Vector, typename Type>
  71. Vector<Type> & Shape<Vector, Type>::getVertex(const size_t &id) const
  72. {
  73.     if (id < this->verticies.size()) return const_cast<Vector<Type> &>(this->verticies[id]);
  74.     return Vector<Type>();
  75. }
  76.  
  77. template<template<typename> class Vector, typename Type>
  78. void Shape<Vector, Type>::addVertex(const size_t &id, const Vector<Type> &v)
  79. {
  80.     if (id < this->verticies.size() && this->verticies.size() < MAX_VERTICIES_PER_SHAPE) this->verticies.insert(id, v);
  81.     else if (id && this->verticies.size() < MAX_VERTICIES_PER_SHAPE) this->verticies.push_back(v);
  82. }
  83.  
  84. template<template<typename> class Vector, typename Type>
  85. void Shape<Vector, Type>::delVertex(const size_t &id)
  86. {
  87.     if (id < this->verticies.size()) this->verticies.erase(verticies.begin() + id);
  88.     else if (id && this->verticies.size()) this->verticies.pop_back();
  89. }
  90.  
  91. template<template<typename> class Vector, typename Type>
  92. void Shape<Vector, Type>::setAxis(const Vector<Type> &v)
  93. {
  94.     this->axis = v;
  95. }
  96.  
  97. template<template<typename> class Vector, typename Type>
  98. Vector<Type> & Shape<Vector, Type>::getAxis() const
  99. {
  100.     return this->axis;
  101. }
  102.  
  103. template<template<typename> class Vector, typename Type>
  104. size_t & Shape<Vector, Type>::getVertexCount() const
  105. {
  106.     return const_cast<size_t &>(this->verticies.size());
  107. }
  108.  
  109. #endif //SHAPE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement