1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b2xrange.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basegfx.hxx"
34 #include <basegfx/range/b2drange.hxx>
35 #include <basegfx/range/b2irange.hxx>
36 #include <basegfx/range/b2ibox.hxx>
43 /** Generic implementation of the difference set computation
46 Type to operate on. Must provide ValueType and TraitsType
49 template< class RangeType
> void doComputeSetDifference(
50 ::std::vector
< RangeType
>& o_rRanges
,
56 // special-casing the empty rect case (this will fail most
57 // of the times below, because of the DBL_MIN/MAX special
58 // values denoting emptyness in the rectangle.
61 o_rRanges
.push_back( b
);
66 o_rRanges
.push_back( a
);
70 const typename
RangeType::ValueType
ax(a
.getMinX());
71 const typename
RangeType::ValueType
ay(a
.getMinY());
72 const typename
RangeType::TraitsType::DifferenceType
aw(a
.getWidth());
73 const typename
RangeType::TraitsType::DifferenceType
ah(a
.getHeight());
74 const typename
RangeType::ValueType
bx(b
.getMinX());
75 const typename
RangeType::ValueType
by(b
.getMinY());
76 const typename
RangeType::TraitsType::DifferenceType
bw(b
.getWidth());
77 const typename
RangeType::TraitsType::DifferenceType
bh(b
.getHeight());
79 const typename
RangeType::TraitsType::DifferenceType
h0( (by
> ay
) ? by
- ay
: 0 );
80 const typename
RangeType::TraitsType::DifferenceType
h3( (by
+ bh
< ay
+ ah
) ? ay
+ ah
- by
- bh
: 0 );
81 const typename
RangeType::TraitsType::DifferenceType
w1( (bx
> ax
) ? bx
- ax
: 0 );
82 const typename
RangeType::TraitsType::DifferenceType
w2( (ax
+ aw
> bx
+ bw
) ? ax
+ aw
- bx
- bw
: 0 );
83 const typename
RangeType::TraitsType::DifferenceType
h12( (h0
+ h3
< ah
) ? ah
- h0
- h3
: 0 );
85 // TODO(E2): Use numeric_cast instead of static_cast here,
90 static_cast<typename
RangeType::ValueType
>(ax
+aw
),
91 static_cast<typename
RangeType::ValueType
>(ay
+h0
)) );
93 if (w1
> 0 && h12
> 0)
96 static_cast<typename
RangeType::ValueType
>(ay
+h0
),
97 static_cast<typename
RangeType::ValueType
>(ax
+w1
),
98 static_cast<typename
RangeType::ValueType
>(ay
+h0
+h12
)) );
100 if (w2
> 0 && h12
> 0)
102 RangeType(static_cast<typename
RangeType::ValueType
>(bx
+bw
),
103 static_cast<typename
RangeType::ValueType
>(ay
+h0
),
104 static_cast<typename
RangeType::ValueType
>(bx
+bw
+w2
),
105 static_cast<typename
RangeType::ValueType
>(ay
+h0
+h12
)) );
110 static_cast<typename
RangeType::ValueType
>(ay
+h0
+h12
),
111 static_cast<typename
RangeType::ValueType
>(ax
+aw
),
112 static_cast<typename
RangeType::ValueType
>(ay
+h0
+h12
+h3
)) );
116 ::std::vector
< B2IRange
>& computeSetDifference( ::std::vector
< B2IRange
>& o_rResult
,
117 const B2IRange
& rFirst
,
118 const B2IRange
& rSecond
)
120 doComputeSetDifference( o_rResult
, rFirst
, rSecond
);
125 ::std::vector
< B2DRange
>& computeSetDifference( ::std::vector
< B2DRange
>& o_rResult
,
126 const B2DRange
& rFirst
,
127 const B2DRange
& rSecond
)
129 doComputeSetDifference( o_rResult
, rFirst
, rSecond
);
134 ::std::vector
< B2IBox
>& computeSetDifference( ::std::vector
< B2IBox
>& o_rResult
,
135 const B2IBox
& rFirst
,
136 const B2IBox
& rSecond
)
138 doComputeSetDifference( o_rResult
, rFirst
, rSecond
);
143 } // end of namespace basegfx