cid#1607257 Overflowed constant
[LibreOffice.git] / include / basegfx / range / b2irange.hxx
blob602e64eddbad3cfaf909bf1dd867372b7bdcc66b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <ostream>
23 #include <vector>
25 #include <basegfx/basegfxdllapi.h>
26 #include <basegfx/point/b2ipoint.hxx>
27 #include <basegfx/tuple/b2i64tuple.hxx>
28 #include <basegfx/range/basicrange.hxx>
29 #include <basegfx/range/Range2D.hxx>
31 namespace basegfx
33 /** A two-dimensional interval over integers
35 This is a set of real numbers, bounded by a lower and an upper
36 pair. All inbetween values are included in the set (see also
37 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
39 Probably you rather want B2IBox for integers.
41 The set is closed, i.e. the upper and the lower bound are
42 included (if you're used to the notation - we're talking about
43 [a,b] here, compared to half-open [a,b) or open intervals
44 (a,b)).
46 That means, isInside(val) will return true also for values of
47 val=a or val=b.
49 @see B2IBox
51 class B2IRange : public Range2D<sal_Int32, Int32Traits>
53 public:
54 B2IRange()
55 : Range2D()
58 /// Create degenerate interval consisting of a single point
59 explicit B2IRange(const Tuple2D<ValueType>& rTuple)
60 : Range2D(rTuple)
64 /// Create proper interval between the two given points
65 B2IRange(const Tuple2D<ValueType>& rTuple1,
66 const Tuple2D<ValueType>& rTuple2)
67 : Range2D(rTuple1, rTuple2)
71 B2IRange(ValueType x1, ValueType y1, ValueType x2, ValueType y2)
72 : Range2D(x1, y1, x2, y2)
75 /// get lower bound of the set. returns arbitrary values for empty sets.
76 B2IPoint getMinimum() const
78 return B2IPoint(
79 maRangeX.getMinimum(),
80 maRangeY.getMinimum()
84 /// get upper bound of the set. returns arbitrary values for empty sets.
85 B2IPoint getMaximum() const
87 return B2IPoint(
88 maRangeX.getMaximum(),
89 maRangeY.getMaximum()
93 /// return difference between upper and lower point. returns (0,0) for empty sets.
94 B2I64Tuple getRange() const
96 return B2I64Tuple(
97 maRangeX.getRange(),
98 maRangeY.getRange()
103 /** Compute the set difference of the two given ranges
105 This method calculates the symmetric difference (aka XOR)
106 between the two given ranges, and returning the resulting
107 ranges. Thus, the result will contain all areas where one, but
108 not both ranges lie.
110 @param o_rResult
111 Result vector. The up to four difference ranges are returned
112 within this vector
114 @param rFirst
115 The first range
117 @param rSecond
118 The second range
120 @return the input vector
122 BASEGFX_DLLPUBLIC std::vector<B2IRange>& computeSetDifference(
123 std::vector<B2IRange>& o_rResult,
124 const B2IRange& rFirst,
125 const B2IRange& rSecond);
127 /** Write to char stream */
128 template<typename charT, typename traits>
129 inline std::basic_ostream<charT, traits>& operator<<(
130 std::basic_ostream<charT, traits>& stream, const B2IRange& range)
132 if (range.isEmpty())
133 return stream << "EMPTY";
134 else
135 return stream << range.getWidth() << 'x' << range.getHeight() << "@" << range.getMinimum();
138 } // end of namespace basegfx
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */