Skip to content

Commit 13ff006

Browse files
remove some unused code and macros + remove .only from floodfill test
1 parent a2443f5 commit 13ff006

File tree

7 files changed

+27
-55
lines changed

7 files changed

+27
-55
lines changed

cc/core/Mat.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ NAN_METHOD(Mat::New) {
119119
cv::Mat channelMat = FF_UNWRAP_MAT_AND_GET(jsChannelMat);
120120
channels.push_back(channelMat);
121121
if (i > 0) {
122-
FF_ASSERT_EQUALS(channels.at(i - 1).rows, channelMat.rows, "Mat::New - rows", " at channel " + std::to_string(i));
123-
FF_ASSERT_EQUALS(channels.at(i - 1).cols, channelMat.cols, "Mat::New - cols", " at channel " + std::to_string(i));
122+
if (channels.at(i - 1).rows != channelMat.rows) {
123+
return Nan::ThrowError(FF_NEW_STRING("Mat::New - rows "
124+
+ std::to_string(channels.at(i - 1).rows) + ", have " + std::to_string(channelMat.rows)
125+
+ " at channel " + std::to_string(i)));
126+
}
127+
if (channels.at(i - 1).cols != channelMat.cols) {
128+
return Nan::ThrowError(FF_NEW_STRING("Mat::New - cols "
129+
+ std::to_string(channels.at(i - 1).cols) + ", have " + std::to_string(channelMat.rows)
130+
+ " at channel " + std::to_string(i)));
131+
}
124132
}
125133
}
126134
cv::Mat mat;

cc/core/core.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ NAN_METHOD(Core::Partition) {
8484
}
8585

8686
FF_OBJ ret = FF_NEW_OBJ();
87-
Nan::Set(ret, FF_NEW_STRING("labels"), FF::stdVecToJSArray<int>(labels));
87+
Nan::Set(ret, FF_NEW_STRING("labels"), IntArrayConverter::wrap(labels));
8888
Nan::Set(ret, FF_NEW_STRING("numLabels"), Nan::New(numLabels));
8989
FF_RETURN(ret);
9090
}

cc/macros.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@
2121
#define FF_SET_CV_CONSTANT(obj, cvConstant) \
2222
FF_SET_JS_PROP(obj, cvConstant, Nan::New<v8::Integer>(cvConstant));
2323

