Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SHAPE_H
- #define SHAPE_H
- #define MAX_VERTICIES_PER_SHAPE 32 //TODO: Drag in a config file.
- #include <vector>
- /*
- TODO: For standard primitives use the constructor once for each,
- in subsequent uses use copy constructor.
- (Quickly select and copy than to isolate and create)
- */
- template<template<typename> class Vector, typename Type>
- class Shape
- {
- protected:
- std::vector<Vector<Type>> verticies = {};
- Vector<Type> axis = Vector<Type>(1,1);
- Shape(const std::vector<Vector<Type>> &);
- Shape(const std::vector<Vector<Type>> &, const Vector<Type> &);
- void check_size(const std::vector<Vector<Type>> &) const;
- public:
- Shape() {}
- ~Shape() {}
- void setVertex(const size_t &, const Vector<Type> &);
- Vector<Type> & getVertex(const size_t &) const;
- void addVertex(const size_t &, const Vector<Type> &);
- void delVertex(const size_t &);
- void setAxis(const Vector<Type> &);
- Vector<Type> & getAxis() const;
- size_t & getVertexCount() const;
- };
- template<template<typename> class Vector, typename Type>
- inline Shape<Vector, Type>::Shape(const std::vector<Vector<Type>> &v)
- {
- check_size(v);
- this->verticies = v;
- }
- template<template<typename> class Vector, typename Type>
- Shape<Vector, Type>::Shape(const std::vector<Vector<Type>> &v, const Vector<Type> &a)
- {
- check_size(v);
- this->verticies = v;
- this->axis = a;
- }
- template<template<typename> class Vector, typename Type>
- void Shape<Vector, Type>::check_size(const std::vector<Vector<Type>>& v) const
- {
- if(this->verticies.size() < v.size()) this->verticies.resize(v.size());
- }
- template<template<typename> class Vector, typename Type>
- void Shape<Vector, Type>::setVertex(const size_t &id, const Vector<Type> &v)
- {
- if (id < this->verticies.size()) this->verticies[id] = v;
- }
- template<template<typename> class Vector, typename Type>
- Vector<Type> & Shape<Vector, Type>::getVertex(const size_t &id) const
- {
- if (id < this->verticies.size()) return const_cast<Vector<Type> &>(this->verticies[id]);
- return Vector<Type>();
- }
- template<template<typename> class Vector, typename Type>
- void Shape<Vector, Type>::addVertex(const size_t &id, const Vector<Type> &v)
- {
- if (id < this->verticies.size() && this->verticies.size() < MAX_VERTICIES_PER_SHAPE) this->verticies.insert(id, v);
- else if (id && this->verticies.size() < MAX_VERTICIES_PER_SHAPE) this->verticies.push_back(v);
- }
- template<template<typename> class Vector, typename Type>
- void Shape<Vector, Type>::delVertex(const size_t &id)
- {
- if (id < this->verticies.size()) this->verticies.erase(verticies.begin() + id);
- else if (id && this->verticies.size()) this->verticies.pop_back();
- }
- template<template<typename> class Vector, typename Type>
- void Shape<Vector, Type>::setAxis(const Vector<Type> &v)
- {
- this->axis = v;
- }
- template<template<typename> class Vector, typename Type>
- Vector<Type> & Shape<Vector, Type>::getAxis() const
- {
- return this->axis;
- }
- template<template<typename> class Vector, typename Type>
- size_t & Shape<Vector, Type>::getVertexCount() const
- {
- return const_cast<size_t &>(this->verticies.size());
- }
- #endif //SHAPE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement