Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / basegfx / range / b2drange.hxx
blobd6cd708609bce66e228575063c71dc49782f481c
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/vector/b2dvector.hxx>
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/tuple/b2dtuple.hxx>
29 #include <basegfx/range/basicrange.hxx>
30 #include <basegfx/range/Range2D.hxx>
32 namespace basegfx
34 class B2IRange;
35 class B2DHomMatrix;
37 /** A two-dimensional interval over doubles
39 This is a set of real numbers, bounded by a lower and an upper
40 pair. All inbetween values are included in the set (see also
41 http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
43 The set is closed, i.e. the upper and the lower bound are
44 included (if you're used to the notation - we're talking about
45 [a,b] here, compared to half-open [a,b) or open intervals
46 (a,b)).
48 That means, isInside(val) will return true also for values of
49 val=a or val=b.
51 @see B1DRange
53 class SAL_WARN_UNUSED B2DRange : public Range2D<double, DoubleTraits>
55 public:
56 B2DRange()
57 : Range2D()
60 /// Create degenerate interval consisting of a single point
61 explicit B2DRange(const Tuple2D<ValueType>& rTuple)
62 : Range2D(rTuple)
66 /// Create proper interval between the two given points
67 B2DRange(const Tuple2D<ValueType>& rTuple1,
68 const Tuple2D<ValueType>& rTuple2)
69 : Range2D(rTuple1, rTuple2)
73 B2DRange(ValueType x1, ValueType y1, ValueType x2, ValueType y2)
74 : Range2D(x1, y1, x2, y2)
77 BASEGFX_DLLPUBLIC explicit B2DRange(const B2IRange& rRange);
79 /// get lower bound of the set. returns arbitrary values for empty sets.
80 B2DPoint getMinimum() const
82 return B2DPoint(
83 maRangeX.getMinimum(),
84 maRangeY.getMinimum()
88 /// get upper bound of the set. returns arbitrary values for empty sets.
89 B2DPoint getMaximum() const
91 return B2DPoint(
92 maRangeX.getMaximum(),
93 maRangeY.getMaximum()
97 /// return difference between upper and lower point. returns (0,0) for empty sets.
98 B2DVector getRange() const
100 return B2DVector(
101 maRangeX.getRange(),
102 maRangeY.getRange()
106 /// return center point of set. returns (0,0) for empty sets.
107 B2DPoint getCenter() const
109 return B2DPoint(
110 maRangeX.getCenter(),
111 maRangeY.getCenter()
115 /** Transform Range by given transformation matrix. */
116 BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix& rMatrix);
118 /** Transform Range by given transformation matrix.
120 This operation transforms the Range by transforming all four possible
121 extrema points (corners) of the given range and building a new one.
122 This means that the range will grow evtl. when a shear and/or rotation
123 is part of the transformation.
125 BASEGFX_DLLPUBLIC B2DRange& operator*=( const ::basegfx::B2DHomMatrix& rMat );
127 /** Get a range filled with (0.0, 0.0, 1.0, 1.0) */
128 BASEGFX_DLLPUBLIC static const B2DRange& getUnitB2DRange();
131 /** Transform B2DRange by given transformation matrix (see operator*=())
133 B2DRange operator*( const B2DHomMatrix& rMat, const B2DRange& rB2DRange );
135 /** Round double to nearest integer for 2D range
137 @return the nearest integer for this range
139 BASEGFX_DLLPUBLIC B2IRange fround(const B2DRange& rRange);
141 /** Compute the set difference of the two given ranges
143 This method calculates the symmetric difference (aka XOR)
144 between the two given ranges, and returning the resulting
145 ranges. Thus, the result will contain all areas where one, but
146 not both ranges lie.
148 @param o_rResult
149 Result vector. The up to four difference ranges are returned
150 within this vector
152 @param rFirst
153 The first range
155 @param rSecond
156 The second range
158 @return the input vector
160 BASEGFX_DLLPUBLIC std::vector<B2DRange>& computeSetDifference(
161 std::vector<B2DRange>& o_rResult,
162 const B2DRange& rFirst,
163 const B2DRange& rSecond);
165 /** Write to char stream */
166 template<typename charT, typename traits>
167 inline std::basic_ostream<charT, traits>& operator<<(
168 std::basic_ostream<charT, traits>& stream, const B2DRange& range)
170 return stream << range.getWidth() << "x" << range.getHeight() << "@" << range.getMinimum();
173 } // end of namespace basegfx
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */