diff options
30 files changed, 4977 insertions, 40 deletions
diff --git a/basegfx/prj/build.lst b/basegfx/prj/build.lst index 143d8452dab5..20b8a625186b 100644 --- a/basegfx/prj/build.lst +++ b/basegfx/prj/build.lst @@ -2,7 +2,12 @@ fx basegfx : sal NULL fx basegfx usr1 - all fx_mkout NULL fx basegfx\inc get - all fx_inc NULL fx basegfx\prj get - all fx_prj NULL -fx basegfx\source\base1d nmake - all fx_base1d NULL -fx basegfx\source\base2d nmake - all fx_base2d NULL -fx basegfx\source\base3d nmake - all fx_base3d NULL -fx basegfx\util nmake - all fx_util fx_base1d fx_base2d fx_base3d NULL +fx basegfx\source\curve nmake - all fx_curve NULL +fx basegfx\source\matrix nmake - all fx_matrix NULL +fx basegfx\source\numeric nmake - all fx_numeric NULL +fx basegfx\source\point nmake - all fx_point NULL +fx basegfx\source\polygon nmake - all fx_polygon NULL +fx basegfx\source\range nmake - all fx_range NULL +fx basegfx\source\tuple nmake - all fx_tuple NULL +fx basegfx\source\vector nmake - all fx_vector NULL +fx basegfx\util nmake - all fx_util fx_curve fx_matrix fx_numeric fx_point fx_polygon fx_range fx_tuple fx_vector NULL diff --git a/basegfx/prj/d.lst b/basegfx/prj/d.lst index 1753f069a2ac..4a1b2167cffe 100644 --- a/basegfx/prj/d.lst +++ b/basegfx/prj/d.lst @@ -7,24 +7,15 @@ ..\%__SRC%\lib\*.dylib %_DEST%\lib%_EXT%\*.dylib mkdir: %_DEST%\inc%_EXT%\basegfx +mkdir: %_DEST%\inc%_EXT%\basegfx\inc -hedabu: ..\inc\b1drange.hxx %_DEST%\inc%_EXT%\basegfx\b1drange.hxx +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\curve +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\matrix +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\numeric +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\point +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\polygon +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\range +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\tuple +#mkdir: %_DEST%\inc%_EXT%\basegfx\inc\vector +#hedabu: ..\inc\base1d\b1drange.hxx %_DEST%\inc%_EXT%\basegfx\inc\base1d\b1drange.hxx -hedabu: ..\inc\b2drange.hxx %_DEST%\inc%_EXT%\basegfx\b2drange.hxx -hedabu: ..\inc\b2dtuple.hxx %_DEST%\inc%_EXT%\basegfx\b2dtuple.hxx -hedabu: ..\inc\b2dvector.hxx %_DEST%\inc%_EXT%\basegfx\b2dvector.hxx -hedabu: ..\inc\b2dpoint.hxx %_DEST%\inc%_EXT%\basegfx\b2dpoint.hxx -hedabu: ..\inc\b2dhompoint.hxx %_DEST%\inc%_EXT%\basegfx\b2dhompoint.hxx -hedabu: ..\inc\b2dhommatrix.hxx %_DEST%\inc%_EXT%\basegfx\b2dhommatrix.hxx -hedabu: ..\inc\b2dpolygon.hxx %_DEST%\inc%_EXT%\basegfx\b2dpolygon.hxx -hedabu: ..\inc\b2dpolygontools.hxx %_DEST%\inc%_EXT%\basegfx\b2dpolygontools.hxx -hedabu: ..\inc\b2dquadraticbezier.hxx %_DEST%\inc%_EXT%\basegfx\b2dquadraticbezier.hxx -hedabu: ..\inc\b2dcubicbezier.hxx %_DEST%\inc%_EXT%\basegfx\b2dcubicbezier.hxx -hedabu: ..\inc\b2dpolypolygon.hxx %_DEST%\inc%_EXT%\basegfx\b2dpolypolygon.hxx - -hedabu: ..\inc\b3drange.hxx %_DEST%\inc%_EXT%\basegfx\b3drange.hxx -hedabu: ..\inc\b3dtuple.hxx %_DEST%\inc%_EXT%\basegfx\b3dtuple.hxx -hedabu: ..\inc\b3dvector.hxx %_DEST%\inc%_EXT%\basegfx\b3dvector.hxx -hedabu: ..\inc\b3dpoint.hxx %_DEST%\inc%_EXT%\basegfx\b3dpoint.hxx -hedabu: ..\inc\b3dhompoint.hxx %_DEST%\inc%_EXT%\basegfx\b3dhompoint.hxx -hedabu: ..\inc\b3dhommatrix.hxx %_DEST%\inc%_EXT%\basegfx\b3dhommatrix.hxx diff --git a/basegfx/source/curve/b2dcubicbezier.cxx b/basegfx/source/curve/b2dcubicbezier.cxx new file mode 100644 index 000000000000..b63e277dcd04 --- /dev/null +++ b/basegfx/source/curve/b2dcubicbezier.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: b2dcubicbezier.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:24:52 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_CURVE_B2DCUBICBEZIER_HXX +#include <basegfx/inc/curve/b2dcubicbezier.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + namespace curve + { + B2DCubicBezier::B2DCubicBezier(const B2DCubicBezier& rBezier) + : maStartPoint(rBezier.maStartPoint), + maEndPoint(rBezier.maEndPoint), + maControlPointA(rBezier.maControlPointA), + maControlPointB(rBezier.maControlPointB) + { + } + + B2DCubicBezier::B2DCubicBezier() + { + } + + B2DCubicBezier::B2DCubicBezier(const point::B2DPoint& rStart, const point::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd), + maControlPointA(rStart), + maControlPointB(rEnd) + { + } + + B2DCubicBezier::B2DCubicBezier(const point::B2DPoint& rStart, const point::B2DPoint& rControlPointA, + const point::B2DPoint& rControlPointB, const point::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd), + maControlPointA(rControlPointA), + maControlPointB(rControlPointB) + { + } + + B2DCubicBezier::~B2DCubicBezier() + { + } + + // assignment operator + B2DCubicBezier& B2DCubicBezier::operator=(const B2DCubicBezier& rBezier) + { + maStartPoint = rBezier.maStartPoint; + maEndPoint = rBezier.maEndPoint; + maControlPointA = rBezier.maControlPointA; + maControlPointB = rBezier.maControlPointB; + + return *this; + } + + // compare operators + bool B2DCubicBezier::operator==(const B2DCubicBezier& rBezier) const + { + return ( + maStartPoint == rBezier.maStartPoint + && maEndPoint == rBezier.maEndPoint + && maControlPointA == rBezier.maControlPointA + && maControlPointB == rBezier.maControlPointB + ); + } + + bool B2DCubicBezier::operator!=(const B2DCubicBezier& rBezier) const + { + return ( + maStartPoint != rBezier.maStartPoint + || maEndPoint != rBezier.maEndPoint + || maControlPointA != rBezier.maControlPointA + || maControlPointB != rBezier.maControlPointB + ); + } + + // test if vectors are used + bool B2DCubicBezier::isBezier() const + { + if(maControlPointA != maStartPoint || maControlPointB != maEndPoint) + { + return true; + } + + return false; + } + + void B2DCubicBezier::testAndSolveTrivialBezier() + { + // TODO + } + + } // end of namespace curve +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/curve/b2dquadraticbezier.cxx b/basegfx/source/curve/b2dquadraticbezier.cxx new file mode 100644 index 000000000000..63e360ca3f90 --- /dev/null +++ b/basegfx/source/curve/b2dquadraticbezier.cxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * $RCSfile: b2dquadraticbezier.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:24:53 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_CURVE_B2DQUADRATICBEZIER_HXX +#include <basegfx/inc/curve/b2dquadraticbezier.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/inc/numeric/ftools.hxx> +#endif + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + namespace curve + { + B2DQuadraticBezier::B2DQuadraticBezier(const B2DQuadraticBezier& rBezier) + : maStartPoint(rBezier.maStartPoint), + maEndPoint(rBezier.maEndPoint), + maControlPoint(rBezier.maControlPoint) + { + } + + B2DQuadraticBezier::B2DQuadraticBezier() + { + } + + B2DQuadraticBezier::B2DQuadraticBezier(const point::B2DPoint& rStart, const point::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd) + { + } + + B2DQuadraticBezier::B2DQuadraticBezier(const point::B2DPoint& rStart, const point::B2DPoint& rControl, const point::B2DPoint& rEnd) + : maStartPoint(rStart), + maEndPoint(rEnd), + maControlPoint(rControl) + { + } + + B2DQuadraticBezier::~B2DQuadraticBezier() + { + } + + // assignment operator + B2DQuadraticBezier& B2DQuadraticBezier::operator=(const B2DQuadraticBezier& rBezier) + { + maStartPoint = rBezier.maStartPoint; + maEndPoint = rBezier.maEndPoint; + maControlPoint = rBezier.maControlPoint; + + return *this; + } + + // compare operators + bool B2DQuadraticBezier::operator==(const B2DQuadraticBezier& rBezier) const + { + return ( + maStartPoint == rBezier.maStartPoint + && maEndPoint == rBezier.maEndPoint + && maControlPoint == rBezier.maControlPoint + ); + } + + bool B2DQuadraticBezier::operator!=(const B2DQuadraticBezier& rBezier) const + { + return ( + maStartPoint != rBezier.maStartPoint + || maEndPoint != rBezier.maEndPoint + || maControlPoint != rBezier.maControlPoint + ); + } + + // test if control vector is used + bool B2DQuadraticBezier::isBezier() const + { + // if control vector is empty, bezier is not used + if(maControlPoint == maStartPoint || maControlPoint == maEndPoint) + return false; + + return true; + } + } // end of namespace curve +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/curve/makefile.mk b/basegfx/source/curve/makefile.mk new file mode 100644 index 000000000000..1d58cd1ae26c --- /dev/null +++ b/basegfx/source/curve/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:24:53 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=curve + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b2dcubicbezier.obj \ + $(SLO)$/b2dquadraticbezier.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/inc/hommatrixtemplate.hxx b/basegfx/source/inc/hommatrixtemplate.hxx index 9f87ff293763..c20a18a9336f 100644 --- a/basegfx/source/inc/hommatrixtemplate.hxx +++ b/basegfx/source/inc/hommatrixtemplate.hxx @@ -2,9 +2,9 @@ * * $RCSfile: hommatrixtemplate.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: thb $ $Date: 2003-09-26 07:54:57 $ + * last change: $Author: aw $ $Date: 2003-10-28 11:23:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,8 +66,8 @@ #include <sal/types.h> #endif -#ifndef _FTOOLS_HXX -#include <ftools.hxx> +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/inc/numeric/ftools.hxx> #endif #include <math.h> @@ -134,7 +134,7 @@ public: const double fDefault(implGetDefaultValue((RowSize - 1), a)); const double fLineValue(mpLine->get(a)); - if(!fTools::equal(fDefault, fLineValue)) + if(!::basegfx::numeric::fTools::equal(fDefault, fLineValue)) { return false; } @@ -221,7 +221,7 @@ public: { const double fDefault(implGetDefaultValue((RowSize - 1), nColumn)); - if(!fTools::equal(fDefault, rValue)) + if(!::basegfx::numeric::fTools::equal(fDefault, rValue)) { mpLine = new ImplMatLine< RowSize >((RowSize - 1), 0L); mpLine->set(nColumn, rValue); @@ -240,7 +240,7 @@ public: const double fDefault(implGetDefaultValue((RowSize - 1), a)); const double fLineValue(mpLine->get(a)); - if(!fTools::equal(fDefault, fLineValue)) + if(!::basegfx::numeric::fTools::equal(fDefault, fLineValue)) { bNecessary = true; } @@ -273,13 +273,13 @@ public: { double fTemp(fabs(get(a, b))); - if(fTools::more(fTemp, fBig)) + if(::basegfx::numeric::fTools::more(fTemp, fBig)) { fBig = fTemp; } } - if(fTools::equalZero(fBig)) + if(::basegfx::numeric::fTools::equalZero(fBig)) { return false; } @@ -316,7 +316,7 @@ public: set(a, b, fSum); fDum = fStorage[a] * fabs(fSum); - if(fTools::moreOrEqual(fDum, fBig)) + if(::basegfx::numeric::fTools::moreOrEqual(fDum, fBig)) { fBig = fDum; nAMax = a; @@ -341,7 +341,7 @@ public: // here the failure of precision occurs const double fValBB(fabs(get(b, b))); - if(fTools::equalZero(fValBB)) + if(::basegfx::numeric::fTools::equalZero(fValBB)) { return false; } @@ -379,7 +379,7 @@ public: fSum -= get(a, b) * fRow[b]; } } - else if(!fTools::equalZero(fSum)) + else if(!::basegfx::numeric::fTools::equalZero(fSum)) { a2 = a; } @@ -398,7 +398,7 @@ public: const double fValueAA(get(a, a)); - if(!fTools::equalZero(fValueAA)) + if(!::basegfx::numeric::fTools::equalZero(fValueAA)) { fRow[a] = fSum / get(a, a); } @@ -417,7 +417,7 @@ public: const double fDefault(implGetDefaultValue(a, b)); const double fValueAB(get(a, b)); - if(!fTools::equal(fDefault, fValueAB)) + if(!::basegfx::numeric::fTools::equal(fDefault, fValueAB)) { return false; } @@ -443,14 +443,14 @@ public: const double fHomValue(get((RowSize - 1), (RowSize - 1))); - if(fTools::equalZero(fHomValue)) + if(::basegfx::numeric::fTools::equalZero(fHomValue)) { return true; } const double fOne(1.0); - if(fTools::equal(fOne, fHomValue)) + if(::basegfx::numeric::fTools::equal(fOne, fHomValue)) { return true; } @@ -629,7 +629,7 @@ public: const double fValueA(get(a, b)); const double fValueB(rMat.get(a, b)); - if(!fTools::equal(fValueA, fValueB)) + if(!::basegfx::numeric::fTools::equal(fValueA, fValueB)) { return false; } diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx new file mode 100644 index 000000000000..95500889bc48 --- /dev/null +++ b/basegfx/source/matrix/b2dhommatrix.cxx @@ -0,0 +1,416 @@ +/************************************************************************* + * + * $RCSfile: b2dhommatrix.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:25:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/inc/matrix/b2dhommatrix.hxx> +#endif + +#ifndef _HOMMATRIX_TEMPLATE_HXX +#include <hommatrixtemplate.hxx> +#endif + +#ifndef _BGFX_MATRIX_B3DHOMMATRIX_HXX +#include <basegfx/inc/matrix/b3dhommatrix.hxx> +#endif + +#ifndef _BGFX_TUPLE_B3DTUPLE_HXX +#include <basegfx/inc/tuple/b3dtuple.hxx> +#endif + +#ifndef _BGFX_TUPLE_B2DTUPLE_HXX +#include <basegfx/inc/tuple/b2dtuple.hxx> +#endif + +class Impl2DHomMatrix : public ImplHomMatrixTemplate< 3 > +{ +}; + +static Impl2DHomMatrix& get2DIdentityMatrix() +{ + static Impl2DHomMatrix maStatic2DIdentityHomMatrix; + return maStatic2DIdentityHomMatrix; +} + +namespace basegfx +{ + namespace matrix + { + void B2DHomMatrix::implPrepareChange() + { + if(mpM->getRefCount()) + { + mpM->decRefCount(); + mpM = new Impl2DHomMatrix(*mpM); + } + } + + B2DHomMatrix::B2DHomMatrix() + : mpM(&get2DIdentityMatrix()) + { + mpM->incRefCount(); + } + + B2DHomMatrix::B2DHomMatrix(const B2DHomMatrix& rMat) + : mpM(rMat.mpM) + { + mpM->incRefCount(); + } + + B2DHomMatrix::~B2DHomMatrix() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + } + + B2DHomMatrix& B2DHomMatrix::operator=(const B2DHomMatrix& rMat) + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = rMat.mpM; + mpM->incRefCount(); + + return *this; + } + + double B2DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const + { + return mpM->get(nRow, nColumn); + } + + void B2DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue) + { + implPrepareChange(); + mpM->set(nRow, nColumn, fValue); + } + + bool B2DHomMatrix::isIdentity() const + { + if(mpM == &get2DIdentityMatrix()) + return true; + + return mpM->isIdentity(); + } + + void B2DHomMatrix::identity() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = &get2DIdentityMatrix(); + mpM->incRefCount(); + } + + bool B2DHomMatrix::isInvertible() const + { + return mpM->isInvertible(); + } + + bool B2DHomMatrix::invert() + { + Impl2DHomMatrix aWork(*mpM); + sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()]; + sal_Int16 nParity; + + if(aWork.ludcmp(pIndex, nParity)) + { + implPrepareChange(); + mpM->doInvert(aWork, pIndex); + delete pIndex; + + return true; + } + + delete pIndex; + return false; + } + + bool B2DHomMatrix::isNormalized() const + { + return mpM->isNormalized(); + } + + void B2DHomMatrix::normalize() + { + if(!mpM->isNormalized()) + { + implPrepareChange(); + mpM->doNormalize(); + } + } + + double B2DHomMatrix::determinant() const + { + return mpM->doDeterminant(); + } + + double B2DHomMatrix::trace() const + { + return mpM->doTrace(); + } + + void B2DHomMatrix::transpose() + { + implPrepareChange(); + mpM->doTranspose(); + } + + B2DHomMatrix& B2DHomMatrix::operator+=(const B2DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doAddMatrix(*rMat.mpM); + + return *this; + } + + B2DHomMatrix& B2DHomMatrix::operator-=(const B2DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doSubMatrix(*rMat.mpM); + + return *this; + } + + B2DHomMatrix& B2DHomMatrix::operator*=(double fValue) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fValue)) + { + implPrepareChange(); + mpM->doMulMatrix(fValue); + } + + return *this; + } + + B2DHomMatrix& B2DHomMatrix::operator/=(double fValue) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fValue)) + { + implPrepareChange(); + mpM->doMulMatrix(1.0 / fValue); + } + + return *this; + } + + B2DHomMatrix& B2DHomMatrix::operator*=(const B2DHomMatrix& rMat) + { + if(!rMat.isIdentity()) + { + implPrepareChange(); + mpM->doMulMatrix(*rMat.mpM); + } + + return *this; + } + + bool B2DHomMatrix::operator==(const B2DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return true; + + return mpM->isEqual(*rMat.mpM); + } + + bool B2DHomMatrix::operator!=(const B2DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return false; + + return !mpM->isEqual(*rMat.mpM); + } + + void B2DHomMatrix::rotate(double fRadiant) + { + if(!::basegfx::numeric::fTools::equalZero(fRadiant)) + { + Impl2DHomMatrix aRotMat(get2DIdentityMatrix()); + double fSin(sin(fRadiant)); + double fCos(cos(fRadiant)); + + aRotMat.set(0, 0, fCos); + aRotMat.set(1, 1, fCos); + aRotMat.set(1, 0, fSin); + aRotMat.set(0, 1, -fSin); + + implPrepareChange(); + mpM->doMulMatrix(aRotMat); + } + } + + void B2DHomMatrix::translate(double fX, double fY) + { + if(!::basegfx::numeric::fTools::equalZero(fX) || !::basegfx::numeric::fTools::equalZero(fY)) + { + Impl2DHomMatrix aTransMat(get2DIdentityMatrix()); + + aTransMat.set(0, 2, fX); + aTransMat.set(1, 2, fY); + + implPrepareChange(); + mpM->doMulMatrix(aTransMat); + } + } + + void B2DHomMatrix::scale(double fX, double fY) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fX) || !::basegfx::numeric::fTools::equal(fOne, fY)) + { + Impl2DHomMatrix aScaleMat(get2DIdentityMatrix()); + + aScaleMat.set(0, 0, fX); + aScaleMat.set(1, 1, fY); + + implPrepareChange(); + mpM->doMulMatrix(aScaleMat); + } + } + + void B2DHomMatrix::shearX(double fSx) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fSx)) + { + Impl2DHomMatrix aShearXMat(get2DIdentityMatrix()); + + aShearXMat.set(0, 1, fSx); + + implPrepareChange(); + mpM->doMulMatrix(aShearXMat); + } + } + + void B2DHomMatrix::shearY(double fSy) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fSy)) + { + Impl2DHomMatrix aShearYMat(get2DIdentityMatrix()); + + aShearYMat.set(1, 0, fSy); + + implPrepareChange(); + mpM->doMulMatrix(aShearYMat); + } + } + + // Decomposition + bool B2DHomMatrix::decompose(tuple::B2DTuple& rScale, tuple::B2DTuple& rTranslate, double& rRotate, double& rShearX) const + { + // when perspective is used, decompose is not made here + if(!mpM->isLastLineDefault()) + return false; + + // If determinant is zero, decomposition is not possible + if(0.0 == mpM->doDeterminant()) + return false; + + // copy 2x2 matrix and translate vector to 3x3 matrix + ::basegfx::matrix::B3DHomMatrix a3DHomMat; + + a3DHomMat.set(0, 0, get(0, 0)); + a3DHomMat.set(0, 1, get(0, 1)); + a3DHomMat.set(1, 0, get(1, 0)); + a3DHomMat.set(1, 1, get(1, 1)); + a3DHomMat.set(0, 2, get(0, 3)); + a3DHomMat.set(1, 2, get(1, 3)); + + ::basegfx::tuple::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear; + + if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear)) + { + // copy scale values + rScale.setX(r3DScale.getX()); + rScale.setY(r3DScale.getY()); + + // copy shear + rShearX = r3DShear.getX(); + + // copy rotate + rRotate = r3DRotate.getZ(); + + // copy translate + rTranslate.setX(r3DTranslate.getX()); + rTranslate.setY(r3DTranslate.getY()); + + return true; + } + + return false; + } + } // end of namespace matrix +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/matrix/b3dhommatrix.cxx b/basegfx/source/matrix/b3dhommatrix.cxx new file mode 100644 index 000000000000..283c59af703f --- /dev/null +++ b/basegfx/source/matrix/b3dhommatrix.cxx @@ -0,0 +1,639 @@ +/************************************************************************* + * + * $RCSfile: b3dhommatrix.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:25:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_MATRIX_B3DHOMMATRIX_HXX +#include <basegfx/inc/matrix/b3dhommatrix.hxx> +#endif + +#ifndef _HOMMATRIX_TEMPLATE_HXX +#include <hommatrixtemplate.hxx> +#endif + +#ifndef _BGFX_VECTOR_B3DVECTOR_HXX +#include <basegfx/inc/vector/b3dvector.hxx> +#endif + +class Impl3DHomMatrix : public ImplHomMatrixTemplate< 4 > +{ +}; + +static Impl3DHomMatrix& get3DIdentityMatrix() +{ + static Impl3DHomMatrix maStatic3DIdentityHomMatrix; + return maStatic3DIdentityHomMatrix; +} + +namespace basegfx +{ + namespace matrix + { + void B3DHomMatrix::implPrepareChange() + { + if(mpM->getRefCount()) + { + mpM->decRefCount(); + mpM = new Impl3DHomMatrix(*mpM); + } + } + + B3DHomMatrix::B3DHomMatrix() + : mpM(&get3DIdentityMatrix()) + { + mpM->incRefCount(); + } + + B3DHomMatrix::B3DHomMatrix(const B3DHomMatrix& rMat) + : mpM(rMat.mpM) + { + mpM->incRefCount(); + } + + B3DHomMatrix::~B3DHomMatrix() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + } + + B3DHomMatrix& B3DHomMatrix::operator=(const B3DHomMatrix& rMat) + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = rMat.mpM; + mpM->incRefCount(); + + return *this; + } + + double B3DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const + { + return mpM->get(nRow, nColumn); + } + + void B3DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue) + { + implPrepareChange(); + mpM->set(nRow, nColumn, fValue); + } + + bool B3DHomMatrix::isIdentity() const + { + if(mpM == &get3DIdentityMatrix()) + return true; + + return mpM->isIdentity(); + } + + void B3DHomMatrix::identity() + { + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = &get3DIdentityMatrix(); + mpM->incRefCount(); + } + + bool B3DHomMatrix::isInvertible() const + { + return mpM->isInvertible(); + } + + bool B3DHomMatrix::invert() + { + Impl3DHomMatrix aWork(*mpM); + sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()]; + sal_Int16 nParity; + + if(aWork.ludcmp(pIndex, nParity)) + { + implPrepareChange(); + mpM->doInvert(aWork, pIndex); + delete pIndex; + + return true; + } + + delete pIndex; + return false; + } + + bool B3DHomMatrix::isNormalized() const + { + return mpM->isNormalized(); + } + + void B3DHomMatrix::normalize() + { + if(!mpM->isNormalized()) + { + implPrepareChange(); + mpM->doNormalize(); + } + } + + double B3DHomMatrix::determinant() const + { + return mpM->doDeterminant(); + } + + double B3DHomMatrix::trace() const + { + return mpM->doTrace(); + } + + void B3DHomMatrix::transpose() + { + implPrepareChange(); + mpM->doTranspose(); + } + + B3DHomMatrix& B3DHomMatrix::operator+=(const B3DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doAddMatrix(*rMat.mpM); + + return *this; + } + + B3DHomMatrix& B3DHomMatrix::operator-=(const B3DHomMatrix& rMat) + { + implPrepareChange(); + mpM->doSubMatrix(*rMat.mpM); + + return *this; + } + + B3DHomMatrix& B3DHomMatrix::operator*=(double fValue) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fValue)) + { + implPrepareChange(); + mpM->doMulMatrix(fValue); + } + + return *this; + } + + B3DHomMatrix& B3DHomMatrix::operator/=(double fValue) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fValue)) + { + implPrepareChange(); + mpM->doMulMatrix(1.0 / fValue); + } + + return *this; + } + + B3DHomMatrix& B3DHomMatrix::operator*=(const B3DHomMatrix& rMat) + { + if(!rMat.isIdentity()) + { + implPrepareChange(); + mpM->doMulMatrix(*rMat.mpM); + } + + return *this; + } + + bool B3DHomMatrix::operator==(const B3DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return true; + + return mpM->isEqual(*rMat.mpM); + } + + bool B3DHomMatrix::operator!=(const B3DHomMatrix& rMat) const + { + if(mpM == rMat.mpM) + return false; + + return !mpM->isEqual(*rMat.mpM); + } + + void B3DHomMatrix::rotate(double fAngleX,double fAngleY,double fAngleZ) + { + if(!::basegfx::numeric::fTools::equalZero(fAngleX) || !::basegfx::numeric::fTools::equalZero(fAngleY) || !::basegfx::numeric::fTools::equalZero(fAngleZ)) + { + implPrepareChange(); + + if(!::basegfx::numeric::fTools::equalZero(fAngleX)) + { + Impl3DHomMatrix aRotMatX(get3DIdentityMatrix()); + double fSin(sin(fAngleX)); + double fCos(cos(fAngleX)); + + aRotMatX.set(1, 1, fCos); + aRotMatX.set(2, 2, fCos); + aRotMatX.set(2, 1, fSin); + aRotMatX.set(1, 2, -fSin); + + mpM->doMulMatrix(aRotMatX); + } + + if(!::basegfx::numeric::fTools::equalZero(fAngleY)) + { + Impl3DHomMatrix aRotMatY(get3DIdentityMatrix()); + double fSin(sin(fAngleY)); + double fCos(cos(fAngleY)); + + aRotMatY.set(0, 0, fCos); + aRotMatY.set(2, 2, fCos); + aRotMatY.set(0, 2, fSin); + aRotMatY.set(2, 0, -fSin); + + mpM->doMulMatrix(aRotMatY); + } + + if(!::basegfx::numeric::fTools::equalZero(fAngleZ)) + { + Impl3DHomMatrix aRotMatZ(get3DIdentityMatrix()); + double fSin(sin(fAngleZ)); + double fCos(cos(fAngleZ)); + + aRotMatZ.set(0, 0, fCos); + aRotMatZ.set(1, 1, fCos); + aRotMatZ.set(1, 0, fSin); + aRotMatZ.set(0, 1, -fSin); + + mpM->doMulMatrix(aRotMatZ); + } + } + } + + void B3DHomMatrix::translate(double fX, double fY, double fZ) + { + if(!::basegfx::numeric::fTools::equalZero(fX) || !::basegfx::numeric::fTools::equalZero(fY) || !::basegfx::numeric::fTools::equalZero(fZ)) + { + Impl3DHomMatrix aTransMat(get3DIdentityMatrix()); + + aTransMat.set(0, 2, fX); + aTransMat.set(1, 2, fY); + aTransMat.set(2, 2, fZ); + + implPrepareChange(); + mpM->doMulMatrix(aTransMat); + } + } + + void B3DHomMatrix::scale(double fX, double fY, double fZ) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fX) || !::basegfx::numeric::fTools::equal(fOne, fY) ||!::basegfx::numeric::fTools::equal(fOne, fZ)) + { + Impl3DHomMatrix aScaleMat(get3DIdentityMatrix()); + + aScaleMat.set(0, 0, fX); + aScaleMat.set(1, 1, fY); + aScaleMat.set(2, 2, fZ); + + implPrepareChange(); + mpM->doMulMatrix(aScaleMat); + } + } + + void B3DHomMatrix::shearXY(double fSx, double fSy) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fSx) || !::basegfx::numeric::fTools::equal(fOne, fSy)) + { + Impl3DHomMatrix aShearXYMat(get3DIdentityMatrix()); + + aShearXYMat.set(0, 2, fSx); + aShearXYMat.set(1, 2, fSy); + + implPrepareChange(); + mpM->doMulMatrix(aShearXYMat); + } + } + + void B3DHomMatrix::shearYZ(double fSy, double fSz) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fSy) || !::basegfx::numeric::fTools::equal(fOne, fSz)) + { + Impl3DHomMatrix aShearYZMat(get3DIdentityMatrix()); + + aShearYZMat.set(1, 0, fSy); + aShearYZMat.set(2, 0, fSz); + + implPrepareChange(); + mpM->doMulMatrix(aShearYZMat); + } + } + + void B3DHomMatrix::shearXZ(double fSx, double fSz) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fSx) || !::basegfx::numeric::fTools::equal(fOne, fSz)) + { + Impl3DHomMatrix aShearXZMat(get3DIdentityMatrix()); + + aShearXZMat.set(0, 1, fSx); + aShearXZMat.set(2, 1, fSz); + + implPrepareChange(); + mpM->doMulMatrix(aShearXZMat); + } + } + + void B3DHomMatrix::frustum(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar) + { + const double fZero(0.0); + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::more(fNear, fZero)) + { + fNear = 0.001; + } + + if(!::basegfx::numeric::fTools::more(fFar, fZero)) + { + fFar = fOne; + } + + if(::basegfx::numeric::fTools::equal(fNear, fFar)) + { + fFar = fNear + fOne; + } + + if(::basegfx::numeric::fTools::equal(fLeft, fRight)) + { + fLeft -= fOne; + fRight += fOne; + } + + if(::basegfx::numeric::fTools::equal(fTop, fBottom)) + { + fBottom -= fOne; + fTop += fOne; + } + + Impl3DHomMatrix aFrustumMat(get3DIdentityMatrix()); + + aFrustumMat.set(0, 0, 2.0 * fNear / (fRight - fLeft)); + aFrustumMat.set(1, 1, 2.0 * fNear / (fTop - fBottom)); + aFrustumMat.set(0, 2, (fRight + fLeft) / (fRight - fLeft)); + aFrustumMat.set(1, 2, (fTop + fBottom) / (fTop - fBottom)); + aFrustumMat.set(2, 2, -fOne * ((fFar + fNear) / (fFar - fNear))); + aFrustumMat.set(3, 2, -fOne); + aFrustumMat.set(2, 3, -fOne * ((2.0 * fFar * fNear) / (fFar - fNear))); + aFrustumMat.set(3, 3, fZero); + + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = new Impl3DHomMatrix(aFrustumMat); + } + + void B3DHomMatrix::ortho(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar) + { + if(::basegfx::numeric::fTools::equal(fNear, fFar)) + { + fFar = fNear + 1.0; + } + + if(::basegfx::numeric::fTools::equal(fLeft, fRight)) + { + fLeft -= 1.0; + fRight += 1.0; + } + + if(::basegfx::numeric::fTools::equal(fTop, fBottom)) + { + fBottom -= 1.0; + fTop += 1.0; + } + + Impl3DHomMatrix aOrthoMat(get3DIdentityMatrix()); + + aOrthoMat.set(0, 0, 2.0 / (fRight - fLeft)); + aOrthoMat.set(1, 1, 2.0 / (fTop - fBottom)); + aOrthoMat.set(2, 2, -1.0 * (2.0 / (fFar - fNear))); + aOrthoMat.set(0, 3, -1.0 * ((fRight + fLeft) / (fRight - fLeft))); + aOrthoMat.set(1, 3, -1.0 * ((fTop + fBottom) / (fTop - fBottom))); + aOrthoMat.set(2, 3, -1.0 * ((fFar + fNear) / (fFar - fNear))); + + if(mpM->getRefCount()) + mpM->decRefCount(); + else + delete mpM; + + mpM = new Impl3DHomMatrix(aOrthoMat); + } + + bool B3DHomMatrix::decompose(tuple::B3DTuple& rScale, tuple::B3DTuple& rTranslate, tuple::B3DTuple& rRotate, tuple::B3DTuple& rShear) const + { + // when perspective is used, decompose is not made here + if(!mpM->isLastLineDefault()) + return false; + + // If determinant is zero, decomposition is not possible + if(0.0 == mpM->doDeterminant()) + return false; + + // isolate translation + rTranslate.setX(mpM->get(0, 3)); + rTranslate.setY(mpM->get(1, 3)); + rTranslate.setZ(mpM->get(2, 3)); + + // correct translate values + rTranslate.correctValues(); + + // get scale and shear + vector::B3DVector aCol0(mpM->get(0, 0), mpM->get(1, 0), mpM->get(2, 0)); + vector::B3DVector aCol1(mpM->get(0, 1), mpM->get(1, 1), mpM->get(2, 1)); + vector::B3DVector aCol2(mpM->get(0, 2), mpM->get(1, 2), mpM->get(2, 2)); + vector::B3DVector aTemp; + + // get ScaleX + rScale.setX(aCol0.getLength()); + aCol0.normalize(); + + // get ShearXY + rShear.setX(aCol0.scalar(aCol1)); + + if(::basegfx::numeric::fTools::equalZero(rShear.getX())) + { + rShear.setX(0.0); + } + else + { + aTemp.setX(aCol1.getX() - rShear.getX() * aCol0.getX()); + aTemp.setY(aCol1.getY() - rShear.getX() * aCol0.getY()); + aTemp.setZ(aCol1.getZ() - rShear.getX() * aCol0.getZ()); + aCol1 = aTemp; + } + + // get ScaleY + rScale.setY(aCol1.getLength()); + aCol1.normalize(); + + const double fShearX(rShear.getX()); + + if(!::basegfx::numeric::fTools::equalZero(fShearX)) + { + rShear.setX(rShear.getX() / rScale.getY()); + } + + // get ShearXZ + rShear.setY(aCol0.scalar(aCol2)); + + if(::basegfx::numeric::fTools::equalZero(rShear.getY())) + { + rShear.setY(0.0); + } + else + { + aTemp.setX(aCol2.getX() - rShear.getY() * aCol0.getX()); + aTemp.setY(aCol2.getY() - rShear.getY() * aCol0.getY()); + aTemp.setZ(aCol2.getZ() - rShear.getY() * aCol0.getZ()); + aCol2 = aTemp; + } + + // get ShearYZ + rShear.setZ(aCol1.scalar(aCol2)); + + if(::basegfx::numeric::fTools::equalZero(rShear.getZ())) + { + rShear.setZ(0.0); + } + else + { + aTemp.setX(aCol2.getX() - rShear.getZ() * aCol1.getX()); + aTemp.setY(aCol2.getY() - rShear.getZ() * aCol1.getY()); + aTemp.setZ(aCol2.getZ() - rShear.getZ() * aCol1.getZ()); + aCol2 = aTemp; + } + + // get ScaleZ + rScale.setZ(aCol2.getLength()); + aCol2.normalize(); + + const double fShearY(rShear.getY()); + + if(!::basegfx::numeric::fTools::equalZero(fShearY)) + { + rShear.setY(rShear.getY() / rScale.getZ()); + } + + const double fShearZ(rShear.getZ()); + + if(!::basegfx::numeric::fTools::equalZero(fShearZ)) + { + rShear.setZ(rShear.getZ() / rScale.getZ()); + } + + // correct shear values + rShear.correctValues(); + + // Coordinate system flip? + if(0.0 > aCol0.scalar(aCol1.getPerpendicular(aCol2))) + { + rScale = -rScale; + aCol0 = -aCol0; + aCol1 = -aCol1; + aCol2 = -aCol2; + } + + // correct scale values + rScale.correctValues(1.0); + + // Get rotations + rRotate.setY(asin(-aCol0.getZ())); + + if(::basegfx::numeric::fTools::equalZero(cos(rRotate.getY()))) + { + rRotate.setX(atan2(aCol1.getX(), aCol1.getY())); + rRotate.setZ(0.0); + } + else + { + rRotate.setX(atan2(aCol1.getZ(), aCol2.getZ())); + rRotate.setZ(atan2(aCol0.getY(), aCol0.getX())); + } + + // corrcet rotate values + rRotate.correctValues(); + + return true; + } + } // end of namespace matrix +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/matrix/makefile.mk b/basegfx/source/matrix/makefile.mk new file mode 100644 index 000000000000..423506eb4fe1 --- /dev/null +++ b/basegfx/source/matrix/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:25:16 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=matrix + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b2dhommatrix.obj \ + $(SLO)$/b3dhommatrix.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/numeric/ftools.cxx b/basegfx/source/numeric/ftools.cxx new file mode 100644 index 000000000000..4c49d98d56f7 --- /dev/null +++ b/basegfx/source/numeric/ftools.cxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * $RCSfile: ftools.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:23:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/inc/numeric/ftools.hxx> +#endif + +namespace basegfx +{ + namespace numeric + { + // init static member of class fTools + double ::basegfx::numeric::fTools::mfSmallValue = 0.000000001; + } // end of namespace numeric +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/numeric/makefile.mk b/basegfx/source/numeric/makefile.mk new file mode 100644 index 000000000000..d0cf90f33772 --- /dev/null +++ b/basegfx/source/numeric/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:23:36 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=numeric + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/ftools.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/point/b2dhompoint.cxx b/basegfx/source/point/b2dhompoint.cxx new file mode 100644 index 000000000000..b67cb73efde3 --- /dev/null +++ b/basegfx/source/point/b2dhompoint.cxx @@ -0,0 +1,302 @@ +/************************************************************************* + * + * $RCSfile: b2dhompoint.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B2DHOMPOINT_HXX +#include <basegfx/inc/point/b2dhompoint.hxx> +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/inc/matrix/b2dhommatrix.hxx> +#endif + +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/inc/numeric/ftools.hxx> +#endif + +namespace basegfx +{ + namespace point + { + bool B2DHomPoint::implIsHomogenized() const + { + const double fOne(1.0); + return ::basegfx::numeric::fTools::equal(fOne, mfW); + } + + void B2DHomPoint::implHomogenize() + { + const double fFactor(1.0 / mfW); + maTuple.setX(maTuple.getX() * fFactor); + maTuple.setY(maTuple.getY() * fFactor); + mfW = 1.0; + } + + void B2DHomPoint::implTestAndHomogenize() const + { + if(!implIsHomogenized()) + ((B2DHomPoint*)this)->implHomogenize(); + } + + B2DPoint B2DHomPoint::getB2DPoint() const + { + implTestAndHomogenize(); + return B2DPoint(maTuple.getX(), maTuple.getY()); + } + + double B2DHomPoint::getX() const + { + implTestAndHomogenize(); + return maTuple.getX(); + } + + double B2DHomPoint::getY() const + { + implTestAndHomogenize(); + return maTuple.getY(); + } + + void B2DHomPoint::setX(double fX) + { + maTuple.setX(implIsHomogenized() ? fX : fX * mfW ); + } + + void B2DHomPoint::setY(double fY) + { + maTuple.setY(implIsHomogenized() ? fY : fY * mfW ); + } + + B2DHomPoint& B2DHomPoint::operator+=( const B2DHomPoint& rPnt ) + { + maTuple.setX(getX() * rPnt.mfW + rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW + rPnt.getY() * mfW); + mfW = mfW * rPnt.mfW; + + return *this; + } + + B2DHomPoint& B2DHomPoint::operator-=( const B2DHomPoint& rPnt ) + { + maTuple.setX(getX() * rPnt.mfW - rPnt.getX() * mfW); + maTuple.setY(getY() * rPnt.mfW - rPnt.getY() * mfW); + mfW = mfW * rPnt.mfW; + + return *this; + } + + B2DHomPoint& B2DHomPoint::operator*=(double t) + { + if(!::basegfx::numeric::fTools::equalZero(t)) + { + mfW /= t; + } + + return *this; + } + + B2DHomPoint& B2DHomPoint::operator*=( const matrix::B2DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*maTuple.getX() + + rMat.get(0,1)*maTuple.getY() + + rMat.get(0,2)*mfW ); + + const double fTempY( rMat.get(1,0)*maTuple.getX() + + rMat.get(1,1)*maTuple.getY() + + rMat.get(1,2)*mfW ); + + const double fTempZ( rMat.get(2,0)*maTuple.getX() + + rMat.get(2,1)*maTuple.getY() + + rMat.get(2,2)*mfW ); + maTuple.setX( fTempX ); + maTuple.setY( fTempY ); + mfW = fTempZ; + + return *this; + } + + B2DHomPoint& B2DHomPoint::operator/=(double t) + { + mfW *= t; + return *this; + } + + B2DHomPoint& B2DHomPoint::operator-(void) + { + mfW = -mfW; + return *this; + } + + bool B2DHomPoint::operator==( const B2DHomPoint& rPnt ) const + { + implTestAndHomogenize(); + return (maTuple == rPnt.maTuple); + } + + bool B2DHomPoint::operator!=( const B2DHomPoint& rPnt ) const + { + implTestAndHomogenize(); + return (maTuple != rPnt.maTuple); + } + + B2DHomPoint& B2DHomPoint::operator=( const B2DHomPoint& rPnt ) + { + maTuple = rPnt.maTuple; + mfW = rPnt.mfW; + return *this; + } + + B2DHomPoint min(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aMin( + (rVecB.getX() < rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() < rVecA.getY()) ? rVecB.getY() : rVecA.getY()); + return aMin; + } + + B2DHomPoint max(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aMax( + (rVecB.getX() > rVecA.getX()) ? rVecB.getX() : rVecA.getX(), + (rVecB.getY() > rVecA.getY()) ? rVecB.getY() : rVecA.getY()); + return aMax; + } + B2DHomPoint abs(const B2DHomPoint& rVec) + { + B2DHomPoint aAbs( + (0.0 > rVec.getX()) ? -rVec.getX() : rVec.getX(), + (0.0 > rVec.getY()) ? -rVec.getY() : rVec.getY()); + return aAbs; + } + + B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t) + { + B2DHomPoint aInt( + ((rOld2.getX() - rOld1.getX()) + t) + rOld1.getX(), + ((rOld2.getY() - rOld1.getY()) + t) + rOld1.getY()); + return aInt; + } + + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2) + { + B2DHomPoint aAvg( + (rOld1.getX() + rOld2.getX()) * 0.5, + (rOld1.getY() + rOld2.getY()) * 0.5); + return aAvg; + } + + B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3) + { + B2DHomPoint aAvg( + (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), + (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); + return aAvg; + } + + B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aSum(rVecA); + aSum += rVecB; + return aSum; + } + + B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB) + { + B2DHomPoint aSub(rVecA); + aSub -= rVecB; + return aSub; + } + + B2DHomPoint operator*(const B2DHomPoint& rVec, double t) + { + B2DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + B2DHomPoint operator*(double t, const B2DHomPoint& rVec) + { + B2DHomPoint aNew(rVec); + aNew *= t; + return aNew; + } + + B2DHomPoint operator*( const matrix::B2DHomMatrix& rMat, const B2DHomPoint& rPoint ) + { + B2DHomPoint aNew(rPoint); + return aNew*=rMat; + } + + B2DHomPoint operator/(const B2DHomPoint& rVec, double t) + { + B2DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } + + B2DHomPoint operator/(double t, const B2DHomPoint& rVec) + { + B2DHomPoint aNew(rVec); + aNew /= t; + return aNew; + } + } // end of namespace point +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/point/b2dpoint.cxx b/basegfx/source/point/b2dpoint.cxx new file mode 100644 index 000000000000..ddedfc1f2dfd --- /dev/null +++ b/basegfx/source/point/b2dpoint.cxx @@ -0,0 +1,97 @@ +/************************************************************************* + * + * $RCSfile: b2dpoint.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/inc/point/b2dpoint.hxx> +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/inc/matrix/b2dhommatrix.hxx> +#endif + +namespace basegfx +{ + namespace point + { + B2DPoint& B2DPoint::operator=( const B2DTuple& rPoint ) + { + mfX = rPoint.getX(); + mfY = rPoint.getY(); + return *this; + } + + B2DPoint& B2DPoint::operator*=( const matrix::B2DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*mfX + + rMat.get(0,1)*mfY + + rMat.get(0,2) ); + const double fTempY( rMat.get(1,0)*mfX + + rMat.get(1,1)*mfY + + rMat.get(1,2) ); + mfX = fTempX; + mfY = fTempY; + + return *this; + } + } // end of namespace point +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/point/b3dhompoint.cxx b/basegfx/source/point/b3dhompoint.cxx new file mode 100644 index 000000000000..6981a4a0e1eb --- /dev/null +++ b/basegfx/source/point/b3dhompoint.cxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * $RCSfile: b3dhompoint.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:14 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B3DHOMPOINT_HXX +#include <basegfx/inc/point/b3dhompoint.hxx> +#endif + +namespace basegfx +{ + namespace point + { + void B3DHomPoint::implHomogenize() + { + const double fFactor(1.0 / mfW); + maTuple.setX(maTuple.getX() * fFactor); + maTuple.setY(maTuple.getY() * fFactor); + maTuple.setZ(maTuple.getZ() * fFactor); + mfW = 1.0; + } + } // end of namespace point +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/point/b3dpoint.cxx b/basegfx/source/point/b3dpoint.cxx new file mode 100644 index 000000000000..0d3b755982f6 --- /dev/null +++ b/basegfx/source/point/b3dpoint.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * $RCSfile: b3dpoint.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:14 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POINT_B3DPOINT_HXX +#include <basegfx/inc/point/b3dpoint.hxx> +#endif + +namespace basegfx +{ + namespace point + { + } // end of namespace point +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/point/makefile.mk b/basegfx/source/point/makefile.mk new file mode 100644 index 000000000000..6be5eace0c9c --- /dev/null +++ b/basegfx/source/point/makefile.mk @@ -0,0 +1,85 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:26:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=point + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b3dpoint.obj \ + $(SLO)$/b2dhompoint.obj \ + $(SLO)$/b3dpoint.obj \ + $(SLO)$/b3dhompoint.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx new file mode 100644 index 000000000000..37d795359e0f --- /dev/null +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -0,0 +1,1041 @@ +/************************************************************************* + * + * $RCSfile: b2dpolygon.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:23:54 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POLYGON_B2DPOLYGON_HXX +#include <basegfx/inc/polygon/b2dpolygon.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _BGFX_POINT_B2DPOINT_HXX +#include <basegfx/inc/point/b2dpoint.hxx> +#endif + +#ifndef _BGFX_VECTOR_B2DVECTOR_HXX +#include <basegfx/inc/vector/b2dvector.hxx> +#endif + +#include <vector> +#include <algorithm> + +////////////////////////////////////////////////////////////////////////////// + +class CoordinateData2D +{ + basegfx::point::B2DPoint maPoint; + +public: + CoordinateData2D() {} + CoordinateData2D(const basegfx::point::B2DPoint& rData) : maPoint(rData) {} + ~CoordinateData2D() {} + + const basegfx::point::B2DPoint& getCoordinate() const { return maPoint; } + void setCoordinate(const basegfx::point::B2DPoint& rValue) { if(rValue != maPoint) maPoint = rValue; } + sal_Bool operator==(const CoordinateData2D& rData ) const { return (maPoint == rData.getCoordinate()); } +}; + +////////////////////////////////////////////////////////////////////////////// + +class CoordinateDataArray2D +{ + typedef ::std::vector< CoordinateData2D > CoordinateData2DVector; + + CoordinateData2DVector maVector; + +public: + CoordinateDataArray2D(sal_uInt32 nCount) + : maVector(nCount) + { + } + + CoordinateDataArray2D(const CoordinateDataArray2D& rOriginal) + : maVector(rOriginal.maVector) + { + } + + CoordinateDataArray2D(const CoordinateDataArray2D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount) + : maVector(rOriginal.maVector.begin() + nIndex, rOriginal.maVector.begin() + (nIndex + nCount)) + { + } + + sal_uInt32 count() const + { + return maVector.size(); + } + + sal_Bool isEqual(const CoordinateDataArray2D& rCandidate) const + { + return (maVector == rCandidate.maVector); + } + + const basegfx::vector::B2DVector& getCoordinate(sal_uInt32 nIndex) const + { + return maVector[nIndex].getCoordinate(); + } + + void setCoordinate(sal_uInt32 nIndex, const basegfx::vector::B2DVector& rValue) + { + maVector[nIndex].setCoordinate(rValue); + } + + void insert(sal_uInt32 nIndex, const CoordinateData2D& rValue, sal_uInt32 nCount) + { + if(nCount) + { + // add nCount copies of rValue + CoordinateData2DVector::iterator aIndex(maVector.begin()); + aIndex += nIndex; + maVector.insert(aIndex, nCount, rValue); + } + } + + void insert(sal_uInt32 nIndex, const CoordinateDataArray2D& rSource) + { + const sal_uInt32 nCount(rSource.maVector.size()); + + if(nCount) + { + // insert data + CoordinateData2DVector::iterator aIndex(maVector.begin()); + aIndex += nIndex; + CoordinateData2DVector::const_iterator aStart(rSource.maVector.begin()); + CoordinateData2DVector::const_iterator aEnd(rSource.maVector.end()); + maVector.insert(aIndex, aStart, aEnd); + } + } + + void remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(nCount) + { + // remove point data + CoordinateData2DVector::iterator aStart(maVector.begin()); + aStart += nIndex; + const CoordinateData2DVector::iterator aEnd(aStart + nCount); + maVector.erase(aStart, aEnd); + } + } + + void flip() + { + if(maVector.size() > 1) + { + const sal_uInt32 nHalfSize(maVector.size() >> 1L); + CoordinateData2DVector::iterator aStart(maVector.begin()); + CoordinateData2DVector::iterator aEnd(maVector.end()); + + for(sal_uInt32 a(0); a < nHalfSize; a++) + { + ::std::swap(*aStart, *aEnd); + aStart++; + aEnd--; + } + } + } +}; + +////////////////////////////////////////////////////////////////////////////// + +class ControlVectorPair2D +{ + basegfx::vector::B2DVector maVectorA; + basegfx::vector::B2DVector maVectorB; + +public: + ControlVectorPair2D() {} + ~ControlVectorPair2D() {} + + const basegfx::vector::B2DVector& getVectorA() const { return maVectorA; } + void setVectorA(const basegfx::vector::B2DVector& rValue) { if(rValue != maVectorA) maVectorA = rValue; } + + const basegfx::vector::B2DVector& getVectorB() const { return maVectorB; } + void setVectorB(const basegfx::vector::B2DVector& rValue) { if(rValue != maVectorB) maVectorB = rValue; } + + sal_Bool operator==(const ControlVectorPair2D& rData ) const + { return (maVectorA == rData.getVectorA() && maVectorB == rData.getVectorB()); } +}; + +////////////////////////////////////////////////////////////////////////////// + +class ControlVectorArray2D +{ + typedef ::std::vector< ControlVectorPair2D > ControlVectorPair2DVector; + + ControlVectorPair2DVector maVector; + sal_uInt32 mnUsedVectors; + +public: + ControlVectorArray2D(sal_uInt32 nCount) + : maVector(nCount), + mnUsedVectors(0L) + { + } + + ControlVectorArray2D(const ControlVectorArray2D& rOriginal) + : maVector(rOriginal.maVector), + mnUsedVectors(rOriginal.mnUsedVectors) + { + } + + ControlVectorArray2D(const ControlVectorArray2D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount) + : maVector(), + mnUsedVectors(0L) + { + ControlVectorPair2DVector::const_iterator aStart(rOriginal.maVector.begin()); + aStart += nIndex; + ControlVectorPair2DVector::const_iterator aEnd(aStart); + aEnd += nCount; + maVector.reserve(nCount); + + for(; aStart != aEnd; aStart++) + { + if(!aStart->getVectorA().equalZero()) + mnUsedVectors++; + + if(!aStart->getVectorB().equalZero()) + mnUsedVectors++; + + maVector.push_back(*aStart); + } + } + + sal_uInt32 count() const + { + return maVector.size(); + } + + sal_Bool isEqual(const ControlVectorArray2D& rCandidate) const + { + return (maVector == rCandidate.maVector); + } + + sal_Bool isUsed() const + { + return (0L != mnUsedVectors); + } + + const basegfx::vector::B2DVector& getVectorA(sal_uInt32 nIndex) const + { + return maVector[nIndex].getVectorA(); + } + + void setVectorA(sal_uInt32 nIndex, const basegfx::vector::B2DVector& rValue) + { + sal_Bool bWasUsed(mnUsedVectors && !maVector[nIndex].getVectorA().equalZero()); + sal_Bool bIsUsed(!rValue.equalZero()); + + if(bWasUsed) + { + if(bIsUsed) + { + maVector[nIndex].setVectorA(rValue); + } + else + { + maVector[nIndex].setVectorA(basegfx::vector::B2DVector::getEmptyVector()); + mnUsedVectors--; + } + } + else + { + if(bIsUsed) + { + maVector[nIndex].setVectorA(rValue); + mnUsedVectors++; + } + } + } + + const basegfx::vector::B2DVector& getVectorB(sal_uInt32 nIndex) const + { + return maVector[nIndex].getVectorB(); + } + + void setVectorB(sal_uInt32 nIndex, const basegfx::vector::B2DVector& rValue) + { + sal_Bool bWasUsed(mnUsedVectors && !maVector[nIndex].getVectorB().equalZero()); + sal_Bool bIsUsed(!rValue.equalZero()); + + if(bWasUsed) + { + if(bIsUsed) + { + maVector[nIndex].setVectorB(rValue); + } + else + { + maVector[nIndex].setVectorB(basegfx::vector::B2DVector::getEmptyVector()); + mnUsedVectors--; + } + } + else + { + if(bIsUsed) + { + maVector[nIndex].setVectorB(rValue); + mnUsedVectors++; + } + } + } + + void insert(sal_uInt32 nIndex, const ControlVectorPair2D& rValue, sal_uInt32 nCount) + { + if(nCount) + { + // add nCount copies of rValue + ControlVectorPair2DVector::iterator aIndex(maVector.begin()); + aIndex += nIndex; + maVector.insert(aIndex, nCount, rValue); + + if(!rValue.getVectorA().equalZero()) + mnUsedVectors += nCount; + + if(!rValue.getVectorB().equalZero()) + mnUsedVectors += nCount; + } + } + + void insert(sal_uInt32 nIndex, const ControlVectorArray2D& rSource) + { + const sal_uInt32 nCount(rSource.maVector.size()); + + if(nCount) + { + // insert data + ControlVectorPair2DVector::iterator aIndex(maVector.begin()); + aIndex += nIndex; + ControlVectorPair2DVector::const_iterator aStart(rSource.maVector.begin()); + ControlVectorPair2DVector::const_iterator aEnd(rSource.maVector.end()); + maVector.insert(aIndex, aStart, aEnd); + + for(; aStart != aEnd; aStart++) + { + if(!aStart->getVectorA().equalZero()) + mnUsedVectors++; + + if(!aStart->getVectorB().equalZero()) + mnUsedVectors++; + } + } + } + + void remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(nCount) + { + const ControlVectorPair2DVector::iterator aDeleteStart(maVector.begin() + nIndex); + const ControlVectorPair2DVector::iterator aDeleteEnd(aDeleteStart + nCount); + ControlVectorPair2DVector::const_iterator aStart(aDeleteStart); + + for(; mnUsedVectors && aStart != aDeleteEnd; aStart++) + { + if(!aStart->getVectorA().equalZero()) + mnUsedVectors--; + + if(mnUsedVectors && !aStart->getVectorB().equalZero()) + mnUsedVectors--; + } + + // remove point data + maVector.erase(aDeleteStart, aDeleteEnd); + } + } +}; + +////////////////////////////////////////////////////////////////////////////// + +class ImplB2DPolygon +{ + // the internal RefCount + sal_uInt32 mnRefCount; + + // The point vector. This vector exists always and defines the + // count of members. + CoordinateDataArray2D maPoints; + + // The control point vectors. This vectors are created on demand + // and may be zero. + ControlVectorArray2D* mpControlVector; + + // bitfield + // flag which decides if this polygon is opened or closed + unsigned mbIsClosed : 1; + +public: + // This constructor is only used from the static identity polygon, thus + // the RefCount is set to 1 to never 'delete' this static incarnation. + ImplB2DPolygon() + : mnRefCount(1), + maPoints(0L), + mpControlVector(0L), + mbIsClosed(sal_False) + { + // complete initialization with defaults + } + + ImplB2DPolygon(const ImplB2DPolygon& rToBeCopied) + : mnRefCount(0), + maPoints(rToBeCopied.maPoints), + mpControlVector(0L), + mbIsClosed(rToBeCopied.mbIsClosed) + { + // complete initialization using copy + if(rToBeCopied.mpControlVector && rToBeCopied.mpControlVector->isUsed()) + { + mpControlVector = new ControlVectorArray2D(*rToBeCopied.mpControlVector); + } + } + + ImplB2DPolygon(const ImplB2DPolygon& rToBeCopied, sal_uInt32 nIndex, sal_uInt32 nCount) + : mnRefCount(0), + maPoints(rToBeCopied.maPoints, nIndex, nCount), + mpControlVector(0L), + mbIsClosed(rToBeCopied.mbIsClosed) + { + // complete initialization using partly copy + if(rToBeCopied.mpControlVector && rToBeCopied.mpControlVector->isUsed()) + { + mpControlVector = new ControlVectorArray2D(*rToBeCopied.mpControlVector, nIndex, nCount); + + if(!mpControlVector->isUsed()) + { + delete mpControlVector; + mpControlVector = 0L; + } + } + } + + ~ImplB2DPolygon() + { + if(mpControlVector) + { + delete mpControlVector; + mpControlVector = 0L; + } + } + + const sal_uInt32 getRefCount() const + { + return mnRefCount; + } + + void incRefCount() + { + mnRefCount++; + } + + void decRefCount() + { + mnRefCount--; + } + + sal_uInt32 count() const + { + return maPoints.count(); + } + + sal_Bool isClosed() const + { + return mbIsClosed; + } + + void setClosed(sal_Bool bNew) + { + if(bNew != mbIsClosed) + { + mbIsClosed = bNew; + } + } + + sal_Bool isEqual(const ImplB2DPolygon& rCandidate) const + { + if(mbIsClosed == rCandidate.mbIsClosed) + { + if(maPoints.isEqual(rCandidate.maPoints)) + { + sal_Bool bControlVectorsAreEqual(sal_True); + + if(mpControlVector) + { + if(rCandidate.mpControlVector) + { + bControlVectorsAreEqual = mpControlVector->isEqual(*rCandidate.mpControlVector); + } + else + { + // candidate has no control vector, so it's assumed all unused. + bControlVectorsAreEqual = !mpControlVector->isUsed(); + } + } + else + { + if(rCandidate.mpControlVector) + { + // we have no control vector, so it's assumed all unused. + bControlVectorsAreEqual = !rCandidate.mpControlVector->isUsed(); + } + } + + if(bControlVectorsAreEqual) + { + return sal_True; + } + } + } + + return sal_False; + } + + const basegfx::point::B2DPoint& getPoint(sal_uInt32 nIndex) const + { + return maPoints.getCoordinate(nIndex); + } + + void setPoint(sal_uInt32 nIndex, const basegfx::point::B2DPoint& rValue) + { + maPoints.setCoordinate(nIndex, rValue); + } + + void insert(sal_uInt32 nIndex, const basegfx::point::B2DPoint& rPoint, sal_uInt32 nCount) + { + if(nCount) + { + CoordinateData2D aCoordinate(rPoint); + maPoints.insert(nIndex, aCoordinate, nCount); + + if(mpControlVector) + { + ControlVectorPair2D aVectorPair; + mpControlVector->insert(nIndex, aVectorPair, nCount); + } + } + } + + const basegfx::point::B2DPoint& getControlPointA(sal_uInt32 nIndex) const + { + if(mpControlVector) + { + return mpControlVector->getVectorA(nIndex); + } + else + { + return basegfx::point::B2DPoint::getEmptyPoint(); + } + } + + void setControlPointA(sal_uInt32 nIndex, const basegfx::point::B2DPoint& rValue) + { + if(!mpControlVector) + { + if(!rValue.equalZero()) + { + mpControlVector = new ControlVectorArray2D(maPoints.count()); + mpControlVector->setVectorA(nIndex, rValue); + } + } + else + { + mpControlVector->setVectorA(nIndex, rValue); + + if(!mpControlVector->isUsed()) + { + delete mpControlVector; + mpControlVector = 0L; + } + } + } + + sal_Bool areControlPointsUsed() const + { + return (mpControlVector && mpControlVector->isUsed()); + } + + const basegfx::point::B2DPoint& getControlPointB(sal_uInt32 nIndex) const + { + if(mpControlVector) + { + return mpControlVector->getVectorB(nIndex); + } + else + { + return basegfx::point::B2DPoint::getEmptyPoint(); + } + } + + void setControlPointB(sal_uInt32 nIndex, const basegfx::point::B2DPoint& rValue) + { + if(!mpControlVector) + { + if(!rValue.equalZero()) + { + mpControlVector = new ControlVectorArray2D(maPoints.count()); + mpControlVector->setVectorB(nIndex, rValue); + } + } + else + { + mpControlVector->setVectorB(nIndex, rValue); + + if(!mpControlVector->isUsed()) + { + delete mpControlVector; + mpControlVector = 0L; + } + } + } + + void insert(sal_uInt32 nIndex, const ImplB2DPolygon& rSource) + { + const sal_uInt32 nCount(rSource.maPoints.count()); + + if(nCount) + { + if(rSource.mpControlVector && rSource.mpControlVector->isUsed() && !mpControlVector) + { + mpControlVector = new ControlVectorArray2D(maPoints.count()); + } + + maPoints.insert(nIndex, rSource.maPoints); + + if(rSource.mpControlVector) + { + mpControlVector->insert(nIndex, *rSource.mpControlVector); + + if(!mpControlVector->isUsed()) + { + delete mpControlVector; + mpControlVector = 0L; + } + } + else if(mpControlVector) + { + ControlVectorPair2D aVectorPair; + mpControlVector->insert(nIndex, aVectorPair, nCount); + } + } + } + + void remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(nCount) + { + maPoints.remove(nIndex, nCount); + + if(mpControlVector) + { + mpControlVector->remove(nIndex, nCount); + + if(!mpControlVector->isUsed()) + { + delete mpControlVector; + mpControlVector = 0L; + } + } + } + } + + void flip() + { + if(maPoints.count() > 1) + { + if(mpControlVector) + { + // Here, the vectors need to be completely flipped. The new vectors + // rely on the predecessor point and A,B need to be flipped. The last + // vectors need to be moved to first, too. It is also necessary to + // copy the points (of courcse, just to not forget). + const sal_uInt32 nCount(maPoints.count()); + + // create copies to have access to source data + CoordinateDataArray2D* pCoordinateCopy = new CoordinateDataArray2D(maPoints); + ControlVectorArray2D* pVectorCopy = new ControlVectorArray2D(*mpControlVector); + + // newly fill the local point and vector data + for(sal_uInt32 a(0L); a < nCount; a++) + { + // get index for source point + const sal_uInt32 nCoorSource(nCount - (a + 1)); + + // get index for predecessor point + const sal_uInt32 nVectorSource(nCoorSource ? nCoorSource - 1L : nCount - 1L); + + // get source data + const basegfx::point::B2DPoint& rSourceCoor = pCoordinateCopy->getCoordinate(nCoorSource); + const basegfx::point::B2DPoint& rVectorSourceCoor = pCoordinateCopy->getCoordinate(nVectorSource); + const basegfx::vector::B2DVector& rVectorSourceA = pVectorCopy->getVectorA(nVectorSource); + const basegfx::vector::B2DVector& rVectorSourceB = pVectorCopy->getVectorB(nVectorSource); + + // copy point data + maPoints.setCoordinate(a, rSourceCoor); + + // copy vector data A to B + if(rVectorSourceA.equalZero()) + { + // unused, use zero vector + mpControlVector->setVectorB(a, basegfx::vector::B2DVector::getEmptyVector()); + } + else + { + // calculate new vector relative to new point + basegfx::vector::B2DVector aNewVectorB((rVectorSourceA + rVectorSourceCoor) - rSourceCoor); + mpControlVector->setVectorB(a, aNewVectorB); + } + + // copy vector data B to A + if(rVectorSourceB.equalZero()) + { + // unused, use zero vector + mpControlVector->setVectorA(a, basegfx::vector::B2DVector::getEmptyVector()); + } + else + { + // calculate new vector relative to new point + basegfx::vector::B2DVector aNewVectorA((rVectorSourceB + rVectorSourceCoor) - rSourceCoor); + mpControlVector->setVectorA(a, aNewVectorA); + } + } + + // get rid of copied source data + delete pCoordinateCopy; + delete pVectorCopy; + } + else + { + maPoints.flip(); + } + } + } +}; + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + namespace polygon + { + // init static default Polygon + static ImplB2DPolygon maStaticDefaultPolygon; + + void B2DPolygon::implForceUniqueCopy() + { + if(mpPolygon->getRefCount()) + { + mpPolygon->decRefCount(); + mpPolygon = new ImplB2DPolygon(*mpPolygon); + } + } + + B2DPolygon::B2DPolygon() + : mpPolygon(&maStaticDefaultPolygon) + { + mpPolygon->incRefCount(); + } + + B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon) + : mpPolygon(rPolygon.mpPolygon) + { + mpPolygon->incRefCount(); + } + + B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) + : mpPolygon(new ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) + { + DBG_ASSERT(nIndex + nCount > rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)"); + } + + B2DPolygon::~B2DPolygon() + { + if(mpPolygon->getRefCount()) + { + mpPolygon->decRefCount(); + } + else + { + delete mpPolygon; + } + } + + B2DPolygon& B2DPolygon::operator=(const B2DPolygon& rPolygon) + { + if(mpPolygon->getRefCount()) + { + mpPolygon->decRefCount(); + } + else + { + delete mpPolygon; + } + + mpPolygon = rPolygon.mpPolygon; + mpPolygon->incRefCount(); + + return *this; + } + + sal_Bool B2DPolygon::operator==(const B2DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) + { + return true; + } + + return mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } + + sal_Bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const + { + if(mpPolygon == rPolygon.mpPolygon) + { + return false; + } + + return !mpPolygon->isEqual(*(rPolygon.mpPolygon)); + } + + sal_uInt32 B2DPolygon::count() const + { + return mpPolygon->count(); + } + + point::B2DPoint B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const + { + DBG_ASSERT(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + return mpPolygon->getPoint(nIndex); + } + + void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const point::B2DPoint& rValue) + { + DBG_ASSERT(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->getPoint(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setPoint(nIndex, rValue); + } + } + + void B2DPolygon::insert(sal_uInt32 nIndex, const point::B2DPoint& rPoint, sal_uInt32 nCount) + { + DBG_ASSERT(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + + if(nCount) + { + implForceUniqueCopy(); + mpPolygon->insert(nIndex, rPoint, nCount); + } + } + + void B2DPolygon::append(const point::B2DPoint& rPoint, sal_uInt32 nCount) + { + if(nCount) + { + implForceUniqueCopy(); + mpPolygon->insert(mpPolygon->count(), rPoint, nCount); + } + } + + point::B2DPoint B2DPolygon::getControlPointA(sal_uInt32 nIndex) const + { + DBG_ASSERT(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + return mpPolygon->getControlPointA(nIndex); + } + + void B2DPolygon::setControlPointA(sal_uInt32 nIndex, const point::B2DPoint& rValue) + { + DBG_ASSERT(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->getControlPointA(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setControlPointA(nIndex, rValue); + } + } + + point::B2DPoint B2DPolygon::getControlPointB(sal_uInt32 nIndex) const + { + DBG_ASSERT(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + return mpPolygon->getControlPointB(nIndex); + } + + void B2DPolygon::setControlPointB(sal_uInt32 nIndex, const point::B2DPoint& rValue) + { + DBG_ASSERT(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + + if(mpPolygon->getControlPointB(nIndex) != rValue) + { + implForceUniqueCopy(); + mpPolygon->setControlPointB(nIndex, rValue); + } + } + + sal_Bool B2DPolygon::areControlPointsUsed() const + { + return mpPolygon->areControlPointsUsed(); + } + + void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPoly, sal_uInt32 nIndex2, sal_uInt32 nCount) + { + DBG_ASSERT(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + + if(rPoly.count()) + { + implForceUniqueCopy(); + + if(!nCount) + { + nCount = rPoly.count(); + } + + if(0L == nIndex2 && nCount == rPoly.count()) + { + mpPolygon->insert(nIndex, *rPoly.mpPolygon); + } + else + { + DBG_ASSERT(nIndex2 + nCount > rPoly.mpPolygon->count(), "B2DPolygon Insert outside range (!)"); + ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex2, nCount); + mpPolygon->insert(nIndex, aTempPoly); + } + } + } + + void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(rPoly.count()) + { + implForceUniqueCopy(); + + if(!nCount) + { + nCount = rPoly.count(); + } + + if(0L == nIndex && nCount == rPoly.count()) + { + mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon); + } + else + { + DBG_ASSERT(nIndex + nCount > rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); + ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); + mpPolygon->insert(mpPolygon->count(), aTempPoly); + } + } + } + + void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + DBG_ASSERT(nIndex + nCount > mpPolygon->count(), "B2DPolygon Remove outside range (!)"); + + if(nCount) + { + implForceUniqueCopy(); + mpPolygon->remove(nIndex, nCount); + } + } + + void B2DPolygon::clear() + { + if(mpPolygon->getRefCount()) + { + mpPolygon->decRefCount(); + } + else + { + delete mpPolygon; + } + + mpPolygon = &maStaticDefaultPolygon; + mpPolygon->incRefCount(); + } + + sal_Bool B2DPolygon::isClosed() const + { + return mpPolygon->isClosed(); + } + + void B2DPolygon::setClosed(sal_Bool bNew) + { + if(mpPolygon->isClosed() != bNew) + { + implForceUniqueCopy(); + mpPolygon->setClosed(bNew); + } + } + + void B2DPolygon::flip() + { + if(mpPolygon->count() > 1) + { + implForceUniqueCopy(); + mpPolygon->flip(); + } + } + } // end of namespace polygon +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// +// eof diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx new file mode 100644 index 000000000000..0df233f19bc2 --- /dev/null +++ b/basegfx/source/polygon/b2dpolygontools.cxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * $RCSfile: b2dpolygontools.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:23:54 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POLYGON_B2DPOLYGONTOOLS_HXX +#include <basegfx/inc/polygon/b2dpolygontools.hxx> +#endif + +#ifndef _BGFX_POLYGON_B2DPOLYGON_HXX +#include <basegfx/inc/polygon/b2dpolygon.hxx> +#endif + +#ifndef _BGFX_CURVE_B2DCUBICBEZIER_HXX +#include <basegfx/inc/curve/b2dcubicbezier.hxx> +#endif + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + namespace polygon + { + namespace tools + { + // B2DPolygon tools + void checkClosed(polygon::B2DPolygon& rCandidate) + { + while(rCandidate.count() > 1L) + { + bool bFirstLastPointEqual( + rCandidate.getB2DPoint(0L) == rCandidate.getB2DPoint(rCandidate.count() - 1L)); + + if(bFirstLastPointEqual) + { + rCandidate.setClosed(true); + rCandidate.remove(rCandidate.count() - 1L); + } + } + } + + // Checks if one of the control vectors is used + bool isEdgeBezier(const polygon::B2DPolygon& rPolygon, sal_uInt32 nEdgeIndex) + { + if(rPolygon.areControlPointsUsed()) + { + DBG_ASSERT(nEdgeIndex < rPolygon.count(), "EdgeIndex out of range (!)"); + + if(!rPolygon.getControlPointA(nEdgeIndex).equalZero()) + return true; + + if(!rPolygon.getControlPointB(nEdgeIndex).equalZero()) + return true; + } + + return false; + } + + bool isEdgeTrivialBezier(const polygon::B2DPolygon& rPolygon, sal_uInt32 nEdgeIndex) + { + if(rPolygon.areControlPointsUsed()) + { + DBG_ASSERT(nEdgeIndex < rPolygon.count(), "EdgeIndex out of range (!)"); + const sal_uInt32 nEndIndex((nEdgeIndex + 1L) % rPolygon.count()); + + curve::B2DCubicBezier aCubicBezier( + rPolygon.getB2DPoint(nEdgeIndex), + rPolygon.getControlPointA(nEdgeIndex), + rPolygon.getControlPointB(nEdgeIndex), + rPolygon.getB2DPoint(nEndIndex)); + + aCubicBezier.testAndSolveTrivialBezier(); + + return !aCubicBezier.isBezier(); + } + + return true; + } + } // end of namespace tools + } // end of namespace polygon +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +// eof diff --git a/basegfx/source/polygon/b2dpolypolygon.cxx b/basegfx/source/polygon/b2dpolypolygon.cxx new file mode 100644 index 000000000000..556a5006948c --- /dev/null +++ b/basegfx/source/polygon/b2dpolypolygon.cxx @@ -0,0 +1,355 @@ +/************************************************************************* + * + * $RCSfile: b2dpolypolygon.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:23:55 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_POLYGON_B2DPOLYPOLYGON_HXX +#include <basegfx/inc/polygon/b2dpolypolygon.hxx> +#endif + +#ifndef _BGFX_POLYGON_B2DPOLYGON_HXX +#include <basegfx/inc/polygon/b2dpolygon.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#include <vector> + +////////////////////////////////////////////////////////////////////////////// + +class ImplB2DPolyPolygon +{ + typedef ::std::vector< basegfx::polygon::B2DPolygon > PolygonVector; + + PolygonVector maPolygons; + sal_uInt32 mnRefCount; + +public: + // This constructor is only used from the static identity polygon, thus + // the RefCount is set to 1 to never 'delete' this static incarnation. + ImplB2DPolyPolygon() + : mnRefCount(1) + { + // complete initialization with defaults + } + + ImplB2DPolyPolygon(const ImplB2DPolyPolygon& rToBeCopied) + : mnRefCount(0) + { + // complete initialization using copy + maPolygons = rToBeCopied.maPolygons; + } + + ~ImplB2DPolyPolygon() + { + } + + const sal_uInt32 getRefCount() const { return mnRefCount; } + void incRefCount() { mnRefCount++; } + void decRefCount() { mnRefCount--; } + + bool isEqual(const ImplB2DPolyPolygon& rPolygonList) const + { + // same polygon count? + if(maPolygons.size() != rPolygonList.maPolygons.size()) + return false; + + // if zero polygons the polys are equal + if(!maPolygons.size()) + return true; + + // compare polygon content + if(maPolygons != rPolygonList.maPolygons) + return false; + + return true; + } + + const basegfx::polygon::B2DPolygon& getPolygon(sal_uInt32 nIndex) const + { + return maPolygons[nIndex]; + } + + void setPolygon(sal_uInt32 nIndex, const basegfx::polygon::B2DPolygon& rPolygon) + { + maPolygons[nIndex] = rPolygon; + } + + void insert(sal_uInt32 nIndex, const basegfx::polygon::B2DPolygon& rPolygon, sal_uInt32 nCount) + { + if(nCount) + { + // add nCount copies of rPolygon + PolygonVector::iterator aIndex(maPolygons.begin()); + aIndex += nIndex; + maPolygons.insert(aIndex, nCount, rPolygon); + } + } + + void insert(sal_uInt32 nIndex, const basegfx::polygon::B2DPolyPolygon& rPolyPolygon) + { + const sal_uInt32 nCount = rPolyPolygon.count(); + + if(nCount) + { + // add nCount polygons from rPolyPolygon + maPolygons.reserve(maPolygons.size() + nCount); + PolygonVector::iterator aIndex(maPolygons.begin()); + aIndex += nIndex; + + for(sal_uInt32 a(0L); a < nCount; a++) + { + maPolygons.insert(aIndex, rPolyPolygon.getPolygon(a)); + aIndex++; + } + } + } + + void remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + if(nCount) + { + // remove polygon data + PolygonVector::iterator aStart(maPolygons.begin()); + aStart += nIndex; + const PolygonVector::iterator aEnd(aStart + nCount); + + maPolygons.erase(aStart, aEnd); + } + } + + sal_uInt32 count() const + { + return maPolygons.size(); + } +}; + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + namespace polygon + { + // init static default Polygon + static ImplB2DPolyPolygon maStaticDefaultPolyPolygon; + + void B2DPolyPolygon::implForceUniqueCopy() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + mpPolyPolygon = new ImplB2DPolyPolygon(*mpPolyPolygon); + } + } + + B2DPolyPolygon::B2DPolyPolygon() + : mpPolyPolygon(&maStaticDefaultPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } + + B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) + : mpPolyPolygon(rPolyPolygon.mpPolyPolygon) + { + mpPolyPolygon->incRefCount(); + } + + B2DPolyPolygon::~B2DPolyPolygon() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else + { + delete mpPolyPolygon; + } + } + + B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon) + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else + { + delete mpPolyPolygon; + } + + mpPolyPolygon = rPolyPolygon.mpPolyPolygon; + mpPolyPolygon->incRefCount(); + + return *this; + } + + bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) + { + return true; + } + + return mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } + + bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const + { + if(mpPolyPolygon == rPolyPolygon.mpPolyPolygon) + { + return false; + } + + return !mpPolyPolygon->isEqual(*(rPolyPolygon.mpPolyPolygon)); + } + + sal_uInt32 B2DPolyPolygon::count() const + { + return mpPolyPolygon->count(); + } + + B2DPolygon B2DPolyPolygon::getPolygon(sal_uInt32 nIndex) const + { + DBG_ASSERT(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + + return mpPolyPolygon->getPolygon(nIndex); + } + + void B2DPolyPolygon::setPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon) + { + DBG_ASSERT(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)"); + + if(mpPolyPolygon->getPolygon(nIndex) != rPolygon) + { + implForceUniqueCopy(); + mpPolyPolygon->setPolygon(nIndex, rPolygon); + } + } + + void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount) + { + DBG_ASSERT(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); + + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolygon, nCount); + } + } + + void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount) + { + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount); + } + } + + void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon) + { + DBG_ASSERT(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)"); + + if(rPolyPolygon.count()) + { + implForceUniqueCopy(); + mpPolyPolygon->insert(nIndex, rPolyPolygon); + } + } + + void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon) + { + if(rPolyPolygon.count()) + { + implForceUniqueCopy(); + mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon); + } + } + + void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) + { + DBG_ASSERT(nIndex + nCount > mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)"); + + if(nCount) + { + implForceUniqueCopy(); + mpPolyPolygon->remove(nIndex, nCount); + } + } + + void B2DPolyPolygon::clear() + { + if(mpPolyPolygon->getRefCount()) + { + mpPolyPolygon->decRefCount(); + } + else + { + delete mpPolyPolygon; + } + + mpPolyPolygon = &maStaticDefaultPolyPolygon; + mpPolyPolygon->incRefCount(); + } + } // end of namespace polygon +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/polygon/makefile.mk b/basegfx/source/polygon/makefile.mk new file mode 100644 index 000000000000..6d2921a7155f --- /dev/null +++ b/basegfx/source/polygon/makefile.mk @@ -0,0 +1,84 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:23:55 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=polygon + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b2dpolygon.obj \ + $(SLO)$/b2dpolygontools.obj \ + $(SLO)$/b2dpolypolygon.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/range/b1drange.cxx b/basegfx/source/range/b1drange.cxx new file mode 100644 index 000000000000..ee8b93d0af89 --- /dev/null +++ b/basegfx/source/range/b1drange.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * $RCSfile: b1drange.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_RANGE_B1DRANGE_HXX +#include <basegfx/inc/range/b1drange.hxx> +#endif + +namespace basegfx +{ + namespace range + { + } // end of namespace range +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/range/b2drange.cxx b/basegfx/source/range/b2drange.cxx new file mode 100644 index 000000000000..60bd6813fabe --- /dev/null +++ b/basegfx/source/range/b2drange.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * $RCSfile: b2drange.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_RANGE_B2DRANGE_HXX +#include <basegfx/inc/range/b2drange.hxx> +#endif + +namespace basegfx +{ + namespace range + { + } // end of namespace range +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/range/b3drange.cxx b/basegfx/source/range/b3drange.cxx new file mode 100644 index 000000000000..6418697e588e --- /dev/null +++ b/basegfx/source/range/b3drange.cxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * $RCSfile: b3drange.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_RANGE_B3DRANGE_HXX +#include <basegfx/inc/range/b3drange.hxx> +#endif + +namespace basegfx +{ + namespace range + { + } // end of namespace range +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/range/makefile.mk b/basegfx/source/range/makefile.mk new file mode 100644 index 000000000000..f1fda731918c --- /dev/null +++ b/basegfx/source/range/makefile.mk @@ -0,0 +1,84 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:26:38 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=range + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b1drange.obj \ + $(SLO)$/b2drange.obj \ + $(SLO)$/b3drange.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/tuple/b2dtuple.cxx b/basegfx/source/tuple/b2dtuple.cxx new file mode 100644 index 000000000000..70227e5f1b9e --- /dev/null +++ b/basegfx/source/tuple/b2dtuple.cxx @@ -0,0 +1,133 @@ +/************************************************************************* + * + * $RCSfile: b2dtuple.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:24:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_TUPLE_B2DTUPLE_HXX +#include <basegfx/inc/tuple/b2dtuple.hxx> +#endif + +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/inc/numeric/ftools.hxx> +#endif + +namespace basegfx +{ + namespace tuple + { + // initialize static member + B2DTuple B2DTuple::maEmptyTuple(0.0, 0.0); + + bool B2DTuple::equalZero() const + { + return (this == &maEmptyTuple || + (::basegfx::numeric::fTools::equalZero(mfX) && ::basegfx::numeric::fTools::equalZero(mfY))); + } + + bool B2DTuple::equalZero(const double& rfSmallValue) const + { + return (this == &maEmptyTuple || + (::basegfx::numeric::fTools::equalZero(mfX, rfSmallValue) && ::basegfx::numeric::fTools::equalZero(mfY, rfSmallValue))); + } + + bool B2DTuple::equal(const B2DTuple& rTup) const + { + return ( + ::basegfx::numeric::fTools::equal(mfX, rTup.mfX) && + ::basegfx::numeric::fTools::equal(mfY, rTup.mfY)); + } + + bool B2DTuple::equal(const B2DTuple& rTup, const double& rfSmallValue) const + { + return ( + ::basegfx::numeric::fTools::equal(mfX, rTup.mfX, rfSmallValue) && + ::basegfx::numeric::fTools::equal(mfY, rTup.mfY, rfSmallValue)); + } + + void B2DTuple::correctValues(const double fCompareValue) + { + if(0.0 == fCompareValue) + { + if(::basegfx::numeric::fTools::equalZero(mfX)) + { + mfX = 0.0; + } + + if(::basegfx::numeric::fTools::equalZero(mfY)) + { + mfY = 0.0; + } + } + else + { + if(::basegfx::numeric::fTools::equal(mfX, fCompareValue)) + { + mfX = fCompareValue; + } + + if(::basegfx::numeric::fTools::equal(mfY, fCompareValue)) + { + mfY = fCompareValue; + } + } + } + } // end of namespace tuple +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/tuple/b3dtuple.cxx b/basegfx/source/tuple/b3dtuple.cxx new file mode 100644 index 000000000000..fcd5b2316358 --- /dev/null +++ b/basegfx/source/tuple/b3dtuple.cxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * $RCSfile: b3dtuple.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:24:16 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_TUPLE_B3DTUPLE_HXX +#include <basegfx/inc/tuple/b3dtuple.hxx> +#endif + +namespace basegfx +{ + namespace tuple + { + // initialize static member + B3DTuple B3DTuple::maEmptyTuple(0.0, 0.0, 0.0); + } // end of namespace tuple +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/tuple/makefile.mk b/basegfx/source/tuple/makefile.mk new file mode 100644 index 000000000000..94566b96d598 --- /dev/null +++ b/basegfx/source/tuple/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:24:16 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=tuple + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b2dtuple.obj \ + $(SLO)$/b3dtuple.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/basegfx/source/vector/b2dvector.cxx b/basegfx/source/vector/b2dvector.cxx new file mode 100644 index 000000000000..f80ae063d985 --- /dev/null +++ b/basegfx/source/vector/b2dvector.cxx @@ -0,0 +1,201 @@ +/************************************************************************* + * + * $RCSfile: b2dvector.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:56 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_VECTOR_B2DVECTOR_HXX +#include <basegfx/inc/vector/b2dvector.hxx> +#endif + +#ifndef _BGFX_MATRIX_B2DHOMMATRIX_HXX +#include <basegfx/inc/matrix/b2dhommatrix.hxx> +#endif + +#ifndef _BGFX_NUMERIC_FTOOLS_HXX +#include <basegfx/inc/numeric/ftools.hxx> +#endif + +namespace basegfx +{ + namespace vector + { + B2DVector& B2DVector::normalize() + { + double fLen(scalar(*this)); + + if(!::basegfx::numeric::fTools::equalZero(fLen)) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fLen)) + { + fLen = sqrt(fLen); + + if(!::basegfx::numeric::fTools::equalZero(fLen)) + { + mfX /= fLen; + mfY /= fLen; + } + } + } + + return *this; + } + + B2DVector& B2DVector::operator=( const B2DTuple& rVec ) + { + mfX = rVec.getX(); + mfY = rVec.getY(); + return *this; + } + + + double B2DVector::getLength() const + { + return hypot( mfX, mfY ); + } + + double B2DVector::scalar( const B2DVector& rVec ) const + { + return((mfX * rVec.mfX) + (mfY * rVec.mfY)); + } + + const B2DVector& B2DVector::getEmptyVector() + { + return (const B2DVector&) B2DTuple::getEmptyTuple(); + } + + B2DVector& B2DVector::operator*=( const matrix::B2DHomMatrix& rMat ) + { + const double fTempX( rMat.get(0,0)*mfX + + rMat.get(0,1)*mfY ); + const double fTempY( rMat.get(1,0)*mfX + + rMat.get(1,1)*mfY ); + mfX = fTempX; + mfY = fTempY; + + return *this; + } + + B2DVector& B2DVector::setLength(double fLen) + { + double fLenNow(scalar(*this)); + + if(!::basegfx::numeric::fTools::equalZero(fLenNow)) + { + const double fOne(10.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fLenNow)) + { + fLen /= sqrt(fLenNow); + } + + mfX *= fLen; + mfY *= fLen; + } + + return *this; + } + + bool B2DVector::isNormalized() const + { + const double fOne(1.0); + const double fScalar(scalar(*this)); + + return (::basegfx::numeric::fTools::equal(fOne, fScalar)); + } + + bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB ) + { + double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecA.getX()); + return ::basegfx::numeric::fTools::equalZero(fVal); + } + + B2DVector::B2DVectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB ) + { + double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecA.getX()); + + if(fVal > 0.0) + { + return B2DVector::POSITIVE; + } + + if(fVal < 0.0) + { + return B2DVector::NEGATIVE; + } + + return B2DVector::NEUTRAL; + } + + B2DVector getPerpendicular( const B2DVector& rNormalizedVec ) + { + B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX()); + return aPerpendicular; + } + + B2DVector operator*( const matrix::B2DHomMatrix& rMat, const B2DVector& rVec ) + { + B2DVector aRes( rVec ); + return aRes*=rMat; + } + } // end of namespace vector +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/vector/b3dvector.cxx b/basegfx/source/vector/b3dvector.cxx new file mode 100644 index 000000000000..8fab9f687c99 --- /dev/null +++ b/basegfx/source/vector/b3dvector.cxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * $RCSfile: b3dvector.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: aw $ $Date: 2003-10-28 11:26:57 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BGFX_VECTOR_B3DVECTOR_HXX +#include <basegfx/inc/vector/b3dvector.hxx> +#endif + +namespace basegfx +{ + namespace vector + { + B3DVector& B3DVector::normalize() + { + double fLen(scalar(*this)); + + if(!::basegfx::numeric::fTools::equalZero(fLen)) + { + const double fOne(1.0); + + if(!::basegfx::numeric::fTools::equal(fOne, fLen)) + { + fLen = sqrt(fLen); + + if(!::basegfx::numeric::fTools::equalZero(fLen)) + { + mfX /= fLen; + mfY /= fLen; + mfZ /= fLen; + } + } + } + + return *this; + } + + B3DVector B3DVector::getPerpendicular(const B3DVector& rNormalizedVec) const + { + B3DVector aNew(*this); + aNew = cross(aNew, rNormalizedVec); + aNew.normalize(); + return aNew; + } + + B3DVector B3DVector::getProjectionOnPlane(const B3DVector& rNormalizedPlane) const + { + B3DVector aNew(*this); + aNew = cross(aNew, rNormalizedPlane); + aNew = cross(aNew, rNormalizedPlane); + + aNew.mfX = mfX - aNew.mfX; + aNew.mfY = mfY - aNew.mfY; + aNew.mfZ = mfZ - aNew.mfZ; + + return aNew; + } + } // end of namespace vector +} // end of namespace basegfx + +// eof diff --git a/basegfx/source/vector/makefile.mk b/basegfx/source/vector/makefile.mk new file mode 100644 index 000000000000..fead5951b707 --- /dev/null +++ b/basegfx/source/vector/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: aw $ $Date: 2003-10-28 11:26:57 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=basegfx +TARGET=vector + +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +#ENABLE_EXCEPTIONS=FALSE +#USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/b2dvector.obj \ + $(SLO)$/b3dvector.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk |