Debian Codegraph @

src/Base/Placement.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2006 Jürgen Riegel <[email protected]> *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Library General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Library General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Library General Public *
19 * License along with this library; see the file COPYING.LIB. If not, *
20 * write to the Free Software Foundation, Inc., 59 Temple Place, *
21 * Suite 330, Boston, MA 02111-1307, USA *
22 * *
23 ***************************************************************************/
24
25 #ifndef BASE_PLACEMENT_H
26 #define BASE_PLACEMENT_H
27
28 #include <string>
29
30 #include "Rotation.h"
31
32
33 namespace Base
34 {
35
36 class DualQuat;
37 class Matrix4D;
38
39 template<typename T>
40 class Vector3;
41 using Vector3d = Vector3<double>;
42
43 /**
44 * The Placement class.
45 */
46 class BaseExport Placement
47 {
48 public:
49 /// default constructor
50 Placement();
51 Placement(const Placement&) = default;
52 Placement(Placement&&) = default;
53 Placement(const Base::Matrix4D& matrix);
54 Placement(const Vector3d& Pos, const Rotation& Rot);
55 Placement(const Vector3d& Pos, const Rotation& Rot, const Vector3d& Cnt);
56
57 /** specialty constructors */
58 //@{
59 static Placement fromDualQuaternion(DualQuat qq);
60 //@}
61
62 /// Destruction
63 ~Placement() = default;
64
65 Matrix4D toMatrix() const;
66 void fromMatrix(const Matrix4D& m);
67 DualQuat toDualQuaternion() const;
68 const Vector3d& getPosition() const
69 {
70 return _pos;
71 }
72 const Rotation& getRotation() const
73 {
74 return _rot;
75 }
76 void setPosition(const Vector3d& Pos)
77 {
78 _pos = Pos;
79 }
80 void setRotation(const Rotation& Rot)
81 {
82 _rot = Rot;
83 }
84
85 bool isIdentity() const;
86 bool isIdentity(double tol) const;
87 void invert();
88 Placement inverse() const;
89 void move(const Vector3d& MovVec);
90
91 bool isSame(const Placement&) const;
92 bool isSame(const Placement&, double tol) const;
93
94 /** Operators. */
95 //@{
96 Placement& operator*=(const Placement& p);
97 Placement operator*(const Placement& p) const;
98 bool operator==(const Placement&) const;
99 bool operator!=(const Placement&) const;
100 Placement& operator=(const Placement&) = default;
101 Placement& operator=(Placement&&) = default;
102 Placement pow(double t, bool shorten = true) const;
103
104 Placement& multRight(const Base::Placement& p);
105 Placement& multLeft(const Base::Placement& p);
106
107 void multVec(const Vector3d& src, Vector3d& dst) const;
108 void multVec(const Vector3f& src, Vector3f& dst) const;
109 //@}
110
111 static Placement slerp(const Placement& p0, const Placement& p1, double t);
112 static Placement sclerp(const Placement& p0, const Placement& p1, double t, bool shorten = true);
113
114 /// Returns string representation of the placement, useful for debugging
115 std::string toString() const;
116
117 private:
118 Vector3<double> _pos;
119 Base::Rotation _rot;
120 };
121
122 } // namespace Base
123
124
125 #endif // BASE_PLACEMENT_H