cool#10610 Ensure the parent-child relations of comments.
[LibreOffice.git] / include / basegfx / point / b2dpoint.hxx
blob94140aa6f5e1c1e68d09e17e536f8ba56ab24037
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 <compare>
23 #include <ostream>
24 #include <tuple>
26 #include <basegfx/tuple/b2dtuple.hxx>
27 #include <basegfx/point/b2ipoint.hxx>
28 #include <basegfx/basegfxdllapi.h>
29 #include <basegfx/tuple/Size2D.hxx>
31 namespace basegfx
33 class B2DHomMatrix;
35 /** Base Point class with two double values
37 This class derives all operators and common handling for
38 a 2D data class from B2DTuple. All necessary extensions
39 which are special for points will be added here.
41 @see B2DTuple
43 class SAL_WARN_UNUSED B2DPoint : public ::basegfx::B2DTuple
45 public:
46 /** Create a 2D Point
48 The point is initialized to (0.0, 0.0)
50 B2DPoint()
53 /** Create a 2D Point
55 @param fX
56 This parameter is used to initialize the X-coordinate
57 of the 2D Point.
59 @param fY
60 This parameter is used to initialize the Y-coordinate
61 of the 2D Point.
63 B2DPoint(double fX, double fY)
64 : B2DTuple(fX, fY)
67 /** Create a copy of a 2D Point
69 @param rPoint
70 The 2D Point which will be copied.
72 explicit B2DPoint(const ::basegfx::B2IPoint& rPoint)
73 : B2DTuple(rPoint)
76 /** constructor with tuple to allow copy-constructing
77 from B2DTuple-based classes
79 B2DPoint(Tuple2D<double> const& rTuple)
80 : B2DTuple(rTuple)
83 /** create a point from a size object */
84 explicit B2DPoint(Size2D<double> const& rSize)
85 : B2DTuple(rSize.getWidth(), rSize.getHeight())
88 /** *=operator to allow usage from B2DPoint, too
90 B2DPoint& operator*=( const B2DPoint& rPnt )
92 mnX *= rPnt.mnX;
93 mnY *= rPnt.mnY;
94 return *this;
97 /** *=operator to allow usage from B2DPoint, too
99 B2DPoint& operator*=(double t)
101 mnX *= t;
102 mnY *= t;
103 return *this;
106 /** assignment operator to allow assigning the results
107 of B2DTuple calculations
109 BASEGFX_DLLPUBLIC B2DPoint& operator=(Tuple2D<double>& rPoint)
111 mnX = rPoint.getX();
112 mnY = rPoint.getY();
113 return *this;
116 /** Transform point by given transformation matrix.
118 The translational components of the matrix are, in
119 contrast to B2DVector, applied.
121 BASEGFX_DLLPUBLIC B2DPoint& operator*=( const ::basegfx::B2DHomMatrix& rMat );
123 static const B2DPoint& getEmptyPoint()
125 return static_cast<const B2DPoint&>( ::basegfx::B2DTuple::getEmptyTuple() );
128 friend auto operator <=>(B2DPoint const & a, B2DPoint const & b)
130 // Avoid compilation failure with Android NDK 23.2, where std::tuple operator <=> isn't
131 // yet implemented (and where __cpp_lib_three_way_comparison happens to not be defined
132 // in <compare>, so discriminate on that):
133 #if defined __cpp_lib_three_way_comparison
134 return std::tie(a.mnX, a.mnY) <=> std::tie(b.mnX, b.mnY);
135 #else
136 auto const comp = a.mnX <=> b.mnX;
137 return comp == 0 ? a.mnY <=> b.mnY : comp;
138 #endif
142 // external operators
144 /** Transform B2DPoint by given transformation matrix.
146 Since this is a Point, translational components of the
147 matrix are used.
149 BASEGFX_DLLPUBLIC B2DPoint operator*( const B2DHomMatrix& rMat, const B2DPoint& rPoint );
151 template< typename charT, typename traits >
152 inline std::basic_ostream<charT, traits> & operator <<(
153 std::basic_ostream<charT, traits> & stream, const B2DPoint& point )
155 return stream << "(" << point.getX() << "," << point.getY() << ")";
158 } // end of namespace basegfx
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */