#include "Wumbo-Functions.h"
#include "Wumbo-Types.h"
#include <cmath>
#define M_PI 3.14159265359f
namespace Wumbo
{
	vec2df rotatePointDEG(float pointX, float pointY, float originX, float originY, float angle)
	{
		angle *= M_PI/180.f;
		vec2df point;
		point.x = cos(angle) * (pointX-originX) - sin(angle) * (pointY-originY) + originX;
		point.y = sin(angle) * (pointX-originX) + cos(angle) * (pointY-originY) + originY;
		return point;
	}
	
	NSString *cstr2nsstring(const char *cstr)
	{
#if PLATFORM_APPLE
		return [NSString stringWithFormat:@"%s",cstr];
#else
		return (char*) cstr;
#endif	
	}
#if PLATFORM_APPLE
	NSString* concat(NSString* one, NSString* two)
	{
		return [NSString stringWithFormat:@"%@%@",one,two];
	}
	
	NSString* NSStd(std::string a)
	{
		NSString* cereal = [NSString stringWithUTF8String: a.c_str()];
		return cereal;
	}
#endif
	
#if PLATFORM_APPLE
	NSString* BundleResource(NSString *name)
	{
		//NSString* fname = concat(@"/",name);
		NSString* nspath = [NSString stringWithFormat:@"%@%s%@",[[NSBundle mainBundle] resourcePath],"/",name];//[[NSBundle mainBundle] pathForResource: fname_prefix ofType: fname_ext];
		return nspath;
	}
#endif
	
	NSString* BundleResource(char *name)
	{
#if PLATFORM_APPLE
		//NSString* fname = concat(@"/",name);
		NSString* nspath = [NSString stringWithFormat:@"%@%s%@",[[NSBundle mainBundle] resourcePath],"/",cstr2nsstring(name)];//[[NSBundle mainBundle] pathForResource: fname_prefix ofType: fname_ext];
		return nspath;
#else
		return name;
#endif
	}
	
	NSString* BundleResource(std::string name)
	{
#if PLATFORM_APPLE
		//NSString* fname = concat(@"/",name);
		NSString* nspath = [NSString stringWithFormat:@"%@%s%@",[[NSBundle mainBundle] resourcePath],"/",cstr2nsstring(name.c_str())];//[[NSBundle mainBundle] pathForResource: fname_prefix ofType: fname_ext];
		return nspath;
#else
		return (char*) name.c_str();
#endif
	}
	
	
	
#if PLATFORM_APPLE	
	NSString* DocumentResource(NSString *name)
	{

		NSArray *search = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
		NSMutableString *nspath = [NSMutableString stringWithFormat:@"%@%s%@", [search objectAtIndex:0], "/", name];
		return nspath;
	}
#endif

	NSString* DocumentResource(char *name)
	{
#if PLATFORM_APPLE
		NSArray *search = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
		NSMutableString *nspath = [NSMutableString stringWithFormat:@"%@%s%s", [search objectAtIndex:0], "/", name];
		return nspath;
#else
		return name;
#endif
	}
	
	NSString* DocumentResource(std::string name)
	{
#if PLATFORM_APPLE
		NSArray *search = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
		NSMutableString *nspath = [NSMutableString stringWithFormat:@"%@%s%s", [search objectAtIndex:0], "/", name.c_str()];
		return nspath;
#else
		return (char*) name.c_str();
#endif
	}

};