Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/basegfx/range/b2drange.hxx
Line
Count
Source
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
20
#pragma once
21
22
#include <ostream>
23
#include <vector>
24
25
#include <basegfx/basegfxdllapi.h>
26
#include <basegfx/vector/b2dvector.hxx>
27
#include <basegfx/point/b2dpoint.hxx>
28
#include <basegfx/range/basicrange.hxx>
29
#include <basegfx/range/Range2D.hxx>
30
31
namespace basegfx
32
{
33
    class B2IRange;
34
    class B2DHomMatrix;
35
36
    /** A two-dimensional interval over doubles
37
38
        This is a set of real numbers, bounded by a lower and an upper
39
        pair. All inbetween values are included in the set (see also
40
        http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
41
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)).
46
47
        That means, isInside(val) will return true also for values of
48
        val=a or val=b.
49
50
        @see B1DRange
51
     */
52
    class SAL_WARN_UNUSED B2DRange : public Range2D<double, DoubleTraits>
53
    {
54
    public:
55
        B2DRange()
56
46.0M
            : Range2D()
57
46.0M
        {}
58
59
        /// Create degenerate interval consisting of a single point
60
        explicit B2DRange(const Tuple2D<ValueType>& rTuple)
61
812
            : Range2D(rTuple)
62
812
        {
63
812
        }
64
65
        /// Create proper interval between the two given points
66
        B2DRange(const Tuple2D<ValueType>& rTuple1,
67
                 const Tuple2D<ValueType>& rTuple2)
68
1.57G
            : Range2D(rTuple1, rTuple2)
69
1.57G
        {
70
1.57G
        }
71
72
        B2DRange(ValueType x1, ValueType y1, ValueType x2, ValueType y2)
73
60.8M
            : Range2D(x1, y1, x2, y2)
74
60.8M
        {}
75
76
        BASEGFX_DLLPUBLIC explicit B2DRange(const B2IRange& rRange);
77
78
        /// get lower bound of the set. returns arbitrary values for empty sets.
79
        B2DPoint getMinimum() const
80
3.49k
        {
81
3.49k
            return B2DPoint(
82
3.49k
                maRangeX.getMinimum(),
83
3.49k
                maRangeY.getMinimum()
84
3.49k
                );
85
3.49k
        }
86
87
        /// get upper bound of the set. returns arbitrary values for empty sets.
88
        B2DPoint getMaximum() const
89
1.04k
        {
90
1.04k
            return B2DPoint(
91
1.04k
                maRangeX.getMaximum(),
92
1.04k
                maRangeY.getMaximum()
93
1.04k
                );
94
1.04k
        }
95
96
        /// return difference between upper and lower point. returns (0,0) for empty sets.
97
        B2DVector getRange() const
98
1.75k
        {
99
1.75k
            return B2DVector(
100
1.75k
                maRangeX.getRange(),
101
1.75k
                maRangeY.getRange()
102
1.75k
                );
103
1.75k
        }
104
105
        /// return center point of set. returns (0,0) for empty sets.
106
        B2DPoint getCenter() const
107
6.05k
        {
108
6.05k
            return B2DPoint(
109
6.05k
                maRangeX.getCenter(),
110
6.05k
                maRangeY.getCenter()
111
6.05k
                );
112
6.05k
        }
113
114
        /** Transform Range by given transformation matrix. */
115
        BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix& rMatrix);
116
117
        /** Translate Range (ie. move).
118
            Much faster equivalent of transform(createTranslateB2DHomMatrix(xx)). */
119
        BASEGFX_DLLPUBLIC void translate(double fTranslateX, double fTranslateY);
120
121
        inline void translate(const B2DTuple& rTranslate)
122
41.3M
        {
123
41.3M
            translate(rTranslate.getX(), rTranslate.getY());
124
41.3M
        }
125
126
        /** Transform Range by given transformation matrix.
127
128
            This operation transforms the Range by transforming all four possible
129
            extrema points (corners) of the given range and building a new one.
130
            This means that the range will grow evtl. when a shear and/or rotation
131
            is part of the transformation.
132
        */
133
        BASEGFX_DLLPUBLIC B2DRange& operator*=( const ::basegfx::B2DHomMatrix& rMat );
134
135
        /** Get a range filled with (0.0, 0.0, 1.0, 1.0) */
136
        BASEGFX_DLLPUBLIC static const B2DRange& getUnitB2DRange();
137
    };
138
139
    /** Transform B2DRange by given transformation matrix (see operator*=())
140
    */
141
    B2DRange operator*( const B2DHomMatrix& rMat, const B2DRange& rB2DRange );
142
143
    /** Round double to nearest integer for 2D range
144
145
        @return the nearest integer for this range
146
    */
147
    BASEGFX_DLLPUBLIC B2IRange fround(const B2DRange& rRange);
148
149
    /** Compute the set difference of the two given ranges
150
151
        This method calculates the symmetric difference (aka XOR)
152
        between the two given ranges, and returning the resulting
153
        ranges. Thus, the result will contain all areas where one, but
154
        not both ranges lie.
155
156
        @param o_rResult
157
        Result vector. The up to four difference ranges are returned
158
        within this vector
159
160
        @param rFirst
161
        The first range
162
163
        @param rSecond
164
        The second range
165
166
        @return the input vector
167
     */
168
    BASEGFX_DLLPUBLIC std::vector<B2DRange>& computeSetDifference(
169
                                                std::vector<B2DRange>& o_rResult,
170
                                                const B2DRange& rFirst,
171
                                                const B2DRange& rSecond);
172
173
    /** Write to char stream */
174
    template<typename charT, typename traits>
175
    inline std::basic_ostream<charT, traits>& operator<<(
176
        std::basic_ostream<charT, traits>& stream, const B2DRange& range)
177
0
    {
178
0
        return stream << range.getWidth() << "x" << range.getHeight() << "@" << range.getMinimum();
179
0
    }
180
181
} // end of namespace basegfx
182
183
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */