1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx> 32*cdf0e10cSrcweir #include <basegfx/range/b2irange.hxx> 33*cdf0e10cSrcweir #include <basegfx/range/b2ibox.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace basegfx 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir namespace 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir /** Generic implementation of the difference set computation 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir @tpl RangeType 43*cdf0e10cSrcweir Type to operate on. Must provide ValueType and TraitsType 44*cdf0e10cSrcweir nested types. 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir template< class RangeType > void doComputeSetDifference( 47*cdf0e10cSrcweir ::std::vector< RangeType >& o_rRanges, 48*cdf0e10cSrcweir const RangeType& a, 49*cdf0e10cSrcweir const RangeType& b ) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir o_rRanges.clear(); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // special-casing the empty rect case (this will fail most 54*cdf0e10cSrcweir // of the times below, because of the DBL_MIN/MAX special 55*cdf0e10cSrcweir // values denoting emptyness in the rectangle. 56*cdf0e10cSrcweir if( a.isEmpty() ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir o_rRanges.push_back( b ); 59*cdf0e10cSrcweir return; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir if( b.isEmpty() ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir o_rRanges.push_back( a ); 64*cdf0e10cSrcweir return; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir const typename RangeType::ValueType ax(a.getMinX()); 68*cdf0e10cSrcweir const typename RangeType::ValueType ay(a.getMinY()); 69*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType aw(a.getWidth()); 70*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType ah(a.getHeight()); 71*cdf0e10cSrcweir const typename RangeType::ValueType bx(b.getMinX()); 72*cdf0e10cSrcweir const typename RangeType::ValueType by(b.getMinY()); 73*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType bw(b.getWidth()); 74*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType bh(b.getHeight()); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType h0( (by > ay) ? by - ay : 0 ); 77*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType h3( (by + bh < ay + ah) ? ay + ah - by - bh : 0 ); 78*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType w1( (bx > ax) ? bx - ax : 0 ); 79*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType w2( (ax + aw > bx + bw) ? ax + aw - bx - bw : 0 ); 80*cdf0e10cSrcweir const typename RangeType::TraitsType::DifferenceType h12( (h0 + h3 < ah) ? ah - h0 - h3 : 0 ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // TODO(E2): Use numeric_cast instead of static_cast here, 83*cdf0e10cSrcweir // need range checks! 84*cdf0e10cSrcweir if (h0 > 0) 85*cdf0e10cSrcweir o_rRanges.push_back( 86*cdf0e10cSrcweir RangeType(ax,ay, 87*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ax+aw), 88*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0)) ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir if (w1 > 0 && h12 > 0) 91*cdf0e10cSrcweir o_rRanges.push_back( 92*cdf0e10cSrcweir RangeType(ax, 93*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0), 94*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ax+w1), 95*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0+h12)) ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir if (w2 > 0 && h12 > 0) 98*cdf0e10cSrcweir o_rRanges.push_back( 99*cdf0e10cSrcweir RangeType(static_cast<typename RangeType::ValueType>(bx+bw), 100*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0), 101*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(bx+bw+w2), 102*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0+h12)) ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if (h3 > 0) 105*cdf0e10cSrcweir o_rRanges.push_back( 106*cdf0e10cSrcweir RangeType(ax, 107*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0+h12), 108*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ax+aw), 109*cdf0e10cSrcweir static_cast<typename RangeType::ValueType>(ay+h0+h12+h3)) ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir ::std::vector< B2IRange >& computeSetDifference( ::std::vector< B2IRange >& o_rResult, 114*cdf0e10cSrcweir const B2IRange& rFirst, 115*cdf0e10cSrcweir const B2IRange& rSecond ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir doComputeSetDifference( o_rResult, rFirst, rSecond ); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir return o_rResult; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ::std::vector< B2DRange >& computeSetDifference( ::std::vector< B2DRange >& o_rResult, 123*cdf0e10cSrcweir const B2DRange& rFirst, 124*cdf0e10cSrcweir const B2DRange& rSecond ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir doComputeSetDifference( o_rResult, rFirst, rSecond ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir return o_rResult; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir ::std::vector< B2IBox >& computeSetDifference( ::std::vector< B2IBox >& o_rResult, 132*cdf0e10cSrcweir const B2IBox& rFirst, 133*cdf0e10cSrcweir const B2IBox& rSecond ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir doComputeSetDifference( o_rResult, rFirst, rSecond ); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir return o_rResult; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir } // end of namespace basegfx 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // eof 143