#include <hxcpp.h>

#ifndef INCLUDED_Std
#include <Std.h>
#endif
#ifndef INCLUDED_hxMath
#include <hxMath.h>
#endif
#ifndef INCLUDED_luxe_Core
#include <luxe/Core.h>
#endif
#ifndef INCLUDED_luxe_ID
#include <luxe/ID.h>
#endif
#ifndef INCLUDED_luxe_utils_GeometryUtils
#include <luxe/utils/GeometryUtils.h>
#endif
#ifndef INCLUDED_phoenix_Matrix
#include <phoenix/Matrix.h>
#endif
#ifndef INCLUDED_phoenix_Spatial
#include <phoenix/Spatial.h>
#endif
#ifndef INCLUDED_phoenix_Transform
#include <phoenix/Transform.h>
#endif
#ifndef INCLUDED_phoenix_Vector
#include <phoenix/Vector.h>
#endif
#ifndef INCLUDED_phoenix_geometry_Geometry
#include <phoenix/geometry/Geometry.h>
#endif
#ifndef INCLUDED_phoenix_geometry_Vertex
#include <phoenix/geometry/Vertex.h>
#endif
#ifndef INCLUDED_snow_App
#include <snow/App.h>
#endif
namespace luxe{
namespace utils{

Void GeometryUtils_obj::__construct(::luxe::Core _luxe)
{
HX_STACK_FRAME("luxe.utils.GeometryUtils","new",0xd5d0d83c,"luxe.utils.GeometryUtils.new","luxe/utils/GeometryUtils.hx",17,0x749c9d76)

HX_STACK_ARG(_luxe,"_luxe")
{
	HX_STACK_LINE(17)
	this->luxe = _luxe;
}
;
	return null();
}

//GeometryUtils_obj::~GeometryUtils_obj() { }

Dynamic GeometryUtils_obj::__CreateEmpty() { return  new GeometryUtils_obj; }
hx::ObjectPtr< GeometryUtils_obj > GeometryUtils_obj::__new(::luxe::Core _luxe)
{  hx::ObjectPtr< GeometryUtils_obj > result = new GeometryUtils_obj();
	result->__construct(_luxe);
	return result;}

Dynamic GeometryUtils_obj::__Create(hx::DynamicArray inArgs)
{  hx::ObjectPtr< GeometryUtils_obj > result = new GeometryUtils_obj();
	result->__construct(inArgs[0]);
	return result;}

int GeometryUtils_obj::segments_for_smooth_circle( Float _radius,hx::Null< Float >  __o__smooth){
Float _smooth = __o__smooth.Default(6);
	HX_STACK_FRAME("luxe.utils.GeometryUtils","segments_for_smooth_circle",0xd8797010,"luxe.utils.GeometryUtils.segments_for_smooth_circle","luxe/utils/GeometryUtils.hx",23,0x749c9d76)
	HX_STACK_THIS(this)
	HX_STACK_ARG(_radius,"_radius")
	HX_STACK_ARG(_smooth,"_smooth")
{
		HX_STACK_LINE(23)
		return ::Std_obj::_int((_smooth * ::Math_obj::sqrt(_radius)));
	}
}


HX_DEFINE_DYNAMIC_FUNC2(GeometryUtils_obj,segments_for_smooth_circle,return )

::phoenix::Vector GeometryUtils_obj::random_point_in_unit_circle( ){
	HX_STACK_FRAME("luxe.utils.GeometryUtils","random_point_in_unit_circle",0xf851d038,"luxe.utils.GeometryUtils.random_point_in_unit_circle","luxe/utils/GeometryUtils.hx",27,0x749c9d76)
	HX_STACK_THIS(this)
	HX_STACK_LINE(30)
	Float _r = ::Math_obj::sqrt(::Math_obj::random());		HX_STACK_VAR(_r,"_r");
	HX_STACK_LINE(34)
	Float _t = ((((int)-1 + ((int)2 * ::Math_obj::random()))) * 6.283185307179586);		HX_STACK_VAR(_t,"_t");
	HX_STACK_LINE(37)
	Float _g = (_r * ::Math_obj::cos(_t));		HX_STACK_VAR(_g,"_g");
	HX_STACK_LINE(37)
	return ::phoenix::Vector_obj::__new(_g,(_r * ::Math_obj::sin(_t)),null(),null());
}


HX_DEFINE_DYNAMIC_FUNC0(GeometryUtils_obj,random_point_in_unit_circle,return )

bool GeometryUtils_obj::point_in_polygon( ::phoenix::Vector _point,::phoenix::Vector _offset,Array< ::Dynamic > _verts){
	HX_STACK_FRAME("luxe.utils.GeometryUtils","point_in_polygon",0xc66ebe53,"luxe.utils.GeometryUtils.point_in_polygon","luxe/utils/GeometryUtils.hx",41,0x749c9d76)
	HX_STACK_THIS(this)
	HX_STACK_ARG(_point,"_point")
	HX_STACK_ARG(_offset,"_offset")
	HX_STACK_ARG(_verts,"_verts")
	HX_STACK_LINE(43)
	if (((_offset == null()))){
		HX_STACK_LINE(43)
		_offset = ::phoenix::Vector_obj::__new(null(),null(),null(),null());
	}
	HX_STACK_LINE(44)
	bool c = false;		HX_STACK_VAR(c,"c");
	HX_STACK_LINE(45)
	int nvert = _verts->length;		HX_STACK_VAR(nvert,"nvert");
	HX_STACK_LINE(46)
	int j = (nvert - (int)1);		HX_STACK_VAR(j,"j");
	HX_STACK_LINE(48)
	{
		HX_STACK_LINE(48)
		int _g = (int)0;		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(48)
		while(((_g < nvert))){
			HX_STACK_LINE(48)
			int i = (_g)++;		HX_STACK_VAR(i,"i");
			HX_STACK_LINE(50)
			if (((bool((((_verts->__get(i).StaticCast< ::phoenix::Vector >()->y + _offset->y) > _point->y) != ((_verts->__get(j).StaticCast< ::phoenix::Vector >()->y + _offset->y) > _point->y))) && bool((_point->x < ((Float(((((_verts->__get(j).StaticCast< ::phoenix::Vector >()->x + _offset->x) - ((_verts->__get(i).StaticCast< ::phoenix::Vector >()->x + _offset->x)))) * ((_point->y - ((_verts->__get(i).StaticCast< ::phoenix::Vector >()->y + _offset->y)))))) / Float((((_verts->__get(j).StaticCast< ::phoenix::Vector >()->y + _offset->y) - ((_verts->__get(i).StaticCast< ::phoenix::Vector >()->y + _offset->y)))))) + ((_verts->__get(i).StaticCast< ::phoenix::Vector >()->x + _offset->x)))))))){
				HX_STACK_LINE(53)
				c = !(c);
			}
			HX_STACK_LINE(56)
			j = i;
		}
	}
	HX_STACK_LINE(59)
	return c;
}


HX_DEFINE_DYNAMIC_FUNC3(GeometryUtils_obj,point_in_polygon,return )

bool GeometryUtils_obj::point_in_geometry( ::phoenix::Vector _point,::phoenix::geometry::Geometry _geometry){
	HX_STACK_FRAME("luxe.utils.GeometryUtils","point_in_geometry",0x80cfa4b9,"luxe.utils.GeometryUtils.point_in_geometry","luxe/utils/GeometryUtils.hx",66,0x749c9d76)
	HX_STACK_THIS(this)
	HX_STACK_ARG(_point,"_point")
	HX_STACK_ARG(_geometry,"_geometry")
	HX_STACK_LINE(68)
	bool c = false;		HX_STACK_VAR(c,"c");
	HX_STACK_LINE(69)
	int nvert = _geometry->vertices->length;		HX_STACK_VAR(nvert,"nvert");
	HX_STACK_LINE(70)
	int j = (nvert - (int)1);		HX_STACK_VAR(j,"j");
	HX_STACK_LINE(72)
	{
		HX_STACK_LINE(72)
		int _g = (int)0;		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(72)
		while(((_g < nvert))){
			HX_STACK_LINE(72)
			int i = (_g)++;		HX_STACK_VAR(i,"i");
			HX_STACK_LINE(74)
			::phoenix::Vector _vert_i_pos = _geometry->vertices->__get(i).StaticCast< ::phoenix::geometry::Vertex >()->pos->clone()->transform(_geometry->transform->get_world()->get_matrix());		HX_STACK_VAR(_vert_i_pos,"_vert_i_pos");
			HX_STACK_LINE(75)
			::phoenix::Vector _vert_j_pos = _geometry->vertices->__get(j).StaticCast< ::phoenix::geometry::Vertex >()->pos->clone()->transform(_geometry->transform->get_world()->get_matrix());		HX_STACK_VAR(_vert_j_pos,"_vert_j_pos");
			HX_STACK_LINE(77)
			if (((bool(((_vert_i_pos->y > _point->y) != (_vert_j_pos->y > _point->y))) && bool((_point->x < ((Float((((_vert_j_pos->x - _vert_i_pos->x)) * ((_point->y - _vert_i_pos->y)))) / Float(((_vert_j_pos->y - _vert_i_pos->y)))) + _vert_i_pos->x)))))){
				HX_STACK_LINE(80)
				c = !(c);
			}
			HX_STACK_LINE(83)
			j = i;
		}
	}
	HX_STACK_LINE(86)
	return c;
}


HX_DEFINE_DYNAMIC_FUNC2(GeometryUtils_obj,point_in_geometry,return )

::phoenix::Vector GeometryUtils_obj::intersect_ray_plane( ::phoenix::Vector _ray_start,::phoenix::Vector _ray_dir,::phoenix::Vector _plane_normal,::phoenix::Vector _plane_point){
	HX_STACK_FRAME("luxe.utils.GeometryUtils","intersect_ray_plane",0xfb92d043,"luxe.utils.GeometryUtils.intersect_ray_plane","luxe/utils/GeometryUtils.hx",92,0x749c9d76)
	HX_STACK_THIS(this)
	HX_STACK_ARG(_ray_start,"_ray_start")
	HX_STACK_ARG(_ray_dir,"_ray_dir")
	HX_STACK_ARG(_plane_normal,"_plane_normal")
	HX_STACK_ARG(_plane_point,"_plane_point")
	HX_STACK_LINE(98)
	Float part1 = _plane_normal->dot(::phoenix::Vector_obj::Subtract(_plane_point,_ray_start));		HX_STACK_VAR(part1,"part1");
	HX_STACK_LINE(99)
	Float part2 = _plane_normal->dot(_ray_dir);		HX_STACK_VAR(part2,"part2");
	HX_STACK_LINE(101)
	Float T = (Float(part1) / Float(part2));		HX_STACK_VAR(T,"T");
	HX_STACK_LINE(103)
	return ::phoenix::Vector_obj::Add(_ray_start,::phoenix::Vector_obj::Multiply(_ray_dir,T));
}


HX_DEFINE_DYNAMIC_FUNC4(GeometryUtils_obj,intersect_ray_plane,return )

Float GeometryUtils_obj::two_pi;


GeometryUtils_obj::GeometryUtils_obj()
{
}

void GeometryUtils_obj::__Mark(HX_MARK_PARAMS)
{
	HX_MARK_BEGIN_CLASS(GeometryUtils);
	HX_MARK_MEMBER_NAME(luxe,"luxe");
	HX_MARK_END_CLASS();
}

void GeometryUtils_obj::__Visit(HX_VISIT_PARAMS)
{
	HX_VISIT_MEMBER_NAME(luxe,"luxe");
}

Dynamic GeometryUtils_obj::__Field(const ::String &inName,bool inCallProp)
{
	switch(inName.length) {
	case 4:
		if (HX_FIELD_EQ(inName,"luxe") ) { return luxe; }
		break;
	case 16:
		if (HX_FIELD_EQ(inName,"point_in_polygon") ) { return point_in_polygon_dyn(); }
		break;
	case 17:
		if (HX_FIELD_EQ(inName,"point_in_geometry") ) { return point_in_geometry_dyn(); }
		break;
	case 19:
		if (HX_FIELD_EQ(inName,"intersect_ray_plane") ) { return intersect_ray_plane_dyn(); }
		break;
	case 26:
		if (HX_FIELD_EQ(inName,"segments_for_smooth_circle") ) { return segments_for_smooth_circle_dyn(); }
		break;
	case 27:
		if (HX_FIELD_EQ(inName,"random_point_in_unit_circle") ) { return random_point_in_unit_circle_dyn(); }
	}
	return super::__Field(inName,inCallProp);
}

Dynamic GeometryUtils_obj::__SetField(const ::String &inName,const Dynamic &inValue,bool inCallProp)
{
	switch(inName.length) {
	case 4:
		if (HX_FIELD_EQ(inName,"luxe") ) { luxe=inValue.Cast< ::luxe::Core >(); return inValue; }
	}
	return super::__SetField(inName,inValue,inCallProp);
}

void GeometryUtils_obj::__GetFields(Array< ::String> &outFields)
{
	outFields->push(HX_CSTRING("luxe"));
	super::__GetFields(outFields);
};

static ::String sStaticFields[] = {
	HX_CSTRING("two_pi"),
	String(null()) };

#if HXCPP_SCRIPTABLE
static hx::StorageInfo sMemberStorageInfo[] = {
	{hx::fsObject /*::luxe::Core*/ ,(int)offsetof(GeometryUtils_obj,luxe),HX_CSTRING("luxe")},
	{ hx::fsUnknown, 0, null()}
};
#endif

static ::String sMemberFields[] = {
	HX_CSTRING("luxe"),
	HX_CSTRING("segments_for_smooth_circle"),
	HX_CSTRING("random_point_in_unit_circle"),
	HX_CSTRING("point_in_polygon"),
	HX_CSTRING("point_in_geometry"),
	HX_CSTRING("intersect_ray_plane"),
	String(null()) };

static void sMarkStatics(HX_MARK_PARAMS) {
	HX_MARK_MEMBER_NAME(GeometryUtils_obj::__mClass,"__mClass");
	HX_MARK_MEMBER_NAME(GeometryUtils_obj::two_pi,"two_pi");
};

#ifdef HXCPP_VISIT_ALLOCS
static void sVisitStatics(HX_VISIT_PARAMS) {
	HX_VISIT_MEMBER_NAME(GeometryUtils_obj::__mClass,"__mClass");
	HX_VISIT_MEMBER_NAME(GeometryUtils_obj::two_pi,"two_pi");
};

#endif

Class GeometryUtils_obj::__mClass;

void GeometryUtils_obj::__register()
{
	hx::Static(__mClass) = hx::RegisterClass(HX_CSTRING("luxe.utils.GeometryUtils"), hx::TCanCast< GeometryUtils_obj> ,sStaticFields,sMemberFields,
	&__CreateEmpty, &__Create,
	&super::__SGetClass(), 0, sMarkStatics
#ifdef HXCPP_VISIT_ALLOCS
    , sVisitStatics
#endif
#ifdef HXCPP_SCRIPTABLE
    , sMemberStorageInfo
#endif
);
}

void GeometryUtils_obj::__boot()
{
	two_pi= 6.283185307179586;
}

} // end namespace luxe
} // end namespace utils
