1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/types.h>
23 #include <basegfx/basegfxdllapi.h>
24 #include <basegfx/tuple/Tuple2D.hxx>
30 /** Base class for all Points/Vectors with two double values
32 This class provides all methods common to Point
33 and Vector classes which are derived from here.
35 @derive Use this class to implement Points or Vectors
36 which are based on two double values
38 class SAL_WARN_UNUSED B2DTuple
: public Tuple2D
<double>
44 The tuple is initialized to (0.0, 0.0)
53 This parameter is used to initialize the X-coordinate
57 This parameter is used to initialize the Y-coordinate
60 B2DTuple(double fX
, double fY
)
64 B2DTuple(Tuple2D
<double> const& rTuple
)
68 /** Create a copy of a 2D integer Tuple
71 The 2D Tuple which will be copied.
73 BASEGFX_DLLPUBLIC
explicit B2DTuple(const B2ITuple
& rTup
);
77 B2DTuple
operator-(void) const
79 return B2DTuple(-mnX
, -mnY
);
82 BASEGFX_DLLPUBLIC
static const B2DTuple
& getEmptyTuple();
88 inline B2DTuple
absolute(const B2DTuple
& rTup
)
96 inline B2DTuple
interpolate(const B2DTuple
& rOld1
, const B2DTuple
& rOld2
, double t
)
113 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
114 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY());
118 inline B2DTuple
average(const B2DTuple
& rOld1
, const B2DTuple
& rOld2
)
121 rtl_math_approxEqual(rOld1
.getX(), rOld2
.getX()) ? rOld1
.getX() : (rOld1
.getX() + rOld2
.getX()) * 0.5,
122 rtl_math_approxEqual(rOld1
.getY(), rOld2
.getY()) ? rOld1
.getY() : (rOld1
.getY() + rOld2
.getY()) * 0.5);
125 inline B2DTuple
operator*(const B2DTuple
& rTup
, double t
)
132 inline B2DTuple
operator*(double t
, const B2DTuple
& rTup
)
139 inline B2DTuple
operator/(const B2DTuple
& rTup
, double t
)
146 /** Round double to nearest integer for 2D tuple
148 @return the nearest integer for this tuple
150 BASEGFX_DLLPUBLIC B2ITuple
fround(const B2DTuple
& rTup
);
151 } // end of namespace basegfx
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */