LibreOffice Module basegfx (master) 1
b2xrange.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
22
23namespace basegfx
24{
25 namespace
26 {
33 template< class RangeType > void doComputeSetDifference(
34 std::vector< RangeType >& o_rRanges,
35 const RangeType& a,
36 const RangeType& b )
37 {
38 o_rRanges.clear();
39
40 // special-casing the empty rect case (this will fail most
41 // of the times below, because of the DBL_MIN/MAX special
42 // values denoting emptiness in the rectangle.
43 if( a.isEmpty() )
44 {
45 o_rRanges.push_back( b );
46 return;
47 }
48 if( b.isEmpty() )
49 {
50 o_rRanges.push_back( a );
51 return;
52 }
53
54 const typename RangeType::ValueType ax(a.getMinX());
55 const typename RangeType::ValueType ay(a.getMinY());
56 const typename RangeType::TraitsType::DifferenceType aw(a.getWidth());
57 const typename RangeType::TraitsType::DifferenceType ah(a.getHeight());
58 const typename RangeType::ValueType bx(b.getMinX());
59 const typename RangeType::ValueType by(b.getMinY());
60 const typename RangeType::TraitsType::DifferenceType bw(b.getWidth());
61 const typename RangeType::TraitsType::DifferenceType bh(b.getHeight());
62
63 const typename RangeType::TraitsType::DifferenceType h0( (by > ay) ? by - ay : 0 );
64 const typename RangeType::TraitsType::DifferenceType h3( (by + bh < ay + ah) ? ay + ah - by - bh : 0 );
65 const typename RangeType::TraitsType::DifferenceType w1( (bx > ax) ? bx - ax : 0 );
66 const typename RangeType::TraitsType::DifferenceType w2( (ax + aw > bx + bw) ? ax + aw - bx - bw : 0 );
67 const typename RangeType::TraitsType::DifferenceType h12( (h0 + h3 < ah) ? ah - h0 - h3 : 0 );
68
69 // TODO(E2): Use numeric_cast instead of static_cast here,
70 // need range checks!
71 if (h0 > 0)
72 o_rRanges.push_back(
73 RangeType(ax,ay,
74 static_cast<typename RangeType::ValueType>(ax+aw),
75 static_cast<typename RangeType::ValueType>(ay+h0)) );
76
77 if (w1 > 0 && h12 > 0)
78 o_rRanges.push_back(
79 RangeType(ax,
80 static_cast<typename RangeType::ValueType>(ay+h0),
81 static_cast<typename RangeType::ValueType>(ax+w1),
82 static_cast<typename RangeType::ValueType>(ay+h0+h12)) );
83
84 if (w2 > 0 && h12 > 0)
85 o_rRanges.push_back(
86 RangeType(static_cast<typename RangeType::ValueType>(bx+bw),
87 static_cast<typename RangeType::ValueType>(ay+h0),
88 static_cast<typename RangeType::ValueType>(bx+bw+w2),
89 static_cast<typename RangeType::ValueType>(ay+h0+h12)) );
90
91 if (h3 > 0)
92 o_rRanges.push_back(
93 RangeType(ax,
94 static_cast<typename RangeType::ValueType>(ay+h0+h12),
95 static_cast<typename RangeType::ValueType>(ax+aw),
96 static_cast<typename RangeType::ValueType>(ay+h0+h12+h3)) );
97 }
98 }
99
100 std::vector< B2IRange >& computeSetDifference( std::vector< B2IRange >& o_rResult,
101 const B2IRange& rFirst,
102 const B2IRange& rSecond )
103 {
104 doComputeSetDifference( o_rResult, rFirst, rSecond );
105
106 return o_rResult;
107 }
108
109 std::vector< B2DRange >& computeSetDifference( std::vector< B2DRange >& o_rResult,
110 const B2DRange& rFirst,
111 const B2DRange& rSecond )
112 {
113 doComputeSetDifference( o_rResult, rFirst, rSecond );
114
115 return o_rResult;
116 }
117
118} // end of namespace basegfx
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A two-dimensional interval over doubles.
Definition: b2drange.hxx:54
A two-dimensional interval over integers.
Definition: b2irange.hxx:53
uno_Any a
std::vector< B2IRange > & computeSetDifference(std::vector< B2IRange > &o_rResult, const B2IRange &rFirst, const B2IRange &rSecond)
Compute the set difference of the two given ranges.
Definition: b2xrange.cxx:100