Path: blob/master/modules/core/test/test_rotatedrect.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////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// Intel License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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//39//M*/4041#include "test_precomp.hpp"4243namespace opencv_test { namespace {4445class Core_RotatedRectConstructorTest : public cvtest::BaseTest46{47public:48Core_RotatedRectConstructorTest();49protected:50int prepare_test_case( int );51void run_func();52int validate_test_results( int );53float MAX_COORD_VAL;54Point2f a, b, c;55RotatedRect rec;56};5758Core_RotatedRectConstructorTest::Core_RotatedRectConstructorTest()59{60test_case_count = 100;61MAX_COORD_VAL = 1000.0f;62}6364int Core_RotatedRectConstructorTest::prepare_test_case( int test_case_idx )65{66cvtest::BaseTest::prepare_test_case( test_case_idx );67RNG& rng = ts->get_rng();68a = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );69do70{71b = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );72}73while( cv::norm(a - b) <= FLT_EPSILON );74Vec2f along(a - b);75Vec2f perp = Vec2f(-along[1], along[0]);76double d = (double) rng.uniform(1.0f, 5.0f);77if( cvtest::randInt(rng) % 2 == 0 ) d = -d;78c = Point2f( (float) ((double) b.x + d * perp[0]), (float) ((double) b.y + d * perp[1]) );79return 1;80}8182void Core_RotatedRectConstructorTest::run_func()83{84rec = RotatedRect(a, b, c);85}8687int Core_RotatedRectConstructorTest::validate_test_results( int )88{89Point2f vertices[4];90rec.points(vertices);91int count_match = 0;92for( int i = 0; i < 4; i++ )93{94if( cv::norm(vertices[i] - a) <= 0.001 ) count_match++;95else if( cv::norm(vertices[i] - b) <= 0.001 ) count_match++;96else if( cv::norm(vertices[i] - c) <= 0.001 ) count_match++;97}98if( count_match == 3 )99return cvtest::TS::OK;100ts->printf( cvtest::TS::LOG, "RotatedRect end points don't match those supplied in constructor");101ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );102return cvtest::TS::OK;103}104105TEST(Core_RotatedRect, three_point_constructor) { Core_RotatedRectConstructorTest test; test.safe_run(); }106107}} // namespace108109110