1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestFixture.h>
21 #include <cppunit/extensions/HelperMacros.h>
22 #include <basegfx/point/b2dpoint.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
27 class B2DPointTest
: public CppUnit::TestFixture
32 void testTimesEquals();
34 void testAssignment();
35 void testGetEmptyPoint();
36 void testOutputOperator();
38 CPPUNIT_TEST_SUITE(B2DPointTest
);
39 CPPUNIT_TEST(testCreation
);
40 CPPUNIT_TEST(testSet
);
41 CPPUNIT_TEST(testTimesEquals
);
42 CPPUNIT_TEST(testMultipy
);
43 CPPUNIT_TEST(testAssignment
);
44 CPPUNIT_TEST(testGetEmptyPoint
);
45 CPPUNIT_TEST(testOutputOperator
);
46 CPPUNIT_TEST_SUITE_END();
49 void B2DPointTest::testCreation()
51 basegfx::B2DPoint aPointDefault
;
52 CPPUNIT_ASSERT_EQUAL(0.0, aPointDefault
.getX());
53 CPPUNIT_ASSERT_EQUAL(0.0, aPointDefault
.getY());
55 basegfx::B2DPoint
aPoint1(5.0, 2.0);
56 CPPUNIT_ASSERT_EQUAL(5.0, aPoint1
.getX());
57 CPPUNIT_ASSERT_EQUAL(2.0, aPoint1
.getY());
59 basegfx::B2DPoint
aPointCopy(aPoint1
);
60 CPPUNIT_ASSERT_EQUAL(5.0, aPointCopy
.getX());
61 CPPUNIT_ASSERT_EQUAL(2.0, aPointCopy
.getY());
63 basegfx::B2DPoint aPoint2
= { 5.0, 2.0 };
64 CPPUNIT_ASSERT_EQUAL(5.0, aPoint2
.getX());
65 CPPUNIT_ASSERT_EQUAL(2.0, aPoint2
.getY());
67 basegfx::B2IPoint
aPointI1(1, 2);
68 basegfx::B2DPoint
aPointFromI(aPointI1
);
69 CPPUNIT_ASSERT_EQUAL(1.0, aPointFromI
.getX());
70 CPPUNIT_ASSERT_EQUAL(2.0, aPointFromI
.getY());
72 basegfx::B2DTuple
aTuple(3.5, 4.5);
73 basegfx::B2DPoint
aPointFromTuple(aTuple
);
74 CPPUNIT_ASSERT_EQUAL(3.5, aPointFromTuple
.getX());
75 CPPUNIT_ASSERT_EQUAL(4.5, aPointFromTuple
.getY());
77 std::vector
<basegfx::B2DPoint
> aPointVector
{
81 CPPUNIT_ASSERT_EQUAL(5.0, aPointVector
[0].getX());
82 CPPUNIT_ASSERT_EQUAL(2.0, aPointVector
[0].getY());
83 CPPUNIT_ASSERT_EQUAL(4.0, aPointVector
[1].getX());
84 CPPUNIT_ASSERT_EQUAL(3.0, aPointVector
[1].getY());
87 void B2DPointTest::testSet()
89 basegfx::B2DPoint aPoint
;
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.1, aPoint
.getX(), 0.0000001);
93 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.2, aPoint
.getY(), 0.0000001);
96 void B2DPointTest::testTimesEquals()
98 basegfx::B2DPoint
aPoint1(1.1, 2.2);
99 basegfx::B2DPoint
aPoint2(3.0, 4.0);
101 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.3, aPoint1
.getX(), 0.0000001);
102 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.8, aPoint1
.getY(), 0.0000001);
105 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.5, aPoint2
.getX(), 0.0000001);
106 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aPoint2
.getY(), 0.0000001);
108 basegfx::B2DHomMatrix aMatrix
;
111 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.3, aPoint1
.getX(), 0.0000001);
112 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.8, aPoint1
.getY(), 0.0000001);
114 aMatrix
.translate(1.0, 2.0);
116 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3, aPoint1
.getX(), 0.0000001);
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.8, aPoint1
.getY(), 0.0000001);
120 aMatrix
.rotate(-M_PI_4
);
124 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.0), aPoint1
.getX(), 0.0000001);
125 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aPoint1
.getY(), 0.0000001);
128 aMatrix
.translate(0.0, 1.0);
129 aMatrix
.rotate(M_PI_4
);
130 aMatrix
.scale(2.0, 2.0);
136 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.0), aPoint1
.getX(), 0.0000001);
137 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0 * sqrt(2.0), aPoint1
.getY(), 0.0000001);
139 void B2DPointTest::testMultipy()
141 basegfx::B2DPoint
aPoint(1, 2);
142 basegfx::B2DHomMatrix aMatrix
;
144 aMatrix
.rotate(M_PI
);
145 basegfx::B2DPoint aResult
= aMatrix
* aPoint
;
146 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1, aResult
.getX(), 0.0000001);
147 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2, aResult
.getY(), 0.0000001);
150 void B2DPointTest::testAssignment()
152 basegfx::B2DTuple
aTuple(2.5, 5.5);
153 basegfx::B2DPoint
aPoint(0, 0);
155 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.5, aPoint
.getX(), 0.0000001);
156 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.5, aPoint
.getY(), 0.0000001);
158 basegfx::B2DPoint
aPoint2(3.2, 6.2);
160 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.2, aPoint
.getX(), 0.0000001);
161 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.2, aPoint
.getY(), 0.0000001);
163 void B2DPointTest::testGetEmptyPoint()
165 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, basegfx::B2DPoint::getEmptyPoint().getX(), .0000001);
166 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, basegfx::B2DPoint::getEmptyPoint().getY(), .0000001);
169 void B2DPointTest::testOutputOperator()
171 std::ostringstream aOut
;
172 basegfx::B2DPoint
aPoint(2.0, 3.0);
174 std::string aResult
= aOut
.str();
175 CPPUNIT_ASSERT_EQUAL(std::string("(2,3)"), aResult
);
178 CPPUNIT_TEST_SUITE_REGISTRATION(B2DPointTest
);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */