This source file includes following definitions.
- prepare_test_case
- run_func
- validate_test_results
- TEST
#include "test_precomp.hpp"
using namespace cv;
using namespace std;
class Core_RotatedRectConstructorTest : public cvtest::BaseTest
{
public:
Core_RotatedRectConstructorTest();
protected:
int prepare_test_case( int );
void run_func();
int validate_test_results( int );
float MAX_COORD_VAL;
Point2f a, b, c;
RotatedRect rec;
};
Core_RotatedRectConstructorTest::Core_RotatedRectConstructorTest()
{
test_case_count = 100;
MAX_COORD_VAL = 1000.0f;
}
int Core_RotatedRectConstructorTest::prepare_test_case( int test_case_idx )
{
cvtest::BaseTest::prepare_test_case( test_case_idx );
RNG& rng = ts->get_rng();
a = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );
do
{
b = Point2f( rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL), rng.uniform(-MAX_COORD_VAL, MAX_COORD_VAL) );
}
while( norm(a - b) <= FLT_EPSILON );
Vec2f along(a - b);
Vec2f perp = Vec2f(-along[1], along[0]);
double d = (double) rng.uniform(1.0f, 5.0f);
if( cvtest::randInt(rng) % 2 == 0 ) d = -d;
c = Point2f( (float) ((double) b.x + d * perp[0]), (float) ((double) b.y + d * perp[1]) );
return 1;
}
void Core_RotatedRectConstructorTest::run_func()
{
rec = RotatedRect(a, b, c);
}
int Core_RotatedRectConstructorTest::validate_test_results( int )
{
Point2f vertices[4];
rec.points(vertices);
int count_match = 0;
for( int i = 0; i < 4; i++ )
{
if( norm(vertices[i] - a) <= 0.001 ) count_match++;
else if( norm(vertices[i] - b) <= 0.001 ) count_match++;
else if( norm(vertices[i] - c) <= 0.001 ) count_match++;
}
if( count_match == 3 )
return cvtest::TS::OK;
ts->printf( cvtest::TS::LOG, "RotatedRect end points don't match those supplied in constructor");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
return cvtest::TS::OK;
}
TEST(Core_RotatedRect, three_point_constructor) { Core_RotatedRectConstructorTest test; test.safe_run(); }