24-
#define FF_ASSERT_EQUALS(expected, have, what, atmsg) \
25-
if (expected != have) { \
26-
return Nan::ThrowError(FF_NEW_STRING(std::string(what) + " mismatch, expected " \
27-
+ std::to_string(expected) + ", have " + std::to_string(have) + atmsg)); \
28-
}
29-
30-
#define FF_GET_JSARR_REQUIRED_WITH_LENGTH(args, var, prop, length) \
31-
FF_GET_ARRAY_REQUIRED(args, var, #prop) \
32-
if (!var->Length() == length) { \
33-
return Nan::ThrowError(FF_NEW_STRING("expected " \
34-
+ std::string(#prop) + "to be an array of length " \
35-
+ std::to_string(length))); \
36-
}
37-
3824
#define FF_REQUIRE_INSTANCE(objCtor, obj, err) \
3925
if (!FF_IS_INSTANCE(objCtor, obj)) { \
4026
return Nan::ThrowError(err); \
@@ -43,10 +29,6 @@
4329
#define FF_GET_UNPACK_UCHAR_ARRAY_IFDEF(ff_obj, ff_var, ff_prop, ff_defaultValue) FF_GET_UNPACK_ARRAY_IFDEF(ff_obj, ff_var, ff_prop, uchar, ff_uint, ff_defaultValue)
4430
#define FF_ARG_UNPACK_UCHAR_ARRAY_TO_IFDEF(ff_argN, ff_var, ff_defaultValue) FF_ARG_UNPACK_ARRAY_TO_IFDEF(ff_argN, ff_var, ff_uint, ff_defaultValue)
4531

46-
#define FF_ARG_UNPACK_FLOAT_ARRAY(ff_argN, ff_var) FF_ARG_UNPACK_ARRAY(ff_argN, ff_var, float, ff_number);
47-
#define FF_GET_UNPACK_FLOAT_ARRAY_IFDEF(ff_obj, ff_var, ff_prop, ff_defaultValue) FF_GET_UNPACK_ARRAY_IFDEF(ff_obj, ff_var, ff_prop, float, ff_number, ff_defaultValue)
48-
#define FF_ARG_UNPACK_FLOAT_ARRAY_TO_IFDEF(ff_argN, ff_var, ff_defaultValue) FF_ARG_UNPACK_ARRAY_TO_IFDEF(ff_argN, ff_var, ff_number, ff_defaultValue)
49-
5032
/* unwrappers */
5133

5234
#define FF_UNWRAP(obj, clazz) Nan::ObjectWrap::Unwrap<clazz>(obj)
@@ -84,9 +66,6 @@
8466
#define FF_UNWRAP_TRAINDATA(obj) FF_UNWRAP(obj, TrainData)
8567
#define FF_UNWRAP_TRAINDATA_AND_GET(obj) FF_UNWRAP_TRAINDATA(obj)->trainData
8668

87-
#define FF_UNWRAP_PARAMGRID(obj) FF_UNWRAP(obj, ParamGrid)
88-
#define FF_UNWRAP_PARAMGRID_AND_GET(obj) FF_UNWRAP_PARAMGRID(obj)->paramGrid
89-
9069
#define FF_UNWRAP_TERMCRITERA(obj) FF_UNWRAP(obj, TermCriteria)
9170
#define FF_UNWRAP_TERMCRITERA_AND_GET(obj) FF_UNWRAP_TERMCRITERA(obj)->termCriteria
9271

@@ -97,19 +76,7 @@ struct FF_TYPE(FUNC, v8::Local<v8::Function>, FF_IS_FUNC, FF_CAST_FUNC);
9776
static FF_FUNC_TYPE ff_func = FF_FUNC_TYPE();
9877
#define FF_ARG_FUNC(argN, var) FF_ARG(argN, var, ff_func)
9978

100-
#define FF_ARG_IFDEF_NOT_FUNC(argN, ff_arg_getter) \
101-
if (FF_HAS_ARG(argN) && !FF_IS_FUNC(info[argN])) { \
102-
ff_arg_getter \
103-
}
104-
105-
#define FF_ARG_UINT_IFDEF_NOT_FUNC(argN, ff_var, ff_default) \
106-
FF_ARG_IFDEF_NOT_FUNC(argN, FF_ARG_UINT_IFDEF(argN, ff_var, ff_default))
107-
108-
#define FF_ARG_BOOL_IFDEF_NOT_FUNC(argN, ff_var, ff_default) \
109-
FF_ARG_IFDEF_NOT_FUNC(argN, FF_ARG_BOOL_IFDEF(argN, ff_var, ff_default))
110-
111-
#define FF_ARG_IS_OBJECT(argN) \
112-
FF_HAS_ARG(argN) && info[argN]->IsObject() && !info[argN]->IsArray() && !info[argN]->IsFunction()
79+
#define FF_ARG_IS_OBJECT(argN) FF_HAS_ARG(argN) && info[argN]->IsObject() && !info[argN]->IsArray() && !info[argN]->IsFunction()
11380

11481
/* for setters */
11582
#define FF_REQUIRE_VALUE(ff_value, ff_type) \
@@ -129,15 +96,4 @@ static FF_FUNC_TYPE ff_func = FF_FUNC_TYPE();
12996
#define FF_SETTER_NUMBER(clazz, name, prop) FF_SETTER(clazz, name, prop, ff_number)
13097
#define FF_SETTER_BOOL(clazz, name, prop) FF_SETTER(clazz, name, prop, ff_bool)
13198

132-
namespace FF {
133-
template<typename toType, typename type>
134-
static inline v8::Local<v8::Array> stdVecToJSArray(std::vector<type> vec) {
135-
v8::Local<v8::Array> jsArray = Nan::New<v8::Array>(vec.size());
136-
for (int i = 0; i < jsArray->Length(); i++) {
137-
jsArray->Set(i, Nan::New((toType)vec.at(i)));
138-
}
139-
return jsArray;
140-
}
141-
}
142-
14399
#endif

cc/modules/imgproc/imgproc.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ NAN_METHOD(Imgproc::CalcHist) {
123123
ranges.push_back(new float[dims]);
124124
FF_OBJ jsAxis = FF_CAST_OBJ(jsHistAxes->Get(i));
125125
FF_ARR jsRanges;
126-
FF_GET_JSARR_REQUIRED_WITH_LENGTH(jsAxis, jsRanges, ranges, 2);
126+
127+
if (!jsRanges->Length() == 2) {
128+
return Nan::ThrowError(FF_NEW_STRING("expected ranges to be an array of length " + std::to_string(2)));
129+
}
127130
ranges.at(i)[0] = jsRanges->Get(0)->NumberValue();
128131
ranges.at(i)[1] = jsRanges->Get(1)->NumberValue();
129132
int channel, bins;
@@ -168,8 +171,11 @@ NAN_METHOD(Imgproc::Plot1DHist) {
168171

169172
FF_ARG_INSTANCE(0, cv::Mat hist, Mat::constructor, FF_UNWRAP_MAT_AND_GET);
170173
FF_ARG_INSTANCE(1, cv::Mat plot, Mat::constructor, FF_UNWRAP_MAT_AND_GET);
171-
FF_ARG_INSTANCE(2, cv::Vec3d color, Vec3::constructor, FF_UNWRAP_VEC3_AND_GET);
172-
FF_ASSERT_EQUALS(1, hist.cols, "Plot1DHist - hist rows", "");
174+
FF_ARG_INSTANCE(2, cv::Vec3d color, Vec3::constructor, FF_UNWRAP_VEC3_AND_GET);
175+
if (1 != hist.cols) {
176+
return Nan::ThrowError(FF_NEW_STRING("Plot1DHist - hist rows mismatch, expected "
177+
+ std::to_string(1) + ", have " + std::to_string(hist.cols)));
178+
}
173179
if (hist.channels() != 1) {
174180
FF_THROW("expected hist to be single channeled");
175181
}

cc/modules/machinelearning/SVM.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ NAN_METHOD(SVM::Predict) {
9898

9999
cv::Mat results;
100100
if (info[0]->IsArray()) {
101-
FF_ARG_UNPACK_FLOAT_ARRAY(0, samples);
101+
std::vector<float> samples;
102+
FloatArrayConverter::arg(0, &samples, info);
102103
FF_ARG_UINT_IFDEF(1, unsigned int flags, 0);
103104
FF_UNWRAP(info.This(), SVM)->svm->predict(samples, results, (int)flags);
104105
}

cc/modules/machinelearning/TrainData.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ NAN_METHOD(TrainData::New) {
3333
FF_OBJ optArgs = hasOptArgsObj ? info[3]->ToObject() : FF_NEW_OBJ();
3434
FF_GET_UNPACK_INT_ARRAY_IFDEF(optArgs, varIdx, "varIdx", varIdx);
3535
FF_GET_UNPACK_INT_ARRAY_IFDEF(optArgs, sampleIdx, "sampleIdx", sampleIdx);
36-
FF_GET_UNPACK_FLOAT_ARRAY_IFDEF(optArgs, sampleWeights, "sampleWeights", sampleWeights);
36+
std::vector<float> sampleWeights;
37+
FloatArrayConverter::optProp(&sampleWeights, "sampleWeights", optArgs);
3738
FF_GET_UNPACK_UCHAR_ARRAY_IFDEF(optArgs, varType, "varType", varType);
3839
if (!hasOptArgsObj) {
3940
FF_ARG_UNPACK_INT_ARRAY_TO_IFDEF(3, varIdx, varIdx);
4041
FF_ARG_UNPACK_INT_ARRAY_TO_IFDEF(4, sampleIdx, sampleIdx);
41-
FF_ARG_UNPACK_FLOAT_ARRAY_TO_IFDEF(5, sampleWeights, sampleWeights);
42+
FloatArrayConverter::optArg(5, &sampleWeights, info);
4243
FF_ARG_UNPACK_UCHAR_ARRAY_TO_IFDEF(6, varType, varType);
4344
}
4445

test/tests/core/Mat/imgprocTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ module.exports = (getTestImg) => {
12411241
});
12421242
});
12431243

1244-
describe.only('floodFill', () => {
1244+
describe('floodFill', () => {
12451245
const expectOutput = (out) => {
12461246
expect(!!out).to.be.true;
12471247
expect(out).to.have.property('returnValue').to.be.a('number');

0 commit comments

Comments
 (0)