Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/basegfx/point/b2dpoint.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 <tuple>
24
25
#include <basegfx/tuple/b2dtuple.hxx>
26
#include <basegfx/point/b2ipoint.hxx>
27
#include <basegfx/basegfxdllapi.h>
28
#include <basegfx/tuple/Size2D.hxx>
29
30
namespace basegfx
31
{
32
    class B2DHomMatrix;
33
34
    /** Base Point class with two double values
35
36
        This class derives all operators and common handling for
37
        a 2D data class from B2DTuple. All necessary extensions
38
        which are special for points will be added here.
39
40
        @see B2DTuple
41
    */
42
    class SAL_WARN_UNUSED B2DPoint : public ::basegfx::B2DTuple
43
    {
44
    public:
45
        /** Create a 2D Point
46
47
            The point is initialized to (0.0, 0.0)
48
        */
49
        B2DPoint()
50
120M
        {}
51
52
        /** Create a 2D Point
53
54
            @param fX
55
            This parameter is used to initialize the X-coordinate
56
            of the 2D Point.
57
58
            @param fY
59
            This parameter is used to initialize the Y-coordinate
60
            of the 2D Point.
61
        */
62
        B2DPoint(double fX, double fY)
63
790M
        :   B2DTuple(fX, fY)
64
790M
        {}
65
66
        /** Create a copy of a 2D Point
67
68
            @param rPoint
69
            The 2D Point which will be copied.
70
        */
71
        explicit B2DPoint(const ::basegfx::B2IPoint& rPoint)
72
        :   B2DTuple(rPoint)
73
0
        {}
74
75
        /** constructor with tuple to allow copy-constructing
76
            from B2DTuple-based classes
77
        */
78
        B2DPoint(Tuple2D<double> const& rTuple)
79
334M
        :   B2DTuple(rTuple)
80
334M
        {}
81
82
        /** create a point from a size object */
83
        explicit B2DPoint(Size2D<double> const& rSize)
84
            : B2DTuple(rSize.getWidth(), rSize.getHeight())
85
0
        {}
86
87
        /** *=operator to allow usage from B2DPoint, too
88
        */
89
        B2DPoint& operator*=( const B2DPoint& rPnt )
90
0
        {
91
0
            mnX *= rPnt.mnX;
92
0
            mnY *= rPnt.mnY;
93
0
            return *this;
94
0
        }
95
96
        /** *=operator to allow usage from B2DPoint, too
97
        */
98
        B2DPoint& operator*=(double t)
99
0
        {
100
0
            mnX *= t;
101
0
            mnY *= t;
102
0
            return *this;
103
0
        }
104
105
        /** assignment operator to allow assigning the results
106
            of B2DTuple calculations
107
        */
108
        BASEGFX_DLLPUBLIC B2DPoint& operator=(const Tuple2D<double>& rPoint)
109
1.75M
        {
110
1.75M
            mnX = rPoint.getX();
111
1.75M
            mnY = rPoint.getY();
112
1.75M
            return *this;
113
1.75M
        }
114
115
        /** Transform point by given transformation matrix.
116
117
            The translational components of the matrix are, in
118
            contrast to B2DVector, applied.
119
        */
120
        BASEGFX_DLLPUBLIC B2DPoint& operator*=( const ::basegfx::B2DHomMatrix& rMat );
121
122
        static const B2DPoint& getEmptyPoint()
123
0
        {
124
0
            return static_cast<const B2DPoint&>( ::basegfx::B2DTuple::getEmptyTuple() );
125
0
        }
126
127
        friend auto operator <=>(B2DPoint const & a, B2DPoint const & b)
128
50.3M
        {
129
50.3M
            return std::tie(a.mnX, a.mnY) <=> std::tie(b.mnX, b.mnY);
130
50.3M
        }
131
    };
132
133
    // external operators
134
135
    /** Transform B2DPoint by given transformation matrix.
136
137
        Since this is a Point, translational components of the
138
        matrix are used.
139
    */
140
    BASEGFX_DLLPUBLIC B2DPoint operator*( const B2DHomMatrix& rMat, const B2DPoint& rPoint );
141
142
    template< typename charT, typename traits >
143
    inline std::basic_ostream<charT, traits> & operator <<(
144
        std::basic_ostream<charT, traits> & stream, const B2DPoint& point )
145
0
    {
146
0
        return stream << "(" << point.getX() << "," << point.getY() << ")";
147
0
    }
148
149
} // end of namespace basegfx
150
151
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */