1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
21 //
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
25 //
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #include "test_precomp.hpp"
43
44 using namespace cv;
45 using namespace std;
46
47 class Core_RotatedRectConstructorTest : public cvtest::BaseTest
48 {
49 public:
50 Core_RotatedRectConstructorTest();
51 protected:
52 int prepare_test_case( int );
53 void run_func();
54 int validate_test_results( int );
55 float MAX_COORD_VAL;
56 Point2f a, b, c;
57 RotatedRect rec;
58 };
59
Core_RotatedRectConstructorTest()60 Core_RotatedRectConstructorTest::Core_RotatedRectConstructorTest()
61 {
62 test_case_count = 100;
63 MAX_COORD_VAL = 1000.0f;
64 }
65
prepare_test_case(int test_case_idx)66 int Core_RotatedRectConstructorTest::prepare_test_case( int test_case_idx )
67 {
68 cvtest::BaseTest::prepare_test_case( test_case_idx );
69 RNG& rng = ts->get_rng();
70 a = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );
71 do
72 {
73 b = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );
74 }
75 while( norm(a - b) <= FLT_EPSILON );
76 Vec2f along(a - b);
77 Vec2f perp = Vec2f(-along[1], along[0]);
78 double d = (double) rng.uniform(1.0f, 5.0f);
79 if( cvtest::randInt(rng) % 2 == 0 ) d = -d;
80 c = Point2f( (float) ((double) b.x + d * perp[0]), (float) ((double) b.y + d * perp[1]) );
81 return 1;
82 }
83
run_func()84 void Core_RotatedRectConstructorTest::run_func()
85 {
86 rec = RotatedRect(a, b, c);
87 }
88
validate_test_results(int)89 int Core_RotatedRectConstructorTest::validate_test_results( int )
90 {
91 Point2f vertices[4];
92 rec.points(vertices);
93 int count_match = 0;
94 for( int i = 0; i < 4; i++ )
95 {
96 if( norm(vertices[i] - a) <= 0.001 ) count_match++;
97 else if( norm(vertices[i] - b) <= 0.001 ) count_match++;
98 else if( norm(vertices[i] - c) <= 0.001 ) count_match++;
99 }
100 if( count_match == 3 )
101 return cvtest::TS::OK;
102 ts->printf( cvtest::TS::LOG, "RotatedRect end points don't match those supplied in constructor");
103 ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
104 return cvtest::TS::OK;
105 }
106
TEST(Core_RotatedRect,three_point_constructor)107 TEST(Core_RotatedRect, three_point_constructor) { Core_RotatedRectConstructorTest test; test.safe_run(); }
108