1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "sal/config.h"
#include "sal/precppunit.hxx"
// autogenerated file with codegen.pl
#include "cppunit/TestAssert.h"
#include "cppunit/TestFixture.h"
#include "cppunit/extensions/HelperMacros.h"
#include <basegfx/tools/b2dclipstate.hxx>
#include <basegfx/range/b2dpolyrange.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <boost/bind.hpp>
using namespace ::basegfx;
namespace basegfx2d
{
class clipstate : public CppUnit::TestFixture
{
private:
tools::B2DClipState aUnion1;
tools::B2DClipState aUnion2;
tools::B2DClipState aIntersect;
tools::B2DClipState aXor;
tools::B2DClipState aSubtract;
public:
void setUp()
{
B2DRange aCenter(100, 100, -100, -100);
B2DRange aNorth(-10, -110, 10, -90);
B2DRange aWest(-110, -10, -90, 10);
B2DRange aSouth(-10, 110, 10, 90);
B2DRange aEast(110, -10, 90, 10);
aUnion1.unionRange(aCenter);
aUnion1.unionRange(aNorth);
aUnion1.unionRange(aWest);
aUnion1.unionRange(aSouth);
aUnion1.unionRange(aEast);
aUnion2.makeNull();
aUnion2.unionRange(aCenter);
aUnion2.unionRange(aNorth);
aUnion2.unionRange(aWest);
aUnion2.unionRange(aSouth);
aUnion2.unionRange(aEast);
aIntersect.intersectRange(aCenter);
aIntersect.intersectRange(aNorth);
aIntersect.intersectRange(aWest);
aIntersect.intersectRange(aSouth);
aIntersect.intersectRange(aEast);
aXor.makeNull();
aXor.xorRange(aCenter);
aXor.xorRange(aNorth);
aXor.xorRange(aWest);
aXor.xorRange(aSouth);
aXor.xorRange(aEast);
aSubtract.intersectRange(aCenter);
aSubtract.subtractRange(aNorth);
aSubtract.subtractRange(aWest);
aSubtract.subtractRange(aSouth);
aSubtract.subtractRange(aEast);
}
void tearDown()
{}
void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest)
{
#if defined(VERBOSE)
fprintf(stderr, "%s - svg:d=\"%s\"\n",
sName, rtl::OUStringToOString(
basegfx::tools::exportToSvgD(toTest.getClipPoly()),
RTL_TEXTENCODING_UTF8).getStr() );
#endif
B2DPolyPolygon aTmp1;
CPPUNIT_ASSERT_MESSAGE(sName,
tools::importFromSvgD(
aTmp1,
rtl::OUString::createFromAscii(sSvg)));
const rtl::OUString aSvg=
tools::exportToSvgD(toTest.getClipPoly());
B2DPolyPolygon aTmp2;
CPPUNIT_ASSERT_MESSAGE(sName,
tools::importFromSvgD(
aTmp2,
aSvg));
CPPUNIT_ASSERT_MESSAGE(
sName,
aTmp2 == aTmp1);
}
void verifySimpleRange()
{
const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
const char* intersectSvg="m-100 10v-20h10v20zm90 90v-10h20v10zm0-190v-10h20v10zm100 100v-20h10v20z";
const char* xorSvg="m-100 10h10v-20h-10zm90 90h20v-10h-20zm0-190h20v-10h-20zm100 100h10v-20h-10z"
"m10 0v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z";
CPPUNIT_ASSERT_MESSAGE("cleared clip stays empty under union operation",
aUnion1.isCleared());
verifyPoly("union", unionSvg, aUnion2);
verifyPoly("intersect", intersectSvg, aIntersect);
verifyPoly("xor", xorSvg, aXor);
verifyPoly("subtract", subtractSvg, aSubtract);
}
void verifyMixedClips()
{
tools::B2DClipState aMixedClip;
const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z";
B2DPolyPolygon aTmp1;
tools::importFromSvgD(
aTmp1,
rtl::OUString::createFromAscii(unionSvg));
aMixedClip.intersectPolyPolygon(aTmp1);
aMixedClip.subtractRange(B2DRange(-20,-150,20,0));
aMixedClip.subtractRange(B2DRange(-150,-20,0,20));
aMixedClip.xorRange(B2DRange(-150,-150,150,150));
const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-20-20v-80h-80v80zm-130 170v-300h300v300z";
verifyPoly("mixed clip", mixedClipSvg, aMixedClip);
}
CPPUNIT_TEST_SUITE(clipstate);
CPPUNIT_TEST(verifySimpleRange);
CPPUNIT_TEST(verifyMixedClips);
CPPUNIT_TEST_SUITE_END();
};
// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::clipstate);
} // namespace basegfx2d
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|