Sha256: 57ec769e33536031de5a2d18ca64b84a4411c607dda6bda83d86ba25661cd9ec

Contents?: true

Size: 1.68 KB

Versions: 13

Compression:

Stored size: 1.68 KB

Contents

#include "rays/ruby/polygon.h"


#include "rays/ruby/polyline.h"
#include "defs.h"


RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon::Line)

#define THIS  to<Rays::Polygon::Line*>(self)

#define CHECK RUCY_CHECK_OBJECT(Rays::Polygon::Line, self)


static
VALUE alloc(VALUE klass)
{
	return new_type<Rays::Polygon::Line>(klass);
}

static
VALUE setup(VALUE self, VALUE points, VALUE loop, VALUE hole)
{
	CHECK;

	std::vector<Rays::Point> array;
	get_line_args(&array, points.size(), points.as_array());
	*THIS = Rays::Polygon::Line(&array[0], array.size(), loop, hole);
}

static
VALUE hole(VALUE self)
{
	CHECK;
	return value(THIS->hole());
}


static Class cPolygonLine;

void
Init_rays_polygon_line ()
{
	Module mRays = rb_define_module("Rays");
	Class cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);

	cPolygonLine = cPolygon.define_class("Line", Rays::polyline_class());
	rb_define_alloc_func(cPolygonLine, alloc);
	rb_define_private_method(cPolygonLine, "setup", RUBY_METHOD_FUNC(setup), 3);
	cPolygonLine.define_method("hole?", hole);
}


namespace Rucy
{


	template <> Rays::Polygon::Line
	value_to<Rays::Polygon::Line> (int argc, const Value* argv, bool convert)
	{
		assert(argc == 0 || (argc > 0 && argv));

		if (convert)
		{
			if (argc <= 0)
				return Rays::Polygon::Line();
			else if (argv->is_num() || argv->is_array())
			{
				std::vector<Rays::Point> points;
				get_line_args(&points, argc, argv);
				return Rays::Polygon::Line(&points[0], points.size());
			}
		}

		if (argc != 1)
			argument_error(__FILE__, __LINE__);

		return value_to<Rays::Polygon::Line&>(*argv, convert);
	}


}// Rucy


namespace Rays
{


	Class
	polygon_line_class ()
	{
		return cPolygonLine;
	}


}// Rays

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rays-0.1.43 .doc/ext/rays/polygon_line.cpp
rays-0.1.42 .doc/ext/rays/polygon_line.cpp
rays-0.1.40 .doc/ext/rays/polygon_line.cpp
rays-0.1.39 .doc/ext/rays/polygon_line.cpp
rays-0.1.38 .doc/ext/rays/polygon_line.cpp
rays-0.1.37 .doc/ext/rays/polygon_line.cpp
rays-0.1.36 .doc/ext/rays/polygon_line.cpp
rays-0.1.35 .doc/ext/rays/polygon_line.cpp
rays-0.1.34 .doc/ext/rays/polygon_line.cpp
rays-0.1.33 .doc/ext/rays/polygon_line.cpp
rays-0.1.32 .doc/ext/rays/polygon_line.cpp
rays-0.1.31 .doc/ext/rays/polygon_line.cpp
rays-0.1.30 .doc/ext/rays/polygon_line.cpp