Skip to content

Commit

Permalink
better handling of projection failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Jan 29, 2013
1 parent afd78db commit 1ed216e
Showing 1 changed file with 78 additions and 70 deletions.
148 changes: 78 additions & 70 deletions src/mapnik_projection.cpp
Expand Up @@ -68,46 +68,50 @@ Handle<Value> Projection::forward(const Arguments& args)
HandleScope scope; HandleScope scope;
Projection* p = ObjectWrap::Unwrap<Projection>(args.This()); Projection* p = ObjectWrap::Unwrap<Projection>(args.This());


if (!args.Length() == 1) try
return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
else
{ {
if (!args[0]->IsArray()) if (!args.Length() == 1)
return ThrowException(Exception::Error( return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"))); String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));

else
Local<Array> a = Local<Array>::Cast(args[0]);
unsigned int array_length = a->Length();
if (array_length == 2)
{
double x = a->Get(0)->NumberValue();
double y = a->Get(1)->NumberValue();
p->projection_->forward(x,y);
Local<Array> arr = Array::New(2);
arr->Set(0, Number::New(x));
arr->Set(1, Number::New(y));
return scope.Close(arr);
}
else if (array_length == 4)
{ {
double minx = a->Get(0)->NumberValue(); if (!args[0]->IsArray())
double miny = a->Get(1)->NumberValue(); return ThrowException(Exception::Error(
double maxx = a->Get(2)->NumberValue(); String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
double maxy = a->Get(3)->NumberValue(); Local<Array> a = Local<Array>::Cast(args[0]);
p->projection_->forward(minx,miny); unsigned int array_length = a->Length();
p->projection_->forward(maxx,maxy); if (array_length == 2)
Local<Array> arr = Array::New(4); {
arr->Set(0, Number::New(minx)); double x = a->Get(0)->NumberValue();
arr->Set(1, Number::New(miny)); double y = a->Get(1)->NumberValue();
arr->Set(2, Number::New(maxx)); p->projection_->forward(x,y);
arr->Set(3, Number::New(maxy)); Local<Array> arr = Array::New(2);
return scope.Close(arr); arr->Set(0, Number::New(x));
arr->Set(1, Number::New(y));
return scope.Close(arr);
}
else if (array_length == 4)
{
double minx = a->Get(0)->NumberValue();
double miny = a->Get(1)->NumberValue();
double maxx = a->Get(2)->NumberValue();
double maxy = a->Get(3)->NumberValue();
p->projection_->forward(minx,miny);
p->projection_->forward(maxx,maxy);
Local<Array> arr = Array::New(4);
arr->Set(0, Number::New(minx));
arr->Set(1, Number::New(miny));
arr->Set(2, Number::New(maxx));
arr->Set(3, Number::New(maxy));
return scope.Close(arr);
}
else
return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
} }
else } catch (std::exception const & ex) {
return ThrowException(Exception::Error( return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"))); String::New(ex.what())));

} }
} }


Expand All @@ -116,46 +120,50 @@ Handle<Value> Projection::inverse(const Arguments& args)
HandleScope scope; HandleScope scope;
Projection* p = ObjectWrap::Unwrap<Projection>(args.This()); Projection* p = ObjectWrap::Unwrap<Projection>(args.This());


if (!args.Length() == 1) try
return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
else
{ {
if (!args[0]->IsArray()) if (!args.Length() == 1)
return ThrowException(Exception::Error( return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"))); String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));

else
Local<Array> a = Local<Array>::Cast(args[0]);
unsigned int array_length = a->Length();
if (array_length == 2)
{
double x = a->Get(0)->NumberValue();
double y = a->Get(1)->NumberValue();
p->projection_->inverse(x,y);
Local<Array> arr = Array::New(2);
arr->Set(0, Number::New(x));
arr->Set(1, Number::New(y));
return scope.Close(arr);
}
else if (array_length == 4)
{ {
double minx = a->Get(0)->NumberValue(); if (!args[0]->IsArray())
double miny = a->Get(1)->NumberValue(); return ThrowException(Exception::Error(
double maxx = a->Get(2)->NumberValue(); String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
double maxy = a->Get(3)->NumberValue(); Local<Array> a = Local<Array>::Cast(args[0]);
p->projection_->inverse(minx,miny); unsigned int array_length = a->Length();
p->projection_->inverse(maxx,maxy); if (array_length == 2)
Local<Array> arr = Array::New(4); {
arr->Set(0, Number::New(minx)); double x = a->Get(0)->NumberValue();
arr->Set(1, Number::New(miny)); double y = a->Get(1)->NumberValue();
arr->Set(2, Number::New(maxx)); p->projection_->inverse(x,y);
arr->Set(3, Number::New(maxy)); Local<Array> arr = Array::New(2);
return scope.Close(arr); arr->Set(0, Number::New(x));
arr->Set(1, Number::New(y));
return scope.Close(arr);
}
else if (array_length == 4)
{
double minx = a->Get(0)->NumberValue();
double miny = a->Get(1)->NumberValue();
double maxx = a->Get(2)->NumberValue();
double maxy = a->Get(3)->NumberValue();
p->projection_->inverse(minx,miny);
p->projection_->inverse(maxx,maxy);
Local<Array> arr = Array::New(4);
arr->Set(0, Number::New(minx));
arr->Set(1, Number::New(miny));
arr->Set(2, Number::New(maxx));
arr->Set(3, Number::New(maxy));
return scope.Close(arr);
}
else
return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]")));
} }
else } catch (std::exception const & ex) {
return ThrowException(Exception::Error( return ThrowException(Exception::Error(
String::New("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"))); String::New(ex.what())));

} }
} }


0 comments on commit 1ed216e

Please sign in to comment.