From a2cf146565731e09f2e4d3159c19229abc33b143 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 6 Aug 2012 14:26:43 +0200 Subject: [PATCH] added basic vector class + a small set of operators --- Debug/sources.mk | 2 +- Debug/src/geometry/subdir.mk | 16 ------------- Release/sources.mk | 2 +- Release/src/geometry/subdir.mk | 16 ------------- src/geometry/Point.cpp | 12 ---------- src/geometry/Vector.h | 35 +++++++++++++++++++++++++++++ src/geometry/operators.h | 41 ++++++++++++++++++++++++++++++++++ 7 files changed, 78 insertions(+), 46 deletions(-) delete mode 100644 src/geometry/Point.cpp create mode 100644 src/geometry/Vector.h create mode 100644 src/geometry/operators.h diff --git a/Debug/sources.mk b/Debug/sources.mk index 41a8dd3..732350c 100644 --- a/Debug/sources.mk +++ b/Debug/sources.mk @@ -26,7 +26,7 @@ SUBDIRS := \ src/sdl \ src \ src/graphics \ -src/geometry \ src/battle \ src/app \ +src/geometry \ diff --git a/Debug/src/geometry/subdir.mk b/Debug/src/geometry/subdir.mk index 3173086..1957028 100644 --- a/Debug/src/geometry/subdir.mk +++ b/Debug/src/geometry/subdir.mk @@ -3,22 +3,6 @@ ################################################################################ # Add inputs and outputs from these tool invocations to the build variables -CPP_SRCS += \ -../src/geometry/Point.cpp - -OBJS += \ -./src/geometry/Point.o - -CPP_DEPS += \ -./src/geometry/Point.d - # Each subdirectory must supply rules for building sources it contributes -src/geometry/%.o: ../src/geometry/%.cpp - @echo 'Building file: $<' - @echo 'Invoking: GCC C++ Compiler' - g++ -I/usr/include/SDL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - diff --git a/Release/sources.mk b/Release/sources.mk index 41a8dd3..732350c 100644 --- a/Release/sources.mk +++ b/Release/sources.mk @@ -26,7 +26,7 @@ SUBDIRS := \ src/sdl \ src \ src/graphics \ -src/geometry \ src/battle \ src/app \ +src/geometry \ diff --git a/Release/src/geometry/subdir.mk b/Release/src/geometry/subdir.mk index 3ddc804..1957028 100644 --- a/Release/src/geometry/subdir.mk +++ b/Release/src/geometry/subdir.mk @@ -3,22 +3,6 @@ ################################################################################ # Add inputs and outputs from these tool invocations to the build variables -CPP_SRCS += \ -../src/geometry/Point.cpp - -OBJS += \ -./src/geometry/Point.o - -CPP_DEPS += \ -./src/geometry/Point.d - # Each subdirectory must supply rules for building sources it contributes -src/geometry/%.o: ../src/geometry/%.cpp - @echo 'Building file: $<' - @echo 'Invoking: GCC C++ Compiler' - g++ -I/usr/include/SDL -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' - @echo ' ' - diff --git a/src/geometry/Point.cpp b/src/geometry/Point.cpp deleted file mode 100644 index a3bb3a2..0000000 --- a/src/geometry/Point.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Point.cpp - * - * Created on: Aug 5, 2012 - * Author: holy - */ - -#include "Point.h" - -namespace geometry { - -} /* namespace geometry */ diff --git a/src/geometry/Vector.h b/src/geometry/Vector.h new file mode 100644 index 0000000..d7d0f3d --- /dev/null +++ b/src/geometry/Vector.h @@ -0,0 +1,35 @@ +/* + * Vector.h + * + * Created on: Aug 6, 2012 + * Author: holy + */ + +#ifndef GEOMETRY_VECTOR_H_ +#define GEOMETRY_VECTOR_H_ + +namespace geometry { + +template +class Vector { + +public: + Vector() : x(0), y(0) { } + Vector(Scalar x, Scalar y) : x(x), y(y) { } + template + Vector(const Vector &other) : x(other.X()), y(other.Y()) { }; + template + Vector(T x, T y) : x(x), y(y) { } + +public: + Scalar X() const { return x; } + Scalar Y() const { return y; } + +private: + Scalar x, y; + +}; + +} + +#endif /* GEOMETRY_VECTOR_H_ */ diff --git a/src/geometry/operators.h b/src/geometry/operators.h new file mode 100644 index 0000000..7a8e7ea --- /dev/null +++ b/src/geometry/operators.h @@ -0,0 +1,41 @@ +/* + * operators.h + * + * Created on: Aug 6, 2012 + * Author: holy + */ + +#ifndef GEOMETRY_OPERATORS_H_ +#define GEOMETRY_OPERATORS_H_ + +#include "Point.h" +#include "Vector.h" + +namespace geometry { + +template +inline Vector operator +(const Vector &lhs, const Vector &rhs) { + return Vector(lhs.X() + rhs.X(), lhs.Y() + rhs.Y()); +} +template +inline Point operator +(const Point &lhs, const Vector &rhs) { + return Point(lhs.X() + rhs.X(), lhs.Y() + rhs.Y()); +} + +template +inline Vector operator -(const Vector &lhs, const Vector &rhs) { + return Vector(lhs.X() - rhs.X(), lhs.Y() - rhs.Y()); +} +template +inline Point operator -(const Point &lhs, const Vector &rhs) { + return Point(lhs.X() - rhs.X(), lhs.Y() - rhs.Y()); +} + +template +inline Vector operator -(const Vector &v) { + return Vector(-v.X(), -v.Y()); +} + +} + +#endif /* GEOMETRY_OPERATORS_H_ */ -- 2.39.2