// //////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2013, OpenCV Foundation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//3940// //////////////////////////////////////////////////////////////////////////////////////41// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu42//43// LICENSE AGREEMENT44// Copyright (c) 2015 The Regents of the University of California (Regents)45//46// Redistribution and use in source and binary forms, with or without47// modification, are permitted provided that the following conditions are met:48// 1. Redistributions of source code must retain the above copyright49// notice, this list of conditions and the following disclaimer.50// 2. Redistributions in binary form must reproduce the above copyright51// notice, this list of conditions and the following disclaimer in the52// documentation and/or other materials provided with the distribution.53// 3. Neither the name of the University nor the54// names of its contributors may be used to endorse or promote products55// derived from this software without specific prior written permission.56//57// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY58// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED59// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE60// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY61// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES62// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;63// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND64// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT65// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS66// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.67//6869if (typeof module !== 'undefined' && module.exports) {70// The envrionment is Node.js71var cv = require('./opencv.js'); // eslint-disable-line no-var72}73QUnit.module('Utils', {});74QUnit.test('Test vectors', function(assert) {75{76let pointVector = new cv.PointVector();77for (let i=0; i<100; ++i) {78pointVector.push_back({x: i, y: 2*i});79}8081assert.equal(pointVector.size(), 100);8283let index = 10;84let item = pointVector.get(index);85assert.equal(item.x, index);86assert.equal(item.y, 2*index);8788index = 0;89item = pointVector.get(index);90assert.equal(item.x, index);91assert.equal(item.y, 2*index);9293index = 99;94item = pointVector.get(index);95assert.equal(item.x, index);96assert.equal(item.y, 2*index);9798pointVector.delete();99}100101{102let pointVector = new cv.PointVector();103for (let i=0; i<100; ++i) {104pointVector.push_back(new cv.Point(i, 2*i));105}106107pointVector.push_back(new cv.Point());108109assert.equal(pointVector.size(), 101);110111let index = 10;112let item = pointVector.get(index);113assert.equal(item.x, index);114assert.equal(item.y, 2*index);115116index = 0;117item = pointVector.get(index);118assert.equal(item.x, index);119assert.equal(item.y, 2*index);120121index = 99;122item = pointVector.get(index);123assert.equal(item.x, index);124assert.equal(item.y, 2*index);125126index = 100;127item = pointVector.get(index);128assert.equal(item.x, 0);129assert.equal(item.y, 0);130131pointVector.delete();132}133});134QUnit.test('Test Rect', function(assert) {135let rectVector = new cv.RectVector();136let rect = {x: 1, y: 2, width: 3, height: 4};137rectVector.push_back(rect);138rectVector.push_back(new cv.Rect());139rectVector.push_back(new cv.Rect(rect));140rectVector.push_back(new cv.Rect({x: 5, y: 6}, {width: 7, height: 8}));141rectVector.push_back(new cv.Rect(9, 10, 11, 12));142143assert.equal(rectVector.size(), 5);144145let item = rectVector.get(0);146assert.equal(item.x, 1);147assert.equal(item.y, 2);148assert.equal(item.width, 3);149assert.equal(item.height, 4);150151item = rectVector.get(1);152assert.equal(item.x, 0);153assert.equal(item.y, 0);154assert.equal(item.width, 0);155assert.equal(item.height, 0);156157item = rectVector.get(2);158assert.equal(item.x, 1);159assert.equal(item.y, 2);160assert.equal(item.width, 3);161assert.equal(item.height, 4);162163item = rectVector.get(3);164assert.equal(item.x, 5);165assert.equal(item.y, 6);166assert.equal(item.width, 7);167assert.equal(item.height, 8);168169item = rectVector.get(4);170assert.equal(item.x, 9);171assert.equal(item.y, 10);172assert.equal(item.width, 11);173assert.equal(item.height, 12);174175rectVector.delete();176});177QUnit.test('Test Size', function(assert) {178{179let mat = new cv.Mat();180mat.create({width: 5, height: 10}, cv.CV_8UC4);181let size = mat.size();182183assert.ok(mat.type() === cv.CV_8UC4);184assert.ok(size.height === 10);185assert.ok(size.width === 5);186assert.ok(mat.channels() === 4);187188mat.delete();189}190191{192let mat = new cv.Mat();193mat.create(new cv.Size(5, 10), cv.CV_8UC4);194let size = mat.size();195196assert.ok(mat.type() === cv.CV_8UC4);197assert.ok(size.height === 10);198assert.ok(size.width === 5);199assert.ok(mat.channels() === 4);200201mat.delete();202}203});204205206QUnit.test('test_rotated_rect', function(assert) {207{208let rect = {center: {x: 100, y: 100}, size: {height: 100, width: 50}, angle: 30};209210assert.equal(rect.center.x, 100);211assert.equal(rect.center.y, 100);212assert.equal(rect.angle, 30);213assert.equal(rect.size.height, 100);214assert.equal(rect.size.width, 50);215}216217{218let rect = new cv.RotatedRect();219220assert.equal(rect.center.x, 0);221assert.equal(rect.center.y, 0);222assert.equal(rect.angle, 0);223assert.equal(rect.size.height, 0);224assert.equal(rect.size.width, 0);225226let points = cv.RotatedRect.points(rect);227228assert.equal(points[0].x, 0);229assert.equal(points[0].y, 0);230assert.equal(points[1].x, 0);231assert.equal(points[1].y, 0);232assert.equal(points[2].x, 0);233assert.equal(points[2].y, 0);234assert.equal(points[3].x, 0);235assert.equal(points[3].y, 0);236}237238{239let rect = new cv.RotatedRect({x: 100, y: 100}, {height: 100, width: 50}, 30);240241assert.equal(rect.center.x, 100);242assert.equal(rect.center.y, 100);243assert.equal(rect.angle, 30);244assert.equal(rect.size.height, 100);245assert.equal(rect.size.width, 50);246247let points = cv.RotatedRect.points(rect);248249assert.equal(points[0].x, cv.RotatedRect.boundingRect2f(rect).x);250assert.equal(points[1].y, cv.RotatedRect.boundingRect2f(rect).y);251}252});253254255