LibreOffice Module basegfx (master) 1
b2dtuple.hxx
Go to the documentation of this file.
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 <sal/types.h>
25
26namespace basegfx
27{
28 class B2ITuple;
29
38 class SAL_WARN_UNUSED B2DTuple : public Tuple2D<double>
39 {
40 public:
41
47 : Tuple2D(0.0, 0.0)
48 {}
49
60 B2DTuple(double fX, double fY)
61 : Tuple2D(fX, fY)
62 {}
63
65 : Tuple2D(rTuple)
66 {}
67
73 BASEGFX_DLLPUBLIC explicit B2DTuple(const B2ITuple& rTup);
74
75 // operators
76
77 B2DTuple operator-(void) const
78 {
79 return B2DTuple(-mfX, -mfY);
80 }
81
82 BASEGFX_DLLPUBLIC static const B2DTuple& getEmptyTuple();
83 };
84
85 // external operators
86
87
88 inline B2DTuple absolute(const B2DTuple& rTup)
89 {
90 B2DTuple aAbs(
91 fabs(rTup.getX()),
92 fabs(rTup.getY()));
93 return aAbs;
94 }
95
96 inline B2DTuple interpolate(const B2DTuple& rOld1, const B2DTuple& rOld2, double t)
97 {
98 if(rOld1 == rOld2)
99 {
100 return rOld1;
101 }
102 else if(0.0 >= t)
103 {
104 return rOld1;
105 }
106 else if(1.0 <= t)
107 {
108 return rOld2;
109 }
110 else
111 {
112 return B2DTuple(
113 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
114 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY());
115 }
116 }
117
118 inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2)
119 {
120 return B2DTuple(
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);
123 }
124
125 inline B2DTuple operator*(const B2DTuple& rTup, double t)
126 {
127 B2DTuple aNew(rTup);
128 aNew *= t;
129 return aNew;
130 }
131
132 inline B2DTuple operator*(double t, const B2DTuple& rTup)
133 {
134 B2DTuple aNew(rTup);
135 aNew *= t;
136 return aNew;
137 }
138
139 inline B2DTuple operator/(const B2DTuple& rTup, double t)
140 {
141 B2DTuple aNew(rTup);
142 aNew /= t;
143 return aNew;
144 }
145
150 BASEGFX_DLLPUBLIC B2ITuple fround(const B2DTuple& rTup);
151} // end of namespace basegfx
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
Base class for all Points/Vectors with two double values.
Definition: b2dtuple.hxx:39
B2DTuple operator-(void) const
Definition: b2dtuple.hxx:77
B2DTuple()
Create a 2D Tuple.
Definition: b2dtuple.hxx:46
B2DTuple(Tuple2D< double > const &rTuple)
Definition: b2dtuple.hxx:64
B2DTuple(double fX, double fY)
Create a 2D Tuple.
Definition: b2dtuple.hxx:60
Base class for all Points/Vectors with two sal_Int32 values.
Definition: b2ituple.hxx:37
TYPE getX() const
Get X-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:63
TYPE getY() const
Get Y-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:66
B2DTuple interpolate(const B2DTuple &rOld1, const B2DTuple &rOld2, double t)
Definition: b2dtuple.hxx:96
B2DTuple average(const B2DTuple &rOld1, const B2DTuple &rOld2)
Definition: b2dtuple.hxx:118
B2DTuple absolute(const B2DTuple &rTup)
Definition: b2dtuple.hxx:88
B2IRange fround(const B2DRange &rRange)
Round double to nearest integer for 2D range.
Definition: b2drange.cxx:64
B2DPoint operator*(const ::basegfx::B2DHomMatrix &rMat, const B2DPoint &rPoint)
Definition: b2dpoint.cxx:43
B2DTuple operator/(const B2DTuple &rTup, double t)
Definition: b2dtuple.hxx:139
double mfY
double mfX
#define SAL_WARN_UNUSED