#ifndef __IDRAWABLE_H__
#define __IDRAWABLE_H__
#include "../Classes/BaseGUISegmentClass.hpp"
#include <ctime>
/**
* @brief Интерфейс к объекту отображения.
*
*/
class IDrawable
{
ParameterGetSetTyped(float, rendertime, .0);
ParameterGetSetTyped(bool, visible, true);
public:
/**
* @brief Функция тображает объект.
*
*/
virtual void draw() const = 0;
/**
* @brief Функция обёртка для отображения объекта, рассчитыват времы отображения.
*
*/
inline bool make_draw() {
if (!can_draw()) return false;
auto start = std::time(0); this->draw();
set_rendertime(std::time(0) - start);
return true;
}
virtual inline bool can_draw() const
{
if (get_visible() == true) return true;
return false;
}
};
#endif // __IDRAWABLE_H__
#pragma once
#ifndef __ISTRINGABLE_H__
#define __ISTRINGABLE_H__
#include <string>
#include <sstream>
/**
* @brief Интерфейс объекта который можно преобразовать в строку.
*
*/
class IStringable {
public:
/**
* @brief Получить строкое представление объекта.
*
* @return std::string
*/
virtual std::string toString() const = 0;
/**
* @brief Перегрузка оператора << для вывода в std::cout <<.
*
* @param os
* @param dt
* @return std::ostream&
*/
friend std::ostream& operator<<(std::ostream& os, const IStringable& obj)
{
os << obj.toString();
return os;
}
};
#endif // __ISTRINGABLE_H__
#pragma once
#ifndef _ISHAPE_H_
#define _ISHAPE_H_
#include "IDrawable.h"
#include "IStringable.h"
/**
* @brief Класс прототип фигуры.
*
*/
template<typename T> class IShape : public IDrawable, public IStringable
{
public:
/**
* @brief Возвращает площадь фигуры.
*
* @return T
*/
virtual T area() = 0;
/**
* @brief Возвращает периметр фигуры.
*
* @return T
*/
virtual T perimeter() = 0;
/**
* @brief Возвращает тоже что и perimeter.
*
* @return T
*/
virtual inline T circumfence() { return perimeter(); }
/**
* @brief Get the Shape Name object
* Получить название формы.
*
* @return std::string
*/
virtual inline std::string getShapeName() = 0;
};
#endif //_ISHAPE_H_
#pragma once
#ifndef __AXIS__HPP_
#define __AXIS__HPP_
#include "../../../Interfaces/IShape.h"
#include "Point.hpp"
/**
* @brief Класс описывающий точку вращения объекта.
*
* @tparam T
*/
template<typename T> class Axis : public IShape<T>
{
ParameterGetSetTypedClassVariable(Point2D<T>, position);
ParameterGetSetTyped(T, rotation, 0);
public:
Axis(T rotation, Point2D<T> position);
inline virtual std::string getShapeName();
virtual void draw() const;
virtual inline T perimeter();
virtual inline T area();
};
#endif // __AXIS__HPP_
#include "Axis.hpp"
template<typename T> Axis<T>::Axis(T rotation, Point2D<T> position)
: __rotation(rotation)
{
__position.set_x(position.get_x());
__position.set_y(position.get_y());
}
template<typename T> std::string Axis<T>::getShapeName()
{
return "axis";
}
template<typename T> void Axis<T>::draw() const
{
get_position().draw();
}
template<typename T> T Axis<T>::perimeter() {return 0;}
template<typename T> T Axis<T>::area() {return 0;}
TemplateClassNumericTypes(Axis);
/**
* @brief Класс точки различного числового типа.
*
* @tparam T Числовой тип.
*/
template<typename T> class Point2D : public BaseGUISegmentClass, public IShape<T>
{
ParameterGetSetTyped(T, x, 0);
ParameterGetSetTyped(T, y, 0);
public:
Point2D();
Point2D(T x = 0, T y = 0);
Point2D(T x = 0);
~Point2D();
DefineTypeOperators(Point2D<T>);
DefineTypeOperatorsMainMethods(Point2D<T>);
virtual std::string toString() const override;
virtual void fromString(const std::string &input);
virtual void draw() const;
virtual T area() {return 0 ;}
virtual T perimeter() {return 0;}
virtual std::string getShapeName() {return "point";}
};
In file included from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
./Machinarium/Classes/Geometry/Vector2.h: In instantiation of ‘class Vector2D<int>’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘Vector2D<T> Vector2D<T>::add_by_vector(const Vector2D<T>&) const [with T = int]’ marked ‘override’, but does not override
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:22:15: note: in expansion of macro ‘DVector’
22 | DVector(2)<T> DVector(2)<T>::add_by_vector(const DVector(2)<T>& vector2d) const
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘Vector2D<T> Vector2D<T>::sub_by_vector(const Vector2D<T>&) [with T = int]’ marked ‘override’, but does not override
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:28:15: note: in expansion of macro ‘DVector’
28 | DVector(2)<T> DVector(2)<T>::sub_by_vector(const DVector(2)<T>& vector2d)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘bool Vector2D<T>::equals_to(const Vector2D<T>&) [with T = int]’ marked ‘override’, but does not override
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:81:6: note: in expansion of macro ‘DVector’
81 | bool DVector(2)<T>::equals_to(const DVector(2)<T>& vector2d)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: ‘float Vector2D<T>::distance_to(const Vector2D<T>&) [with T = int]’ marked ‘override’, but does not override
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:87:7: note: in expansion of macro ‘DVector’
87 | float DVector(2)<T>::distance_to(const DVector(2)<T>& vector2d)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type ‘Vector2D<int>’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:51:15: note: in expansion of macro ‘DVector’
51 | DVector(2)<T> DVector(2)<T>::divide_by_number(T value)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type ‘Vector2D<int>’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:57:15: note: in expansion of macro ‘DVector’
57 | DVector(2)<T> DVector(2)<T>::multiple_by_vector(const DVector(2)<T>& vector2d)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type ‘Vector2D<int>’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:63:15: note: in expansion of macro ‘DVector’
63 | DVector(2)<T> DVector(2)<T>::divide_by_vector(const DVector(2)<T>& vector2d)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::add_by_vector(const Vector2D<T>&) const [with T = int]’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::add_by_vector(const Vector2D<T>&) const [with T = int]’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:22:15: note: in expansion of macro ‘DVector’
22 | DVector(2)<T> DVector(2)<T>::add_by_vector(const DVector(2)<T>& vector2d) const
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:24:12: note: in expansion of macro ‘DVector’
24 | return DVector(2)<T>(this->get_x() + vector2d.get_x(), this->get_y() + vector2d.get_y());
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::add_by_number(T) [with T = int]’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::add_by_number(T) [with T = int]’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:34:15: note: in expansion of macro ‘DVector’
34 | DVector(2)<T> DVector(2)<T>::add_by_number(T value)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:36:12: note: in expansion of macro ‘DVector’
36 | return DVector(2)<T>(this->x() + value, this->y() + value);
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::sub_by_number(T) [with T = int]’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::sub_by_number(T) [with T = int]’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:39:36: note: in expansion of macro ‘DVector’
39 | template<typename T> DVector(2)<T> DVector(2)<T>::sub_by_number(T value)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:41:12: note: in expansion of macro ‘DVector’
41 | return DVector(2)<T>(this->x() - value, this->y() - value);
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.cpp: In instantiation of ‘Vector2D<T> Vector2D<T>::sub_by_vector(const Vector2D<T>&) [with T = int]’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid abstract return type for member function ‘Vector2D<T> Vector2D<T>::sub_by_vector(const Vector2D<T>&) [with T = int]’
8 | #define DVector(name) Vector ## name ## D
./Machinarium/Classes/Geometry/Vector2.cpp:28:15: note: in expansion of macro ‘DVector’
28 | DVector(2)<T> DVector(2)<T>::sub_by_vector(const DVector(2)<T>& vector2d)
| ^~~~~~~
./Machinarium/Classes/Geometry/Vector2.cpp:30:36: error: passing ‘const Vector2D<int>’ as ‘this’ argument discards qualifiers [-fpermissive]
30 | return DVector(2)<T>(this->x() - vector2d.x(), this->y() - vector2d.y());
In file included from ./Machinarium/Classes/Geometry/Vector2.h:6,
from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
./Machinarium/Classes/Geometry/Vector2.h:23:29: note: in call to ‘T Vector2D<T>::x(T) [with T = int]’
23 | ParameterGetSetTyped(T, x);
| ^
./Machinarium/Classes/Geometry/../BaseGUISegmentClass.hpp:15:14: note: in definition of macro ‘ParameterGetSetTyped’
15 | var_type name (var_type value = 0) { \
| ^~~~
./Machinarium/Classes/Geometry/Vector2.cpp:30:62: error: passing ‘const Vector2D<int>’ as ‘this’ argument discards qualifiers [-fpermissive]
30 | return DVector(2)<T>(this->x() - vector2d.x(), this->y() - vector2d.y());
In file included from ./Machinarium/Classes/Geometry/Vector2.h:6,
from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
./Machinarium/Classes/Geometry/Vector2.h:24:29: note: in call to ‘T Vector2D<T>::y(T) [with T = int]’
24 | ParameterGetSetTyped(T, y);
| ^
./Machinarium/Classes/Geometry/../BaseGUISegmentClass.hpp:15:14: note: in definition of macro ‘ParameterGetSetTyped’
15 | var_type name (var_type value = 0) { \
| ^~~~
In file included from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
./Machinarium/Classes/Geometry/Vector2.h:8:23: error: invalid cast to abstract class type ‘Vector2D<int>’
./main.cpp: In function ‘int main()’:
./main.cpp:7:19: error: cannot declare variable ‘test’ to be of abstract type ‘Vector2D<int>’
7 | Vector2D<int> test(12);
| ^~~~
In file included from ./Machinarium/Classes/Geometry/Vector2.h:10,
from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp: In instantiation of ‘class Vector2D<int>’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp:27:15: error: invalid abstract return type ‘Vector2D<int>’
27 | virtual C add_by_vector(const C&) = 0;
| ^~~~~~~~~~~~~
template<typename T>
class DVector(2) : public IVector<DVector(2)<T>, T>, public BaseGUISegmentClass
{
/**
* @brief Класс вектора с двумя членами.
*
*/
ParameterGetSetTyped(T, x);
ParameterGetSetTyped(T, y);
public:
~DVector(2)();
/**
* @brief Construct a new Vector 2 object
*
* @param x Параметр Y дублируется из параметра Х.
*/
DVector(2)(T x);
/**
* @brief Construct a new Vector 2 object
*
* @param x Значение параметра Х
* @param y Значение параметра У
*/
DVector(2)(T x, T y);
public:
virtual float length();
virtual DVector(2) add_by_vector(const DVector(2)&) const;
virtual DVector(2) add_by_number(T);
virtual DVector(2) sub_by_number(T);
virtual DVector(2) sub_by_vector(const DVector(2)&);
virtual DVector(2) multiple_by_number(T);
virtual DVector(2) divide_by_number(T);
virtual DVector(2) multiple_by_vector(const DVector(2)&);
virtual DVector(2) divide_by_vector(const DVector(2)&);
virtual float calculate_angle(const DVector(2) &);
virtual float calculate_projection(const DVector(2)&);
virtual bool equals_to(const DVector(2)&);
virtual float distance_to(const DVector(2)&);
virtual T scalar_multiply(const DVector(2)&);
};
In file included from ./Machinarium/Classes/Geometry/Vector2.h:10,
from ./Machinarium/Classes/Geometry/Vector2.cpp:1:
./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp: In instantiation of ‘class Vector2D<int>’:
./Machinarium/Classes/Geometry/Vector2.cpp:99:16: required from here
./Machinarium/Classes/Geometry/../../Interfaces/IVector.hpp:25:15: error: invalid abstract return type ‘Vector2D<int>’
25 | virtual C add_by_vector(const C&) = 0;