Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/basegfx/range/b1drange.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 <basegfx/range/basicrange.hxx>
23
#include <ostream>
24
25
26
namespace basegfx
27
{
28
29
    /** A one-dimensional interval over doubles
30
31
        This is a set of real numbers, bounded by a lower and an upper
32
        value. All inbetween values are included in the set (see also
33
        http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
34
35
        The set is closed, i.e. the upper and the lower bound are
36
        included (if you're used to the notation - we're talking about
37
        [a,b] here, compared to half-open [a,b) or open intervals
38
        (a,b)).
39
40
        That means, isInside(val) will return true also for values of
41
        val=a or val=b.
42
     */
43
    class B1DRange
44
    {
45
        ::basegfx::BasicRange< double, DoubleTraits >   maRange;
46
47
    public:
48
0
        B1DRange() {}
49
50
        /// Create degenerate interval consisting of a single double number
51
        explicit B1DRange(double fStartValue)
52
        :   maRange(fStartValue)
53
0
        {
54
0
        }
55
56
        /// Create proper interval between the two given double values
57
        B1DRange(double fStartValue1, double fStartValue2)
58
0
        :   maRange(fStartValue1)
59
0
        {
60
0
            expand(fStartValue2);
61
0
        }
62
63
        /** Check if the interval set is empty
64
65
            @return false, if no value is in this set - having a
66
            single value included will already return true.
67
         */
68
        bool isEmpty() const
69
0
        {
70
0
            return maRange.isEmpty();
71
0
        }
72
73
        bool operator==( const B1DRange& rRange ) const
74
0
        {
75
0
            return (maRange == rRange.maRange);
76
0
        }
77
78
        bool operator!=( const B1DRange& rRange ) const
79
0
        {
80
0
            return (maRange != rRange.maRange);
81
0
        }
82
83
        /// get lower bound of the set. returns arbitrary values for empty sets.
84
        double getMinimum() const
85
0
        {
86
0
            return maRange.getMinimum();
87
0
        }
88
89
        /// get upper bound of the set. returns arbitrary values for empty sets.
90
        double getMaximum() const
91
0
        {
92
0
            return maRange.getMaximum();
93
0
        }
94
95
        /// return difference between upper and lower value. returns 0 for empty sets.
96
        double getRange() const
97
0
        {
98
0
            return maRange.getRange();
99
0
        }
100
101
        /// return middle of upper and lower value. returns 0 for empty sets.
102
        double getCenter() const
103
0
        {
104
0
            return maRange.getCenter();
105
0
        }
106
107
        /// yields true if value is contained in set
108
        bool isInside(double fValue) const
109
0
        {
110
0
            return maRange.isInside(fValue);
111
0
        }
112
113
        /// yields true if rRange at least partly inside set
114
        bool overlaps(const B1DRange& rRange) const
115
0
        {
116
0
            return maRange.overlaps(rRange.maRange);
117
0
        }
118
119
        /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
120
        bool overlapsMore(const B1DRange& rRange) const
121
0
        {
122
0
            return maRange.overlapsMore(rRange.maRange);
123
0
        }
124
125
        /// add fValue to the set, expanding as necessary
126
        void expand(double fValue)
127
0
        {
128
0
            maRange.expand(fValue);
129
0
        }
130
131
        /// add rRange to the set, expanding as necessary
132
        void expand(const B1DRange& rRange)
133
0
        {
134
0
            maRange.expand(rRange.maRange);
135
0
        }
136
137
        /// calc set intersection
138
        void intersect(const B1DRange& rRange)
139
0
        {
140
0
            maRange.intersect(rRange.maRange);
141
0
        }
142
143
        /// clamp value on range
144
        double clamp(double fValue) const
145
0
        {
146
0
            return maRange.clamp(fValue);
147
0
        }
148
    };
149
150
    /** Write to char stream */
151
    template<typename charT, typename traits>
152
    inline std::basic_ostream<charT, traits>& operator<<(
153
        std::basic_ostream<charT, traits>& stream, const B1DRange& range)
154
    {
155
        return stream << "[" << range.getMinimum() << ", " << range.getMaximum() << "]";
156
    }
157
158
} // end of namespace basegfx
159
160
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */