Browse Source

Start geometry tests

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
ea2f9fa567
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
4 changed files with 43 additions and 5 deletions
  1. +16
    -4
      dgl/Geometry.hpp
  2. +6
    -0
      dgl/src/Geometry.cpp
  3. +1
    -1
      tests/Makefile
  4. +20
    -0
      tests/Point.cpp

+ 16
- 4
dgl/Geometry.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -21,7 +21,7 @@

START_NAMESPACE_DGL

// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Forward class names

template<typename> class Line;
@@ -29,7 +29,7 @@ template<typename> class Circle;
template<typename> class Triangle;
template<typename> class Rectangle;

// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------

/**
DGL Point class.
@@ -121,7 +121,7 @@ private:
template<typename> friend class Rectangle;
};

// -----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------

/**
DGL Size class.
@@ -346,10 +346,12 @@ public:
*/
void moveBy(const Point<T>& pos) noexcept;

#ifndef DPF_TEST_POINT_CPP
/**
Draw this line using the current OpenGL state.
*/
void draw();
#endif

/**
Return true if line is null (start and end pos are equal).
@@ -460,6 +462,7 @@ public:
*/
void setNumSegments(const uint num);

#ifndef DPF_TEST_POINT_CPP
/**
Draw this circle using the current OpenGL state.
*/
@@ -469,6 +472,7 @@ public:
Draw lines (outline of this circle) using the current OpenGL state.
*/
void drawOutline();
#endif

Circle<T>& operator=(const Circle<T>& cir) noexcept;
bool operator==(const Circle<T>& cir) const noexcept;
@@ -540,6 +544,7 @@ public:
*/
bool isInvalid() const noexcept;

#ifndef DPF_TEST_POINT_CPP
/**
Draw this triangle using the current OpenGL state.
*/
@@ -549,6 +554,7 @@ public:
Draw lines (outline of this triangle) using the current OpenGL state.
*/
void drawOutline();
#endif

Triangle<T>& operator=(const Triangle<T>& tri) noexcept;
bool operator==(const Triangle<T>& tri) const noexcept;
@@ -557,8 +563,10 @@ public:
private:
Point<T> fPos1, fPos2, fPos3;

#ifndef DPF_TEST_POINT_CPP
/** @internal */
void _draw(const bool outline);
#endif
};

// -----------------------------------------------------------------------
@@ -722,6 +730,7 @@ public:
*/
bool containsY(const T& y) const noexcept;

#ifndef DPF_TEST_POINT_CPP
/**
Draw this rectangle using the current OpenGL state.
*/
@@ -731,6 +740,7 @@ public:
Draw lines (outline of this rectangle) using the current OpenGL state.
*/
void drawOutline();
#endif

Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
Rectangle<T>& operator*=(double m) noexcept;
@@ -742,8 +752,10 @@ private:
Point<T> fPos;
Size<T> fSize;

#ifndef DPF_TEST_POINT_CPP
/** @internal */
void _draw(const bool outline);
#endif
};

// -----------------------------------------------------------------------


+ 6
- 0
dgl/src/Geometry.cpp View File

@@ -599,6 +599,7 @@ void Circle<T>::setNumSegments(const uint num)
fSin = std::sin(fTheta);
}

#ifndef DPF_TEST_POINT_CPP
template<typename T>
void Circle<T>::draw()
{
@@ -610,6 +611,7 @@ void Circle<T>::drawOutline()
{
_draw(true);
}
#endif

template<typename T>
Circle<T>& Circle<T>::operator=(const Circle<T>& cir) noexcept
@@ -686,6 +688,7 @@ bool Triangle<T>::isInvalid() const noexcept
return fPos1 == fPos2 || fPos1 == fPos3;
}

#ifndef DPF_TEST_POINT_CPP
template<typename T>
void Triangle<T>::draw()
{
@@ -697,6 +700,7 @@ void Triangle<T>::drawOutline()
{
_draw(true);
}
#endif

template<typename T>
Triangle<T>& Triangle<T>::operator=(const Triangle<T>& tri) noexcept
@@ -900,6 +904,7 @@ bool Rectangle<T>::containsY(const T& y) const noexcept
return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight);
}

#ifndef DPF_TEST_POINT_CPP
template<typename T>
void Rectangle<T>::draw()
{
@@ -911,6 +916,7 @@ void Rectangle<T>::drawOutline()
{
_draw(true);
}
#endif

template<typename T>
Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) noexcept


+ 1
- 1
tests/Makefile View File

@@ -20,7 +20,7 @@ BUILD_CXX_FLAGS += -Wno-missing-field-initializers -Wno-extra

# ---------------------------------------------------------------------------------------------------------------------

TESTS = Application Color
TESTS = Application Color Point
TARGETS = $(TESTS:%=../build/tests/%)
OBJS = $(TARGETS:%=%.cpp.o)



+ 20
- 0
tests/Point.cpp View File

@@ -14,12 +14,32 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "tests.hpp"

#define DPF_TEST_POINT_CPP
#include "dgl/src/Geometry.cpp"

// --------------------------------------------------------------------------------------------------------------------

int main()
{
USE_NAMESPACE_DGL;

// basic usage
{
Point<int> p;
DISTRHO_ASSERT_EQUAL(p.getX(), 0, "point start X value is 0");
DISTRHO_ASSERT_EQUAL(p.getY(), 0, "point start Y value is 0");

p.setX(5);
DISTRHO_ASSERT_EQUAL(p.getX(), 5, "point X value changed to 5");
DISTRHO_ASSERT_EQUAL(p.getY(), 0, "point start Y value remains 0");

p.setY(7);
DISTRHO_ASSERT_EQUAL(p.getX(), 5, "point X value remains 5");
DISTRHO_ASSERT_EQUAL(p.getY(), 7, "point Y value changed to 7");
}

// TODO

return 0;


Loading…
Cancel
Save