Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/basegfx/range/b2irange.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/point/b2ipoint.hxx>
27
#include <basegfx/tuple/b2i64tuple.hxx>
28
#include <basegfx/range/basicrange.hxx>
29
#include <basegfx/range/Range2D.hxx>
30
31
namespace basegfx
32
{
33
    /** A two-dimensional interval over integers
34
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).
38
39
        Probably you rather want B2IBox for integers.
40
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)).
45
46
        That means, isInside(val) will return true also for values of
47
        val=a or val=b.
48
49
        @see B2IBox
50
     */
51
    class B2IRange : public Range2D<sal_Int32, Int32Traits>
52
    {
53
    public:
54
        B2IRange()
55
163k
            : Range2D()
56
163k
        {}
57
58
        /// Create degenerate interval consisting of a single point
59
        explicit B2IRange(const Tuple2D<ValueType>& rTuple)
60
0
            : Range2D(rTuple)
61
0
        {
62
0
        }
63
64
        /// Create proper interval between the two given points
65
        B2IRange(const Tuple2D<ValueType>& rTuple1,
66
                 const Tuple2D<ValueType>& rTuple2)
67
0
            : Range2D(rTuple1, rTuple2)
68
0
        {
69
0
        }
70
71
        B2IRange(ValueType x1, ValueType y1, ValueType x2, ValueType y2)
72
2.83M
            : Range2D(x1, y1, x2, y2)
73
2.83M
        {}
74
75
        /// get lower bound of the set. returns arbitrary values for empty sets.
76
        B2IPoint getMinimum() const
77
0
        {
78
0
            return B2IPoint(
79
0
                maRangeX.getMinimum(),
80
0
                maRangeY.getMinimum()
81
0
                );
82
0
        }
83
84
        /// get upper bound of the set. returns arbitrary values for empty sets.
85
        B2IPoint getMaximum() const
86
0
        {
87
0
            return B2IPoint(
88
0
                maRangeX.getMaximum(),
89
0
                maRangeY.getMaximum()
90
0
                );
91
0
        }
92
93
        /// return difference between upper and lower point. returns (0,0) for empty sets.
94
        B2I64Tuple getRange() const
95
0
        {
96
0
            return B2I64Tuple(
97
0
                maRangeX.getRange(),
98
0
                maRangeY.getRange()
99
0
                );
100
0
        }
101
    };
102
103
    /** Compute the set difference of the two given ranges
104
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.
109
110
        @param o_rResult
111
        Result vector. The up to four difference ranges are returned
112
        within this vector
113
114
        @param rFirst
115
        The first range
116
117
        @param rSecond
118
        The second range
119
120
        @return the input vector
121
     */
122
    BASEGFX_DLLPUBLIC std::vector<B2IRange>& computeSetDifference(
123
                                                std::vector<B2IRange>& o_rResult,
124
                                                const B2IRange& rFirst,
125
                                                const B2IRange& rSecond);
126
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)
131
    {
132
        if (range.isEmpty())
133
            return stream << "EMPTY";
134
        else
135
            return stream << range.getWidth() << 'x' << range.getHeight() << "@" << range.getMinimum();
136
    }
137
138
} // end of namespace basegfx
139
140
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */