Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / basegfx / range / b2irange.hxx
blobf1a0b0aaefc2133413ad5edf77ae2b29758ae08c
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/b2ituple.hxx>
28 #include <basegfx/tuple/b2i64tuple.hxx>
29 #include <basegfx/range/basicrange.hxx>
30 #include <basegfx/range/Range2D.hxx>
32 namespace basegfx
34 /** A two-dimensional interval over integers
36 This is a set of real numbers, bounded by a lower and an upper
37 pair. All inbetween values are included in the set (see also
38 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
40 Probably you rather want B2IBox for integers.
42 The set is closed, i.e. the upper and the lower bound are
43 included (if you're used to the notation - we're talking about
44 [a,b] here, compared to half-open [a,b) or open intervals
45 (a,b)).
47 That means, isInside(val) will return true also for values of
48 val=a or val=b.
50 @see B2IBox
52 class B2IRange : public Range2D<sal_Int32, Int32Traits>
54 public:
55 B2IRange()
56 : Range2D()
59 /// Create degenerate interval consisting of a single point
60 explicit B2IRange(const Tuple2D<ValueType>& rTuple)
61 : Range2D(rTuple)
65 /// Create proper interval between the two given points
66 B2IRange(const Tuple2D<ValueType>& rTuple1,
67 const Tuple2D<ValueType>& rTuple2)
68 : Range2D(rTuple1, rTuple2)
72 B2IRange(ValueType x1, ValueType y1, ValueType x2, ValueType y2)
73 : Range2D(x1, y1, x2, y2)
76 /// get lower bound of the set. returns arbitrary values for empty sets.
77 B2IPoint getMinimum() const
79 return B2IPoint(
80 maRangeX.getMinimum(),
81 maRangeY.getMinimum()
85 /// get upper bound of the set. returns arbitrary values for empty sets.
86 B2IPoint getMaximum() const
88 return B2IPoint(
89 maRangeX.getMaximum(),
90 maRangeY.getMaximum()
94 /// return difference between upper and lower point. returns (0,0) for empty sets.
95 B2I64Tuple getRange() const
97 return B2I64Tuple(
98 maRangeX.getRange(),
99 maRangeY.getRange()
104 /** Compute the set difference of the two given ranges
106 This method calculates the symmetric difference (aka XOR)
107 between the two given ranges, and returning the resulting
108 ranges. Thus, the result will contain all areas where one, but
109 not both ranges lie.
111 @param o_rResult
112 Result vector. The up to four difference ranges are returned
113 within this vector
115 @param rFirst
116 The first range
118 @param rSecond
119 The second range
121 @return the input vector
123 BASEGFX_DLLPUBLIC std::vector<B2IRange>& computeSetDifference(
124 std::vector<B2IRange>& o_rResult,
125 const B2IRange& rFirst,
126 const B2IRange& rSecond);
128 /** Write to char stream */
129 template<typename charT, typename traits>
130 inline std::basic_ostream<charT, traits>& operator<<(
131 std::basic_ostream<charT, traits>& stream, const B2IRange& range)
133 if (range.isEmpty())
134 return stream << "EMPTY";
135 else
136 return stream << range.getWidth() << 'x' << range.getHeight() << "@" << range.getMinimum();
139 } // end of namespace basegfx
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */