2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-06-15 18:04:58 +00:00
|
|
|
// Unit tests for src/core/SkPoint.cpp and its header
|
|
|
|
|
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
// Tests that SkPoint::length() and SkPoint::Length() both return
|
|
|
|
// approximately expectedLength for this (x,y).
|
|
|
|
static void test_length(skiatest::Reporter* reporter, SkScalar x, SkScalar y,
|
|
|
|
SkScalar expectedLength) {
|
|
|
|
SkPoint point;
|
|
|
|
point.set(x, y);
|
|
|
|
SkScalar s1 = point.length();
|
|
|
|
SkScalar s2 = SkPoint::Length(x, y);
|
2012-08-24 19:53:58 +00:00
|
|
|
//The following should be exactly the same, but need not be.
|
2012-08-27 13:14:46 +00:00
|
|
|
//See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
|
2012-08-24 19:53:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, s2));
|
2011-06-15 18:04:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(s1, expectedLength));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests SkPoint::Normalize() for this (x,y)
|
|
|
|
static void test_Normalize(skiatest::Reporter* reporter,
|
|
|
|
SkScalar x, SkScalar y) {
|
|
|
|
SkPoint point;
|
|
|
|
point.set(x, y);
|
|
|
|
SkScalar oldLength = point.length();
|
|
|
|
SkScalar returned = SkPoint::Normalize(&point);
|
|
|
|
SkScalar newLength = point.length();
|
2012-08-24 19:53:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(returned, oldLength));
|
2011-06-15 18:04:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(newLength, SK_Scalar1));
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
static void PointTest(skiatest::Reporter* reporter) {
|
2011-06-15 18:04:58 +00:00
|
|
|
test_length(reporter, SkIntToScalar(3), SkIntToScalar(4), SkIntToScalar(5));
|
2012-04-10 17:42:21 +00:00
|
|
|
test_length(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f),
|
2011-06-15 18:04:58 +00:00
|
|
|
SK_Scalar1);
|
|
|
|
test_Normalize(reporter, SkIntToScalar(3), SkIntToScalar(4));
|
2012-04-10 17:42:21 +00:00
|
|
|
test_Normalize(reporter, SkFloatToScalar(0.6f), SkFloatToScalar(0.8f));
|
2011-06-15 18:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("Point", PointTestClass, PointTest)
|