summaryrefslogtreecommitdiff
path: root/basegfx/inc
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2005-11-02 12:55:29 +0000
committerKurt Zenker <kz@openoffice.org>2005-11-02 12:55:29 +0000
commit412a75790f51d3c5f12380503ece4f733aeef944 (patch)
tree2a96a554f3646dd2c911621f940d9b98d4493631 /basegfx/inc
parent5ef4d26b3cba160753740fae06b909b94fdc3f02 (diff)
INTEGRATION: CWS canvas02 (1.1.2); FILE ADDED
2005/10/11 15:39:27 thb 1.1.2.2: #i54170# Corrected license headers 2005/06/29 19:16:34 thb 1.1.2.1: #i48939# Added BxIBox classes, that complement the BxIRange ones (the old right and bottom line inclusive/exclusive clash)
Diffstat (limited to 'basegfx/inc')
-rw-r--r--basegfx/inc/basegfx/range/basicbox.hxx146
1 files changed, 146 insertions, 0 deletions
diff --git a/basegfx/inc/basegfx/range/basicbox.hxx b/basegfx/inc/basegfx/range/basicbox.hxx
new file mode 100644
index 000000000000..1e201ef4482e
--- /dev/null
+++ b/basegfx/inc/basegfx/range/basicbox.hxx
@@ -0,0 +1,146 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: basicbox.hxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: kz $ $Date: 2005-11-02 13:55:29 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 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
+ *
+ ************************************************************************/
+
+#ifndef _BGFX_RANGE_BASICBOX_HXX
+#define _BGFX_RANGE_BASICBOX_HXX
+
+#ifndef _BGFX_RANGE_BASICRANGE_HXX
+#include <basegfx/range/basicrange.hxx>
+#endif
+
+
+namespace basegfx
+{
+ /** Specialization of BasicRange, handling the inside predicates
+ differently.
+
+ This template considers the rightmost and bottommost border as
+ <em>outside</em> of the range, in contrast to BasicRange,
+ which considers them inside.
+ */
+ class BasicBox : public BasicRange< sal_Int32, Int32Traits >
+ {
+ typedef BasicRange< sal_Int32, Int32Traits > Base;
+ public:
+ BasicBox() :
+ Base()
+ {
+ }
+
+ BasicBox( sal_Int32 nValue ) :
+ Base( nValue )
+ {
+ }
+
+ BasicBox(const BasicBox& rBox) :
+ Base( rBox )
+ {
+ }
+
+ double getCenter() const
+ {
+ if(isEmpty())
+ {
+ return 0.0;
+ }
+ else
+ {
+ return ((mnMaximum + mnMinimum - 1.0) / 2.0);
+ }
+ }
+
+ using Base::isInside;
+
+ bool isInside(sal_Int32 nValue) const
+ {
+ if(isEmpty())
+ {
+ return false;
+ }
+ else
+ {
+ return (nValue >= mnMinimum) && (nValue < mnMaximum);
+ }
+ }
+
+ using Base::overlaps;
+
+ bool overlaps(const BasicBox& rBox) const
+ {
+ if(isEmpty())
+ {
+ return false;
+ }
+ else
+ {
+ if(rBox.isEmpty())
+ {
+ return false;
+ }
+ else
+ {
+ return !((rBox.mnMaximum <= mnMinimum) || (rBox.mnMinimum >= mnMaximum));
+ }
+ }
+ }
+
+ void grow(sal_Int32 nValue)
+ {
+ if(!isEmpty())
+ {
+ bool bLessThanZero(nValue < 0);
+
+ if(nValue > 0 || bLessThanZero)
+ {
+ mnMinimum -= nValue;
+ mnMaximum += nValue;
+
+ if(bLessThanZero)
+ {
+ // test if range did collapse
+ if(mnMinimum > mnMaximum)
+ {
+ // if yes, collapse to center
+ mnMinimum = mnMaximum = ((mnMaximum + mnMinimum - 1) / 2);
+ }
+ }
+ }
+ }
+ }
+ };
+
+} // end of namespace basegfx
+
+#endif /* _BGFX_RANGE_BASICBOX_HXX */