diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-01-08 15:29:42 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-01-08 15:35:34 +0300 |
commit | e830334357d1f73afbeeeb421ffcbed8e99b2fab (patch) | |
tree | 01042f96ba220e1afba8f090730b9933c257d31d /source/blender/blenlib/intern/math_geom.c | |
parent | 0634fd0e974573d4e9452795ce99b2c8105f9fee (diff) |
Math Lib: use x-span for fill_poly_v2i_n callback
Instead of running the callback per-pixel,
pass the x-span to the callback.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 7ce602238d3..8859be62fea 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2642,10 +2642,20 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], bool (*callback)(int, int } } +/** + * \param callback: Takes the x, y coords and x-span (\a x_end is not inclusive), + * note that \a x_end will always be greater than \a x, so we can use: + * + * \code{.c} + * do { + * func(x, y); + * } while (++x != x_end); + * \endcode + */ void fill_poly_v2i_n( const int xmin, const int ymin, const int xmax, const int ymax, const int verts[][2], const int nr, - void (*callback)(int, int, void *), void *userData) + void (*callback)(int x, int x_end, int y, void *), void *userData) { /* originally by Darel Rex Finley, 2007 */ @@ -2686,9 +2696,18 @@ void fill_poly_v2i_n( if (node_x[i + 1] > xmin) { if (node_x[i ] < xmin) node_x[i ] = xmin; if (node_x[i + 1] > xmax) node_x[i + 1] = xmax; + +#if 0 + /* for many x/y calls */ for (j = node_x[i]; j < node_x[i + 1]; j++) { callback(j - xmin, pixel_y - ymin, userData); } +#else + /* for single call per x-span */ + if (node_x[i] < node_x[i + 1]) { + callback(node_x[i] - xmin, node_x[i + 1] - xmin, pixel_y - ymin, userData); + } +#endif } } } |