ext/rays/polyline.cpp in rays-0.1.47 vs ext/rays/polyline.cpp in rays-0.1.48
- old
+ new
@@ -1,10 +1,11 @@
#include "rays/ruby/polyline.h"
#include <assert.h>
#include <vector>
+#include "rays/ruby/color.h"
#include "rays/ruby/point.h"
#include "rays/ruby/bounds.h"
#include "rays/ruby/polygon.h"
#include "defs.h"
@@ -22,17 +23,19 @@
return new_type<Rays::Polyline>(klass);
}
RUCY_END
static
-RUCY_DEF2(setup, points, loop)
+RUCY_DEF6(setup, points, loop, fill, colors, texcoords, hole)
{
CHECK;
- std::vector<Rays::Point> array;
- get_line_args(&array, points.size(), points.as_array());
- *THIS = Rays::Polyline(&array[0], array.size(), loop);
+ CreateParams params(points, colors, texcoords);
+ *THIS = Rays::Polyline(
+ params.ppoints(), params.size(), loop, fill,
+ params.pcolors(), params.ptexcoords(),
+ hole);
}
RUCY_END
static
RUCY_DEFN(expand)
@@ -58,18 +61,34 @@
return value(THIS->bounds());
}
RUCY_END
static
-RUCY_DEF0(loop)
+RUCY_DEF0(is_loop)
{
CHECK;
return value(THIS->loop());
}
RUCY_END
static
+RUCY_DEF0(is_fill)
+{
+ CHECK;
+ return value(THIS->fill());
+}
+RUCY_END
+
+static
+RUCY_DEF0(is_hole)
+{
+ CHECK;
+ return value(THIS->hole());
+}
+RUCY_END
+
+static
RUCY_DEF0(size)
{
CHECK;
return value(THIS->size());
}
@@ -98,22 +117,82 @@
return value((*THIS)[i]);
}
RUCY_END
static
-RUCY_DEF0(each)
+RUCY_DEF0(has_points)
{
CHECK;
+ return value(THIS->points() && !THIS->empty());
+}
+RUCY_END
+static
+RUCY_DEF0(has_colors)
+{
+ CHECK;
+ return value(THIS->colors() && !THIS->empty());
+}
+RUCY_END
+
+static
+RUCY_DEF0(has_texcoords)
+{
+ CHECK;
+ return value(THIS->texcoords() && !THIS->empty());
+}
+RUCY_END
+
+static
+RUCY_DEF0(each_point)
+{
+ CHECK;
+
Value ret = Qnil;
for (const auto& point : *THIS)
ret = rb_yield(value(point));
return ret;
}
RUCY_END
+static
+RUCY_DEF0(each_color)
+{
+ CHECK;
+ const Rays::Color* colors = THIS->colors();
+
+ Value ret = Qnil;
+ if (colors)
+ {
+ size_t size = THIS->size();
+ for (size_t i = 0; i < size; ++i)
+ ret = rb_yield(value(colors[i]));
+ }
+ return ret;
+}
+RUCY_END
+
+static
+RUCY_DEF0(each_texcoord)
+{
+ CHECK;
+
+ const Rays::Coord3* texcoords = THIS->texcoords();
+
+ Value ret = Qnil;
+ if (texcoords)
+ {
+ size_t size = THIS->size();
+ for (size_t i = 0; i < size; ++i)
+ ret = rb_yield(value(*(Rays::Point*) &texcoords[i]));
+ }
+ return ret;
+}
+RUCY_END
+
+
static Class cPolyline;
void
Init_rays_polyline ()
{
@@ -122,15 +201,22 @@
cPolyline = mRays.define_class("Polyline");
cPolyline.define_alloc_func(alloc);
cPolyline.define_private_method("setup", setup);
cPolyline.define_method("expand", expand);
cPolyline.define_method("bounds", bounds);
- cPolyline.define_method("loop?", loop);
+ cPolyline.define_method("loop?", is_loop);
+ cPolyline.define_method("fill?", is_fill);
+ cPolyline.define_method("hole?", is_hole);
cPolyline.define_method("size", size);
cPolyline.define_method("empty?", is_empty);
cPolyline.define_method("[]", get_at);
- cPolyline.define_method("each", each);
+ cPolyline.define_method("points?", has_points);
+ cPolyline.define_method("colors?", has_colors);
+ cPolyline.define_method("texcoords?", has_texcoords);
+ cPolyline.define_private_method("each_point!", each_point);
+ cPolyline.define_private_method("each_color!", each_color);
+ cPolyline.define_private_method("each_texcoord!", each_texcoord);
}
namespace Rucy
{
@@ -146,10 +232,10 @@
if (argc <= 0)
return Rays::Polyline();
else if (argv->is_num() || argv->is_array())
{
std::vector<Rays::Point> points;
- get_line_args(&points, argc, argv);
+ get_points(&points, argc, argv);
return Rays::Polyline(&points[0], points.size());
}
}
if (argc != 1)