From 8e3a7158ecae541692826e7b5998c8ffc810173a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 19 Oct 2011 13:59:24 -0400 Subject: Make API more consistent. Object methods should be dmnsn__(). --- libdimension-python/dimension.pxd | 18 +++++++++--------- libdimension-python/dimension.pyx | 30 +++++++++++++++++++----------- libdimension-python/tests/demo.py | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) (limited to 'libdimension-python') diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 403b327..7ba17e9 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -84,8 +84,8 @@ cdef extern from "../libdimension/dimension.h": double user double system - void dmnsn_start_timer(dmnsn_timer *timer) - void dmnsn_stop_timer(dmnsn_timer *timer) + void dmnsn_timer_start(dmnsn_timer *timer) + void dmnsn_timer_stop(dmnsn_timer *timer) ############ # Geometry # @@ -186,11 +186,11 @@ cdef extern from "../libdimension/dimension.h": dmnsn_canvas *dmnsn_new_canvas(size_t width, size_t height) void dmnsn_delete_canvas(dmnsn_canvas *canvas) - dmnsn_color dmnsn_get_pixel(dmnsn_canvas *canvas, size_t x, size_t y) - void dmnsn_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, - dmnsn_color color) + dmnsn_color dmnsn_canvas_get_pixel(dmnsn_canvas *canvas, size_t x, size_t y) + void dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, + dmnsn_color color) - void dmnsn_clear_canvas(dmnsn_canvas *canvas, dmnsn_color color) + void dmnsn_canvas_clear(dmnsn_canvas *canvas, dmnsn_color color) int dmnsn_png_optimize_canvas(dmnsn_canvas *canvas) int dmnsn_png_write_canvas(dmnsn_canvas *canvas, FILE *file) @@ -223,7 +223,7 @@ cdef extern from "../libdimension/dimension.h": void dmnsn_delete_map(dmnsn_map *map) - void dmnsn_add_map_entry(dmnsn_map *map, double n, void *obj) + void dmnsn_map_add_entry(dmnsn_map *map, double n, void *obj) size_t dmnsn_map_size(dmnsn_map *map) dmnsn_map *dmnsn_new_pigment_map() @@ -390,8 +390,8 @@ cdef extern from "../libdimension/dimension.h": dmnsn_scene *dmnsn_new_scene() void dmnsn_delete_scene(dmnsn_scene *scene) - void dmnsn_raytrace_scene(dmnsn_scene *scene) - dmnsn_future *dmnsn_raytrace_scene_async(dmnsn_scene *scene) + void dmnsn_ray_trace(dmnsn_scene *scene) + dmnsn_future *dmnsn_ray_trace_async(dmnsn_scene *scene) cdef extern from "platform.h": unsigned int dmnsn_terminal_width() diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 7f9fda0..738a63f 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -113,33 +113,41 @@ cdef class Timer: Timing starts as soon as the object is created. """ self._stopped = False - dmnsn_start_timer(&self._timer) + dmnsn_timer_start(&self._timer) def stop(self): """Stop the Timer.""" if self._stopped: raise RuntimeError("timer already stopped.") - dmnsn_stop_timer(&self._timer) + dmnsn_timer_stop(&self._timer) self._stopped = True property real: """Real (wall clock) time.""" def __get__(self): + self._assert_stopped() return self._timer.real property user: """User (CPU) time.""" def __get__(self): + self._assert_stopped() return self._timer.user property system: """System time.""" def __get__(self): + self._assert_stopped() return self._timer.system def __str__(self): + self._assert_stopped() return "%.2fs (user: %.2fs; system: %.2fs)" % \ (self._timer.real, self._timer.user, self._timer.system) + def _assert_stopped(self): + if not self._stopped: + raise RuntimeError("timer still running.") + cdef Timer _Timer(dmnsn_timer timer): """Wrap a Timer object around a dmnsn_timer.""" cdef Timer self = Timer.__new__(Timer) @@ -558,7 +566,7 @@ cdef class Canvas: def clear(self, c): """Clear a canvas with a solid color.""" - dmnsn_clear_canvas(self._canvas, Color(c)._c) + dmnsn_canvas_clear(self._canvas, Color(c)._c) def write_PNG(self, path): """Export the canvas as a PNG file.""" @@ -606,10 +614,10 @@ cdef class _CanvasProxy: return self._canvas.height def __getitem__(self, int y): self._bounds_check(y) - return _Color(dmnsn_get_pixel(self._canvas, self._x, y)) + return _Color(dmnsn_canvas_get_pixel(self._canvas, self._x, y)) def __setitem__(self, int y, color): self._bounds_check(y) - dmnsn_set_pixel(self._canvas, self._x, y, Color(color)._c) + dmnsn_canvas_set_pixel(self._canvas, self._x, y, Color(color)._c) def _bounds_check(self, int y): if y < 0 or y >= self._canvas.height: @@ -743,13 +751,13 @@ cdef class PigmentMap(Pigment): pigment = Pigment(pigment) real_pigment = (pigment)._pigment DMNSN_INCREF(real_pigment) - dmnsn_add_map_entry(pigment_map, i, &real_pigment) + dmnsn_map_add_entry(pigment_map, i, &real_pigment) else: for i, pigment in enumerate(map): pigment = Pigment(pigment) real_pigment = (pigment)._pigment DMNSN_INCREF(real_pigment) - dmnsn_add_map_entry(pigment_map, i/len(map), &real_pigment) + dmnsn_map_add_entry(pigment_map, i/len(map), &real_pigment) cdef dmnsn_pigment_map_flags flags if sRGB: @@ -1498,10 +1506,10 @@ cdef class Scene: def __get__(self): return _Timer(self._scene.render_timer) - def raytrace(self): + def ray_trace(self): """Render the scene.""" - self.raytrace_async().join() - def raytrace_async(self): + self.ray_trace_async().join() + def ray_trace_async(self): """Render the scene, in the background.""" # Account for image dimensions in the camera # Do this here so subregion renders can tell us the broader image size @@ -1518,7 +1526,7 @@ cdef class Scene: # Ensure the default texture is complete cdef Texture default = Texture(pigment = Black) dmnsn_texture_cascade(default._texture, &self._scene.default_texture) - return _Future(dmnsn_raytrace_scene_async(self._scene)) + return _Future(dmnsn_ray_trace_async(self._scene)) def __dealloc__(self): dmnsn_delete_scene(self._scene) diff --git a/libdimension-python/tests/demo.py b/libdimension-python/tests/demo.py index 720a96c..09ae184 100755 --- a/libdimension-python/tests/demo.py +++ b/libdimension-python/tests/demo.py @@ -53,7 +53,7 @@ scene.default_texture = Texture(finish = Ambient(0.1) + Diffuse(0.7)) scene.background = background scene.adc_bailout = 1/255 scene.recursion_limit = 5 -scene.raytrace() +scene.ray_trace() if have_PNG: canvas.write_PNG("demo.png") -- cgit v1.2.3