diff options
author | thb <thb@openoffice.org> | 2009-10-16 00:57:35 +0200 |
---|---|---|
committer | thb <thb@openoffice.org> | 2009-10-16 00:57:35 +0200 |
commit | 7bae8837395d6f4ab80d01ee9525820ced425a51 (patch) | |
tree | 7ca2d26dc840c7d8ee2bcb1794e53837cd1cef08 /basegfx/test | |
parent | 8454c5ef5057d0d24e52fb9ed10483b598da98b0 (diff) |
#i105939# Adds clip state handling class to basegfx; makes use of that also from slideshow
Diffstat (limited to 'basegfx/test')
-rw-r--r-- | basegfx/test/basegfx2d.cxx | 6 | ||||
-rw-r--r-- | basegfx/test/clipstate.cxx | 187 | ||||
-rw-r--r-- | basegfx/test/genericclipper.cxx | 168 | ||||
-rw-r--r-- | basegfx/test/makefile.mk | 11 |
4 files changed, 368 insertions, 4 deletions
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx index 32128b927049..e30e6bf561c1 100644 --- a/basegfx/test/basegfx2d.cxx +++ b/basegfx/test/basegfx2d.cxx @@ -321,6 +321,12 @@ public: aRange.getElement(0).head == B2DRange(0,0,1,1)); CPPUNIT_ASSERT_MESSAGE("simple poly range - second element", aRange.getElement(1).head == B2DRange(2,2,3,3)); + + // B2DPolyRange relies on correctly orientated rects + const B2DRange aRect(0,0,1,1); + CPPUNIT_ASSERT_MESSAGE("createPolygonFromRect - correct orientation", + tools::getOrientation( + tools::createPolygonFromRect(aRect)) == ORIENTATION_POSITIVE ); } // Change the following lines only, if you add, remove or rename diff --git a/basegfx/test/clipstate.cxx b/basegfx/test/clipstate.cxx new file mode 100644 index 000000000000..38b18d57003f --- /dev/null +++ b/basegfx/test/clipstate.cxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: basegfx2d.cxx,v $ + * $Revision: 1.14 $ + * + * 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. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_basegfx.hxx" +// autogenerated file with codegen.pl + +#include <cppunit/simpleheader.hxx> + +#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-20h10v20zm80 90v-10h20v10zm-20-190v-10h20v10zm80 100v-20h10v20z"; + const char* xorSvg="m-100 10h10v-20h-10zm90 110h20v-10h-20zm0-180h20v-10h-20zm100 110h10v-20h-10zm10 20v90h-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-40-20v-80h-80v80zm-50 170v-300h300v300z"; + verifyPoly("mixed clip", mixedClipSvg, aMixedClip); + } + + CPPUNIT_TEST_SUITE(clipstate); + CPPUNIT_TEST(verifySimpleRange); + CPPUNIT_TEST(verifyMixedClips); + CPPUNIT_TEST_SUITE_END(); +}; + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(basegfx2d::clipstate, "clipstate"); +} // namespace basegfx2d + + +// ----------------------------------------------------------------------------- + +// this macro creates an empty function, which will called by the RegisterAllFunctions() +// to let the user the possibility to also register some functions by hand. +// NOADDITIONAL; + diff --git a/basegfx/test/genericclipper.cxx b/basegfx/test/genericclipper.cxx new file mode 100644 index 000000000000..9ab903ca1541 --- /dev/null +++ b/basegfx/test/genericclipper.cxx @@ -0,0 +1,168 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: basegfx2d.cxx,v $ + * $Revision: 1.14 $ + * + * 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. + * + ************************************************************************/ + + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_basegfx.hxx" +// autogenerated file with codegen.pl + +#include <cppunit/simpleheader.hxx> + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/curve/b2dcubicbezier.hxx> +#include <basegfx/curve/b2dbeziertools.hxx> +#include <basegfx/range/b2dpolyrange.hxx> +#include <basegfx/polygon/b2dpolygon.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygontools.hxx> +#include <basegfx/polygon/b2dpolypolygoncutter.hxx> +#include <basegfx/polygon/b2dpolygonclipper.hxx> +#include <basegfx/polygon/b2dpolypolygon.hxx> +#include <basegfx/numeric/ftools.hxx> + +#include <boost/bind.hpp> + +using namespace ::basegfx; + + +namespace basegfx2d +{ + +class genericclipper : public CppUnit::TestFixture +{ +private: + B2DPolygon aSelfIntersecting; + B2DPolygon aShiftedRectangle; + +public: + // initialise your test code values here. + void setUp() + { + aSelfIntersecting.append(B2DPoint(0, 0)); + aSelfIntersecting.append(B2DPoint(0, 100)); + aSelfIntersecting.append(B2DPoint(75, 100)); + aSelfIntersecting.append(B2DPoint(75, 50)); + aSelfIntersecting.append(B2DPoint(25, 50)); + aSelfIntersecting.append(B2DPoint(25, 150)); + aSelfIntersecting.append(B2DPoint(100,150)); + aSelfIntersecting.append(B2DPoint(100,0)); + aSelfIntersecting.setClosed(true); + + aShiftedRectangle = tools::createPolygonFromRect( + B2DRange(0,90,20,150)); + } + + void tearDown() + {} + + void validate(const char* pName, + const char* pValidSvgD, + B2DPolyPolygon (*pFunc)(const B2DPolyPolygon&, const B2DPolyPolygon&)) + { + const B2DPolyPolygon aSelfIntersect( + tools::prepareForPolygonOperation(aSelfIntersecting)); + const B2DPolyPolygon aRect( + tools::prepareForPolygonOperation(aShiftedRectangle)); +#if defined(VERBOSE) + fprintf(stderr, "%s input LHS - svg:d=\"%s\"\n", + pName, rtl::OUStringToOString( + basegfx::tools::exportToSvgD( + aSelfIntersect), + RTL_TEXTENCODING_UTF8).getStr() ); + fprintf(stderr, "%s input RHS - svg:d=\"%s\"\n", + pName, rtl::OUStringToOString( + basegfx::tools::exportToSvgD( + aRect), + RTL_TEXTENCODING_UTF8).getStr() ); +#endif + + const B2DPolyPolygon aRes= + pFunc(aSelfIntersect, aRect); + +#if defined(VERBOSE) + fprintf(stderr, "%s - svg:d=\"%s\"\n", + pName, rtl::OUStringToOString( + basegfx::tools::exportToSvgD(aRes), + RTL_TEXTENCODING_UTF8).getStr() ); +#endif + + rtl::OUString aValid=rtl::OUString::createFromAscii(pValidSvgD); + + CPPUNIT_ASSERT_MESSAGE(pName, + basegfx::tools::exportToSvgD(aRes) == aValid); + } + + void validateOr() + { + const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm75 10v-50h-50v50z"; + validate("validateOr", pValid, &tools::solvePolygonOperationOr); + } + + void validateXor() + { + const char* pValid="m0 0h100v150h-75v-50h-5v50h-20v-50-10zm0 10h20v-10h-20zm75 10v-50h-50v50z"; + validate("validateXor", pValid, &tools::solvePolygonOperationXor); + } + + void validateAnd() + { + const char* pValid="m0 100v-10h20v10z"; + validate("validateAnd", pValid, &tools::solvePolygonOperationAnd); + } + + void validateDiff() + { + const char* pValid="m0 90v-90h100v150h-75v-50h-5v-10zm55 10v-50h-50v50z"; + validate("validateDiff", pValid, &tools::solvePolygonOperationDiff); + } + + // Change the following lines only, if you add, remove or rename + // member functions of the current class, + // because these macros are need by auto register mechanism. + + CPPUNIT_TEST_SUITE(genericclipper); + CPPUNIT_TEST(validateOr); + CPPUNIT_TEST(validateXor); + CPPUNIT_TEST(validateAnd); + CPPUNIT_TEST(validateDiff); + CPPUNIT_TEST_SUITE_END(); +}; + +// ----------------------------------------------------------------------------- +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(basegfx2d::genericclipper, "genericclipper"); +} // namespace basegfx2d + + +// ----------------------------------------------------------------------------- + +// this macro creates an empty function, which will called by the RegisterAllFunctions() +// to let the user the possibility to also register some functions by hand. +// NOADDITIONAL; + diff --git a/basegfx/test/makefile.mk b/basegfx/test/makefile.mk index cf6c96d4d850..631eb32edc0e 100644 --- a/basegfx/test/makefile.mk +++ b/basegfx/test/makefile.mk @@ -43,10 +43,13 @@ ENABLE_EXCEPTIONS=TRUE # --- Common ---------------------------------------------------------- SHL1OBJS= \ - $(SLO)$/basegfx1d.obj \ - $(SLO)$/basegfx2d.obj \ - $(SLO)$/basegfx3d.obj \ - $(SLO)$/basegfxtools.obj \ + $(SLO)$/basegfx1d.obj \ + $(SLO)$/basegfx2d.obj \ + $(SLO)$/basegfx3d.obj \ + $(SLO)$/boxclipper.obj \ + $(SLO)$/basegfxtools.obj \ + $(SLO)$/clipstate.obj \ + $(SLO)$/genericclipper.obj \ $(SLO)$/testtools.obj # linking statically against basegfx parts |