|
3 | 3 | Nan::Persistent<v8::FunctionTemplate> Vec2::constructor;
|
4 | 4 | Nan::Persistent<v8::FunctionTemplate> Vec3::constructor;
|
5 | 5 | Nan::Persistent<v8::FunctionTemplate> Vec4::constructor;
|
| 6 | +Nan::Persistent<v8::FunctionTemplate> Vec6::constructor; |
6 | 7 |
|
7 | 8 | NAN_MODULE_INIT(Vec::Init) {
|
8 | 9 | v8::Local<v8::FunctionTemplate> vec2Ctor = Nan::New<v8::FunctionTemplate>(Vec2::New);
|
@@ -39,42 +40,74 @@ NAN_MODULE_INIT(Vec::Init) {
|
39 | 40 | Nan::SetPrototypeMethod(vec4Ctor, "norm", Vec4::Norm);
|
40 | 41 | Vec4::Init(vec4Ctor);
|
41 | 42 |
|
| 43 | + v8::Local<v8::FunctionTemplate> vec6Ctor = Nan::New<v8::FunctionTemplate>(Vec6::New); |
| 44 | + Vec6::constructor.Reset(vec6Ctor); |
| 45 | + vec6Ctor->InstanceTemplate()->SetInternalFieldCount(1); |
| 46 | + vec6Ctor->SetClassName(Nan::New("Vec6").ToLocalChecked()); |
| 47 | + Nan::SetAccessor(vec6Ctor->InstanceTemplate(), Nan::New("u").ToLocalChecked(), Vec6::u_getter); |
| 48 | + Nan::SetAccessor(vec6Ctor->InstanceTemplate(), Nan::New("v").ToLocalChecked(), Vec6::v_getter); |
| 49 | + Nan::SetAccessor(vec6Ctor->InstanceTemplate(), Nan::New("w").ToLocalChecked(), Vec6::w_getter); |
| 50 | + Nan::SetAccessor(vec6Ctor->InstanceTemplate(), Nan::New("x").ToLocalChecked(), Vec6::x_getter); |
| 51 | + Nan::SetAccessor(vec6Ctor->InstanceTemplate(), Nan::New("y").ToLocalChecked(), Vec6::y_getter); |
| 52 | + Nan::SetAccessor(vec6Ctor->InstanceTemplate(), Nan::New("z").ToLocalChecked(), Vec6::z_getter); |
| 53 | + Nan::SetPrototypeMethod(vec6Ctor, "at", Vec6::At); |
| 54 | + Nan::SetPrototypeMethod(vec6Ctor, "norm", Vec6::Norm); |
| 55 | + Vec6::Init(vec6Ctor); |
| 56 | + |
42 | 57 | v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(Vec::New);
|
43 | 58 | ctor->InstanceTemplate()->SetInternalFieldCount(1);
|
44 | 59 | ctor->SetClassName(Nan::New("Vec").ToLocalChecked());
|
45 | 60 | Nan::Set(target,Nan::New("Vec").ToLocalChecked(), FF::getFunction(ctor));
|
46 | 61 | Nan::Set(target,Nan::New("Vec2").ToLocalChecked(), FF::getFunction(ctor));
|
47 | 62 | Nan::Set(target,Nan::New("Vec3").ToLocalChecked(), FF::getFunction(ctor));
|
48 | 63 | Nan::Set(target,Nan::New("Vec4").ToLocalChecked(), FF::getFunction(ctor));
|
| 64 | + Nan::Set(target,Nan::New("Vec6").ToLocalChecked(), FF::getFunction(ctor)); |
49 | 65 | };
|
50 | 66 |
|
51 | 67 | NAN_METHOD(Vec::New) {
|
52 | 68 | FF::TryCatch tryCatch("Vec::New");
|
53 | 69 | FF_ASSERT_CONSTRUCT_CALL();
|
54 |
| - if (info.Length() < 2) { |
55 |
| - return tryCatch.throwError("Vec::New - expected arguments (w), x, y, (z)"); |
| 70 | + if (info.Length() < 2 || info.Length() > 6 || info.Length() == 5) { |
| 71 | + return tryCatch.throwError("Vec::New - expected arguments (u, v), (w), x, y, (z)"); |
56 | 72 | }
|
57 | 73 | v8::Local<v8::Object> jsVec;
|
58 |
| - if (info.Length() == 4) { |
59 |
| - jsVec = FF::newInstance(Nan::New(Vec4::constructor)); |
60 |
| - Nan::ObjectWrap::Unwrap<Vec4>(jsVec)->self = cv::Vec4d( |
61 |
| - info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
62 |
| - info[1]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
63 |
| - info[2]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
64 |
| - info[3]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value() |
65 |
| - ); |
66 |
| - } else { |
67 |
| - double x = info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(); |
68 |
| - double y = info[1]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(); |
69 |
| - if (info.Length() == 3) { |
70 |
| - double z = info[2]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(); |
71 |
| - jsVec = FF::newInstance(Nan::New(Vec3::constructor)); |
72 |
| - Nan::ObjectWrap::Unwrap<Vec3>(jsVec)->self = cv::Vec3d(x, y, z); |
73 |
| - } |
74 |
| - else { |
| 74 | + |
| 75 | + switch(info.Length()) { |
| 76 | + case 2: |
75 | 77 | jsVec = FF::newInstance(Nan::New(Vec2::constructor));
|
76 |
| - Nan::ObjectWrap::Unwrap<Vec2>(jsVec)->self = cv::Vec2d(x, y); |
77 |
| - } |
| 78 | + Nan::ObjectWrap::Unwrap<Vec2>(jsVec)->self = cv::Vec2d( |
| 79 | + info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 80 | + info[1]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value() |
| 81 | + ); |
| 82 | + break; |
| 83 | + case 3: |
| 84 | + jsVec = FF::newInstance(Nan::New(Vec3::constructor)); |
| 85 | + Nan::ObjectWrap::Unwrap<Vec3>(jsVec)->self = cv::Vec3d( |
| 86 | + info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 87 | + info[1]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 88 | + info[2]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value() |
| 89 | + ); |
| 90 | + break; |
| 91 | + case 4: |
| 92 | + jsVec = FF::newInstance(Nan::New(Vec4::constructor)); |
| 93 | + Nan::ObjectWrap::Unwrap<Vec4>(jsVec)->self = cv::Vec4d( |
| 94 | + info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 95 | + info[1]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 96 | + info[2]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 97 | + info[3]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value() |
| 98 | + ); |
| 99 | + break; |
| 100 | + case 6: |
| 101 | + jsVec = FF::newInstance(Nan::New(Vec6::constructor)); |
| 102 | + Nan::ObjectWrap::Unwrap<Vec6>(jsVec)->self = cv::Vec6d( |
| 103 | + info[0]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 104 | + info[1]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 105 | + info[2]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 106 | + info[3]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 107 | + info[4]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value(), |
| 108 | + info[5]->ToNumber(Nan::GetCurrentContext()).ToLocalChecked()->Value() |
| 109 | + ); |
| 110 | + break; |
78 | 111 | }
|
79 | 112 | info.GetReturnValue().Set(jsVec);
|
80 | 113 | }
|
0 commit comments