summaryrefslogtreecommitdiffstats
path: root/libdimensionxx
diff options
context:
space:
mode:
Diffstat (limited to 'libdimensionxx')
-rw-r--r--libdimensionxx/camera.cpp4
-rw-r--r--libdimensionxx/cameras.cpp6
-rw-r--r--libdimensionxx/canvas.cpp7
-rw-r--r--libdimensionxx/cookie-fopencookie.cpp11
-rw-r--r--libdimensionxx/cookie-tmpfile.cpp2
-rw-r--r--libdimensionxx/dimensionxx/cameras.hpp2
-rw-r--r--libdimensionxx/dimensionxx/cookie.hpp3
-rw-r--r--libdimensionxx/dimensionxx/error.hpp4
-rw-r--r--libdimensionxx/dimensionxx/object.hpp4
-rw-r--r--libdimensionxx/dimensionxx/objects.hpp2
-rw-r--r--libdimensionxx/dimensionxx/raytrace.hpp1
-rw-r--r--libdimensionxx/object.cpp8
-rw-r--r--libdimensionxx/progress.cpp3
-rw-r--r--libdimensionxx/raytrace.cpp1
-rw-r--r--libdimensionxx/scene.cpp2
15 files changed, 40 insertions, 20 deletions
diff --git a/libdimensionxx/camera.cpp b/libdimensionxx/camera.cpp
index ba2428a..efe0802 100644
--- a/libdimensionxx/camera.cpp
+++ b/libdimensionxx/camera.cpp
@@ -30,7 +30,7 @@ namespace Dimension
Line
Camera::ray(const Canvas& canvas, unsigned int x, unsigned int y)
{
- return Line(dmnsn()->ray_fn(dmnsn(), canvas.dmnsn(), x, y));
+ return Line((*dmnsn()->ray_fn)(dmnsn(), canvas.dmnsn(), x, y));
}
// Return the wrapped camera
@@ -74,7 +74,7 @@ namespace Dimension
bool
Camera::unique() const
{
- return m_camera.unique();
+ return m_camera && m_camera.unique();
}
// Set the wrapped dmnsn_camera*
diff --git a/libdimensionxx/cameras.cpp b/libdimensionxx/cameras.cpp
index ea0bca9..dee4df6 100644
--- a/libdimensionxx/cameras.cpp
+++ b/libdimensionxx/cameras.cpp
@@ -31,7 +31,7 @@ namespace Dimension
}
}
- // Delete a perspective camera
+ // Delete a perspective camera, if we're the last reference
Perspective_Camera::~Perspective_Camera()
{
if (unique()) {
@@ -39,24 +39,28 @@ namespace Dimension
}
}
+ // Get the transformation matrix
Matrix
Perspective_Camera::trans()
{
return Matrix(dmnsn_get_perspective_camera_trans(dmnsn()));
}
+ // Set the transformation matrix
void
Perspective_Camera::trans(const Matrix& trans)
{
dmnsn_set_perspective_camera_trans(dmnsn(), trans.dmnsn());
}
+ // Shallow-copy this camera
Camera*
Perspective_Camera::copy() const
{
return new Perspective_Camera(*this);
}
+ // Private copy-constructor, for copy() implementation
Perspective_Camera::Perspective_Camera(const Perspective_Camera& camera)
: Camera(camera)
{ }
diff --git a/libdimensionxx/canvas.cpp b/libdimensionxx/canvas.cpp
index 3ff9d32..6118730 100644
--- a/libdimensionxx/canvas.cpp
+++ b/libdimensionxx/canvas.cpp
@@ -24,7 +24,12 @@ namespace Dimension
{
// Allocate the canvas with dmnsn_new_canvas()
Canvas::Canvas(unsigned int width, unsigned int height)
- : m_canvas(new dmnsn_canvas*(dmnsn_new_canvas(width, height))) { }
+ : m_canvas(new dmnsn_canvas*(dmnsn_new_canvas(width, height)))
+ {
+ if (!dmnsn()) {
+ throw Dimension_Error("Couldn't allocate canvas.");
+ }
+ }
// Wrap an existing dmnsn_canvas*
Canvas::Canvas(dmnsn_canvas* canvas)
diff --git a/libdimensionxx/cookie-fopencookie.cpp b/libdimensionxx/cookie-fopencookie.cpp
index e165c8d..1d1f813 100644
--- a/libdimensionxx/cookie-fopencookie.cpp
+++ b/libdimensionxx/cookie-fopencookie.cpp
@@ -26,12 +26,11 @@
#endif
#include <stdio.h>
-// The conundrum: libdimension and libdimension-* use C I/O, with FILE*'s.
-// We want to use C++ I/O with std::i/ostreams. If present, we use the
-// nonportable GNU stdio extension fopencookie(), which creates a FILE* with
-// custom read/write/seek functions. BSD also has a similar function, funopen()
-// which we should use too. Failing in all that, fall back on a tmpfile()
-// buffer (see cookie-tmpfile.cpp).
+// The conundrum: libdimension uses C I/O, with FILE*'s. We want to use C++ I/O
+// with std::i/ostreams. If present, we use the nonportable GNU stdio extension
+// fopencookie(), which creates a FILE* with custom read/write/seek functions.
+// BSD also has a similar function, funopen() which we should use too. Failing
+// in all that, fall back on a tmpfile() buffer (see cookie-tmpfile.cpp).
namespace Dimension
{
diff --git a/libdimensionxx/cookie-tmpfile.cpp b/libdimensionxx/cookie-tmpfile.cpp
index 6a41f09..b2d25b8 100644
--- a/libdimensionxx/cookie-tmpfile.cpp
+++ b/libdimensionxx/cookie-tmpfile.cpp
@@ -21,7 +21,7 @@
#include "dimensionxx.hpp"
#include <stdio.h>
-// Use a tmpfile as a buffer for a C++/C I/O interface.
+// Use a tmpfile() as a buffer for a C++/C I/O interface.
namespace Dimension
{
diff --git a/libdimensionxx/dimensionxx/cameras.hpp b/libdimensionxx/dimensionxx/cameras.hpp
index cabae97..2726a0c 100644
--- a/libdimensionxx/dimensionxx/cameras.hpp
+++ b/libdimensionxx/dimensionxx/cameras.hpp
@@ -32,9 +32,11 @@ namespace Dimension
Perspective_Camera(const Matrix& trans);
~Perspective_Camera();
+ // Get/set the transformation matrix
Matrix trans();
void trans(const Matrix& trans);
+ // Shallow-copy the camera
Camera* copy() const;
private:
diff --git a/libdimensionxx/dimensionxx/cookie.hpp b/libdimensionxx/dimensionxx/cookie.hpp
index 0d8b4da..9dbe7b8 100644
--- a/libdimensionxx/dimensionxx/cookie.hpp
+++ b/libdimensionxx/dimensionxx/cookie.hpp
@@ -38,12 +38,15 @@ namespace Dimension
FILE_Cookie(std::iostream& iostr);
~FILE_Cookie();
+ // Get the magic FILE*
FILE* file();
const FILE* file() const;
+ // Are we an input or output stream?
bool is_input() const;
bool is_output() const;
+ // Get the C++ streams
std::istream& istr();
const std::istream& istr() const;
std::ostream& ostr();
diff --git a/libdimensionxx/dimensionxx/error.hpp b/libdimensionxx/dimensionxx/error.hpp
index 7fb0e53..ad61284 100644
--- a/libdimensionxx/dimensionxx/error.hpp
+++ b/libdimensionxx/dimensionxx/error.hpp
@@ -20,8 +20,8 @@
// Wrappers for libdimension error handling, and an exception class.
// dmnsn_error is still used by libdimensionxx whenever an exception shouldn't
-// be thrown, like in destructors, and whenever libdimension or libdimension-*
-// use it internally. Exceptions are thrown otherwise to report errors.
+// be thrown, like in destructors, and whenever libdimension uses it internally.
+// Exceptions are thrown otherwise to report errors.
#ifndef DIMENSIONXX_ERROR_HPP
#define DIMENSIONXX_ERROR_HPP
diff --git a/libdimensionxx/dimensionxx/object.hpp b/libdimensionxx/dimensionxx/object.hpp
index c56d358..e0b45f4 100644
--- a/libdimensionxx/dimensionxx/object.hpp
+++ b/libdimensionxx/dimensionxx/object.hpp
@@ -40,10 +40,10 @@ namespace Dimension
virtual Array<double> intersections(const Line& l);
virtual bool inside(const Vector& point);
- // Shallow-copy a derived
+ // Shallow-copy a derived object
virtual Object* copy() const = 0;
- // Access the wrapped C object.
+ // Access the wrapped C object
dmnsn_object* dmnsn();
const dmnsn_object* dmnsn() const;
diff --git a/libdimensionxx/dimensionxx/objects.hpp b/libdimensionxx/dimensionxx/objects.hpp
index 5b43dc4..11e408c 100644
--- a/libdimensionxx/dimensionxx/objects.hpp
+++ b/libdimensionxx/dimensionxx/objects.hpp
@@ -32,6 +32,7 @@ namespace Dimension
Sphere();
~Sphere();
+ // Shallow-copy the sphere
Object* copy() const;
private:
@@ -47,6 +48,7 @@ namespace Dimension
Cube();
~Cube();
+ // Shallow-copy the cube
Object* copy() const;
private:
diff --git a/libdimensionxx/dimensionxx/raytrace.hpp b/libdimensionxx/dimensionxx/raytrace.hpp
index bfd7e1c..8cf4ee4 100644
--- a/libdimensionxx/dimensionxx/raytrace.hpp
+++ b/libdimensionxx/dimensionxx/raytrace.hpp
@@ -34,6 +34,7 @@ namespace Dimension
Raytracer(Scene& scene);
~Raytracer();
+ // Render the scene
void render();
Progress render_async();
diff --git a/libdimensionxx/object.cpp b/libdimensionxx/object.cpp
index 61b8b7d..1a43f62 100644
--- a/libdimensionxx/object.cpp
+++ b/libdimensionxx/object.cpp
@@ -26,12 +26,14 @@ namespace Dimension
Object::~Object()
{ }
+ // Get the transformation matrix
Matrix
Object::trans()
{
return Matrix(dmnsn()->trans);
}
+ // Set the transformation matrix
void
Object::trans(const Matrix& trans)
{
@@ -42,14 +44,14 @@ namespace Dimension
Array<double>
Object::intersections(const Line& l)
{
- return Array<double>(dmnsn()->intersections_fn(dmnsn(), l.dmnsn()));
+ return Array<double>((*dmnsn()->intersections_fn)(dmnsn(), l.dmnsn()));
}
// Whether the point `point' is inside the object
bool
Object::inside(const Vector& point)
{
- return dmnsn()->inside_fn(dmnsn(), point.dmnsn());
+ return (*dmnsn()->inside_fn)(dmnsn(), point.dmnsn());
}
// Return the wrapped object
@@ -93,7 +95,7 @@ namespace Dimension
bool
Object::unique() const
{
- return m_object.unique();
+ return m_object && m_object.unique();
}
// Set the wrapped dmnsn_object*
diff --git a/libdimensionxx/progress.cpp b/libdimensionxx/progress.cpp
index 66d9d7f..7cf42aa 100644
--- a/libdimensionxx/progress.cpp
+++ b/libdimensionxx/progress.cpp
@@ -22,6 +22,7 @@
namespace Dimension
{
+ // No-op virtual destructor
Persist_Base::~Persist_Base()
{ }
@@ -38,7 +39,7 @@ namespace Dimension
// Finish the progress if not yet finished and we are unique
Progress::~Progress()
{
- if (m_progress) {
+ if (m_progress && m_progress.unique()) {
try {
finish();
} catch (...) {
diff --git a/libdimensionxx/raytrace.cpp b/libdimensionxx/raytrace.cpp
index 263fe6d..d3ae769 100644
--- a/libdimensionxx/raytrace.cpp
+++ b/libdimensionxx/raytrace.cpp
@@ -22,6 +22,7 @@
namespace Dimension
{
+ // Construct a raytracer
Raytracer::Raytracer(Scene& scene)
: m_scene(&scene), m_rendered(false) { }
diff --git a/libdimensionxx/scene.cpp b/libdimensionxx/scene.cpp
index 2b0fba5..fec961a 100644
--- a/libdimensionxx/scene.cpp
+++ b/libdimensionxx/scene.cpp
@@ -27,7 +27,7 @@ namespace Dimension
: m_scene(new dmnsn_scene*(dmnsn_new_scene())), m_camera(camera.copy()),
m_canvas(new Canvas(canvas))
{
- if (!m_scene) {
+ if (!dmnsn()) {
throw Dimension_Error("Couldn't allocate scene.");
}