Skip to content

Commit

Permalink
add subtract() to Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgal committed Apr 14, 2016
1 parent 7a50a5b commit bd56c36
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Matrix.cc
Expand Up @@ -109,6 +109,7 @@ void Matrix::Init(Local<Object> target) {
Nan::SetPrototypeMethod(ctor, "shift", Shift);
Nan::SetPrototypeMethod(ctor, "reshape", Reshape);
Nan::SetPrototypeMethod(ctor, "release", Release);
Nan::SetPrototypeMethod(ctor, "subtract", Subtract);

target->Set(Nan::New("Matrix").ToLocalChecked(), ctor->GetFunction());
};
Expand Down Expand Up @@ -2569,3 +2570,17 @@ NAN_METHOD(Matrix::Release) {

return;
}

NAN_METHOD(Matrix::Subtract) {
SETUP_FUNCTION(Matrix)

if (info.Length() < 1) {
Nan::ThrowTypeError("Invalid number of arguments");
}

Matrix *other = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());

self->mat -= other->mat;

return;
}
2 changes: 2 additions & 0 deletions src/Matrix.h
Expand Up @@ -125,6 +125,8 @@ class Matrix: public node_opencv::Matrix{
JSFUNC(Reshape)

JSFUNC(Release)

JSFUNC(Subtract)
/*
static Handle<Value> Val(const Arguments& info);
static Handle<Value> RowRange(const Arguments& info);
Expand Down
9 changes: 9 additions & 0 deletions test/unit.js
Expand Up @@ -341,6 +341,15 @@ test('Native Matrix', function(assert) {
assert.end();
})

test('Subtract', function(assert) {
var a = new cv.Matrix.Zeros(1,1);
a.set(0, 0, 3);
var b = new cv.Matrix.Zeros(1,1);
b.set(0, 0, 1);
a.subtract(b);
assert.deepEqual(a.get(0, 0), 2);
assert.end();
});

// Test the examples folder.
require('./examples')()
Expand Down

0 comments on commit bd56c36

Please sign in to comment.