Skip to content

Commit

Permalink
Add test code for Sphere.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Apr 14, 2015
1 parent 9a5cdfc commit b40d632
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/rainy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../src/Renderer/common.h"
#include "../src/Renderer/Vector3.h"
#include "../src/Renderer/Sphere.h"
#include "../src/Renderer/Renderer.h"

#endif // RAINY_H_
1 change: 1 addition & 0 deletions src/Renderer/Ray.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define RAINY_RAY_EXPORT
#include "Ray.h"
#include "common.h"

Expand Down
16 changes: 13 additions & 3 deletions src/Renderer/Ray.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#ifndef RAINY_RAY_H_
#define RAINY_RAY_H_

#if defined(_WIN32) || defined(__WIN32__)
#ifdef RAINY_RAY_EXPORT
#define RAINY_RAY_DLL __declspec(dllexport)
#else
#define RAINY_RAY_DLL __declspec(dllimport)
#endif
#elif defined(linux) || defined(__linux)
#define RAINY_RAY_DLL
#endif

#include "Vector3.h"

namespace rainy {

class Ray {
class RAINY_RAY_DLL Ray {
private:
Vector3 _origin;
Vector3 _direction;
Expand All @@ -22,7 +32,7 @@ namespace rainy {
inline Vector3 direction() const { return _direction; }
};

class HitPoint {
class RAINY_RAY_DLL HitPoint {
private:
double _distance;
Vector3 _normal;
Expand All @@ -44,7 +54,7 @@ namespace rainy {
inline void setPosition(const Vector3& position) { _position = position; }
};

class Intersection {
class RAINY_RAY_DLL Intersection {
private:
HitPoint _hitPoint;
int _objectId;
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Sphere.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define RAINY_SPHERE_EXPORT
#include "Sphere.h"

#include <cmath>
Expand Down
14 changes: 13 additions & 1 deletion src/Renderer/Sphere.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#ifndef RAINY_SPHERE_H_
#define RAINY_SPHERE_H_

#if defined(_WIN32) || defined(__WIN32__)
#ifdef RAINY_SPHERE_EXPORT
#define RAINY_SPHERE_DLL __declspec(dllexport)
#else
#define RAINY_SPHERE_DLL __declspec(dllimport)
#endif
#elif defined(linux) || defined(__linux)
#define RAINY_SPHERE_DLL
#endif

#include "Vector3.h"
#include "material.h"
#include "Ray.h"

namespace rainy {

class Sphere {
class RAINY_SPHERE_DLL Sphere {
private:
double _radius;
Vector3 _center;
Expand All @@ -30,6 +40,8 @@ namespace rainy {
*/
bool intersect(const Ray& ray, HitPoint& hitpoint) const;

inline double radius() const { return _radius; }
inline Vector3 center() const { return _center; }
inline Color color() const { return _color; }
inline Color emission() const { return _emission; }
inline ReflectionType reftype() const { return _reftype; }
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function (add_gtest test_name test_source)
endfunction(add_gtest)

add_gtest(test_Vector3 test_Vector3.cc)
add_gtest(test_Sphere test_Sphere.cc)

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_Vector3)

Expand Down
20 changes: 20 additions & 0 deletions test/test_Sphere.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "gtest/gtest.h"

#include "../include/rainy.h"
using namespace rainy;

TEST(SphereTest, InstanceTest) {
Sphere sp(1.0, Vector3(0.0, 0.0, 0.0), Color(), Color(0.75, 0.75, 0.75), REFLECTION_DIFFUSE);

EXPECT_EQ(0.0, sp.center().x());
EXPECT_EQ(0.0, sp.center().y());
EXPECT_EQ(0.0, sp.center().z());

HitPoint hitpoint;
sp.intersect(Ray(Vector3(10.0, 0.0, 0.0), Vector3(-1.0, 0.0, 0.0)), hitpoint);
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
2 changes: 1 addition & 1 deletion test/test_Vector3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ TEST(Vector3Test, AlgebraTest) {
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
}

0 comments on commit b40d632

Please sign in to comment.