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/vector/b2dsize.hxx>
24 #include <basegfx/matrix/b2dhommatrix.hxx>
28 class B2DPointTest
: public CppUnit::TestFixture
33 void testTimesEquals();
35 void testAssignment();
36 void testGetEmptyPoint();
37 void testOutputOperator();
40 CPPUNIT_TEST_SUITE(B2DPointTest
);
41 CPPUNIT_TEST(testCreation
);
42 CPPUNIT_TEST(testSet
);
43 CPPUNIT_TEST(testTimesEquals
);
44 CPPUNIT_TEST(testMultipy
);
45 CPPUNIT_TEST(testAssignment
);
46 CPPUNIT_TEST(testGetEmptyPoint
);
47 CPPUNIT_TEST(testOutputOperator
);
48 CPPUNIT_TEST(testOperators
);
49 CPPUNIT_TEST_SUITE_END();
52 void B2DPointTest::testCreation()
54 basegfx::B2DPoint aPointDefault
;
55 CPPUNIT_ASSERT_EQUAL(0.0, aPointDefault
.getX());
56 CPPUNIT_ASSERT_EQUAL(0.0, aPointDefault
.getY());
58 basegfx::B2DPoint
aPoint1(5.0, 2.0);
59 CPPUNIT_ASSERT_EQUAL(5.0, aPoint1
.getX());
60 CPPUNIT_ASSERT_EQUAL(2.0, aPoint1
.getY());
62 basegfx::B2DPoint
aPointCopy(aPoint1
);
63 CPPUNIT_ASSERT_EQUAL(5.0, aPointCopy
.getX());
64 CPPUNIT_ASSERT_EQUAL(2.0, aPointCopy
.getY());
66 basegfx::B2DPoint aPoint2
= { 5.0, 2.0 };
67 CPPUNIT_ASSERT_EQUAL(5.0, aPoint2
.getX());
68 CPPUNIT_ASSERT_EQUAL(2.0, aPoint2
.getY());
70 basegfx::B2IPoint
aPointI1(1, 2);
71 basegfx::B2DPoint
aPointFromI(aPointI1
);
72 CPPUNIT_ASSERT_EQUAL(1.0, aPointFromI
.getX());
73 CPPUNIT_ASSERT_EQUAL(2.0, aPointFromI
.getY());
75 basegfx::B2DTuple
aTuple(3.5, 4.5);
76 basegfx::B2DPoint
aPointFromTuple(aTuple
);
77 CPPUNIT_ASSERT_EQUAL(3.5, aPointFromTuple
.getX());
78 CPPUNIT_ASSERT_EQUAL(4.5, aPointFromTuple
.getY());
80 std::vector
<basegfx::B2DPoint
> aPointVector
{
84 CPPUNIT_ASSERT_EQUAL(5.0, aPointVector
[0].getX());
85 CPPUNIT_ASSERT_EQUAL(2.0, aPointVector
[0].getY());
86 CPPUNIT_ASSERT_EQUAL(4.0, aPointVector
[1].getX());
87 CPPUNIT_ASSERT_EQUAL(3.0, aPointVector
[1].getY());
90 void B2DPointTest::testSet()
92 basegfx::B2DPoint aPoint
;
95 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.1, aPoint
.getX(), 0.0000001);
96 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.2, aPoint
.getY(), 0.0000001);
99 void B2DPointTest::testTimesEquals()
101 basegfx::B2DPoint
aPoint1(1.1, 2.2);
102 basegfx::B2DPoint
aPoint2(3.0, 4.0);
104 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.3, aPoint1
.getX(), 0.0000001);
105 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.8, aPoint1
.getY(), 0.0000001);
108 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.5, aPoint2
.getX(), 0.0000001);
109 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aPoint2
.getY(), 0.0000001);
111 basegfx::B2DHomMatrix aMatrix
;
114 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.3, aPoint1
.getX(), 0.0000001);
115 CPPUNIT_ASSERT_DOUBLES_EQUAL(8.8, aPoint1
.getY(), 0.0000001);
117 aMatrix
.translate(1.0, 2.0);
119 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.3, aPoint1
.getX(), 0.0000001);
120 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.8, aPoint1
.getY(), 0.0000001);
123 aMatrix
.rotate(-M_PI_4
);
127 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.0), aPoint1
.getX(), 0.0000001);
128 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aPoint1
.getY(), 0.0000001);
131 aMatrix
.translate(0.0, 1.0);
132 aMatrix
.rotate(M_PI_4
);
133 aMatrix
.scale(2.0, 2.0);
139 CPPUNIT_ASSERT_DOUBLES_EQUAL(sqrt(2.0), aPoint1
.getX(), 0.0000001);
140 CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0 * sqrt(2.0), aPoint1
.getY(), 0.0000001);
142 void B2DPointTest::testMultipy()
144 basegfx::B2DPoint
aPoint(1, 2);
145 basegfx::B2DHomMatrix aMatrix
;
147 aMatrix
.rotate(M_PI
);
148 basegfx::B2DPoint aResult
= aMatrix
* aPoint
;
149 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1, aResult
.getX(), 0.0000001);
150 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2, aResult
.getY(), 0.0000001);
153 void B2DPointTest::testAssignment()
155 basegfx::B2DTuple
aTuple(2.5, 5.5);
156 basegfx::B2DPoint
aPoint(0, 0);
158 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.5, aPoint
.getX(), 0.0000001);
159 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.5, aPoint
.getY(), 0.0000001);
161 basegfx::B2DPoint
aPoint2(3.2, 6.2);
163 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.2, aPoint
.getX(), 0.0000001);
164 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.2, aPoint
.getY(), 0.0000001);
166 void B2DPointTest::testGetEmptyPoint()
168 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, basegfx::B2DPoint::getEmptyPoint().getX(), .0000001);
169 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, basegfx::B2DPoint::getEmptyPoint().getY(), .0000001);
172 void B2DPointTest::testOutputOperator()
174 std::ostringstream aOut
;
175 basegfx::B2DPoint
aPoint(2.0, 3.0);
177 std::string aResult
= aOut
.str();
178 CPPUNIT_ASSERT_EQUAL(std::string("(2,3)"), aResult
);
181 void B2DPointTest::testOperators()
183 basegfx::B2DPoint
aPoint(2.0, 3.0);
184 basegfx::B2DSize
aSize(1.0, 1.0);
186 CPPUNIT_ASSERT_EQUAL(true, basegfx::B2DPoint(3.0, 4.0) == aPoint
+ basegfx::B2DPoint(aSize
));
187 CPPUNIT_ASSERT_EQUAL(true, basegfx::B2DPoint(1.0, 2.0) == aPoint
- basegfx::B2DPoint(aSize
));
188 CPPUNIT_ASSERT_EQUAL(true, basegfx::B2DPoint(2.0, 3.0) == aPoint
* basegfx::B2DPoint(aSize
));
189 CPPUNIT_ASSERT_EQUAL(true, basegfx::B2DPoint(2.0, 3.0) == aPoint
/ basegfx::B2DPoint(aSize
));
192 CPPUNIT_TEST_SUITE_REGISTRATION(B2DPointTest
);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */