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