ACF $AcfVersion:0$
CSplineSegment.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <istd/IChangeable.h>
7
8#include <i2d/CVector2d.h>
9
10
11namespace i2d
12{
13
14
20class CSplineSegment: virtual public istd::IChangeable
21{
22public:
27 virtual i2d::CVector2d GetPointInSegment(double position) const;
28
33 virtual i2d::CVector2d GetDerivationInSegment(double position) const;
34
38 virtual i2d::CVector2d GetDerivationBegin() const;
39
43 virtual i2d::CVector2d GetDerivationEnd() const;
44
48 virtual i2d::CVector2d GetPointBegin() const;
49
53 virtual i2d::CVector2d GetPointEnd() const;
54
58 virtual i2d::CVector2d GetBezierPointBegin() const;
59
63 virtual i2d::CVector2d GetBezierPointEnd() const;
64
68 virtual bool IsCloserThan(const i2d::CVector2d position, double distance) const;
69
73 virtual void GetHalfSegmentFirst(CSplineSegment& result) const;
74
78 virtual void GetHalfSegmentSecond(CSplineSegment& result) const;
79
84 const i2d::CVector2d& A() const;
89 void A(const i2d::CVector2d& value);
94 const i2d::CVector2d& B() const;
99 void B(const i2d::CVector2d& value);
104 const i2d::CVector2d& C() const;
109 void C(const i2d::CVector2d& value);
114 const i2d::CVector2d& D() const;
119 void D(const i2d::CVector2d& value);
120
121 // reimplemented (istd::IChangeable)
122 virtual int GetSupportedOperations() const override;
123 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
125
126private:
127 i2d::CVector2d m_a;
128 i2d::CVector2d m_b;
129 i2d::CVector2d m_c;
130 i2d::CVector2d m_d;
131};
132
133
135{
136 return ((m_a * position + m_b) * position + m_c) * position + m_d;
137}
138
139
141{
142 return (m_a * (3 * position) + m_b * 2) * position + m_c;
143}
144
145
147{
148 return m_c;
149}
150
151
153{
154 return m_a * 3 + m_b * 2 + m_c;
155}
156
157
159{
160 return m_d;
161}
162
163
165{
166 return m_a + m_b + m_c + m_d;
167}
168
169
171{
172 return m_d + m_c / 3;
173}
174
175
177{
178 return m_c + m_d + (m_b - m_c) / 3;
179}
180
181
183{
184 result.m_a = m_a * 0.125;
185 result.m_b = m_b * 0.25;
186 result.m_c = m_c * 0.5;
187 result.m_d = m_d;
188}
189
190
192{
193 result.m_a = m_a * 0.125;
194 result.m_b = m_a * 0.375 + m_b * 0.25;
195 result.m_c = m_a * 0.375 + (m_b + m_c) * 0.5;
196 result.m_d = m_a * 0.125 + m_b * 0.25 + m_c * 0.5 + m_d;
197}
198
199
200// acces to members
201
203{
204 return m_a;
205}
206
207
208inline void CSplineSegment::A(const i2d::CVector2d& value)
209{
210 m_a = value;
211}
212
213
215{
216 return m_b;
217}
218
219
220inline void CSplineSegment::B(const i2d::CVector2d& value)
221{
222 m_b = value;
223}
224
225
227{
228 return m_c;
229}
230
231
232inline void CSplineSegment::C(const i2d::CVector2d& value)
233{
234 m_c = value;
235}
236
237
239{
240 return m_d;
241}
242
243
244inline void CSplineSegment::D(const i2d::CVector2d& value)
245{
246 m_d = value;
247}
248
249
250} // namespace i2d
251
252
Represents a single cubic polynomial segment of a spline curve.
const i2d::CVector2d & C() const
Get linear coefficient C (coefficient of t term).
virtual i2d::CVector2d GetDerivationInSegment(double position) const
Get derivation.
const i2d::CVector2d & D() const
Get constant coefficient D (constant term).
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
virtual bool IsCloserThan(const i2d::CVector2d position, double distance) const
Check, if segment is closer than specifier distance.
virtual i2d::CVector2d GetPointInSegment(double position) const
Get point.
virtual i2d::CVector2d GetBezierPointBegin() const
Get first Bezier's control point.
virtual i2d::CVector2d GetPointBegin() const
Get begin point.
virtual int GetSupportedOperations() const override
Get set of flags for supported operations.
virtual void GetHalfSegmentFirst(CSplineSegment &result) const
Get a first half segment.
virtual void GetHalfSegmentSecond(CSplineSegment &result) const
Get a second half segment.
const i2d::CVector2d & A() const
Get cubic coefficient A (coefficient of t^3 term).
virtual i2d::CVector2d GetDerivationBegin() const
Get derivation in begin point.
virtual i2d::CVector2d GetBezierPointEnd() const
Get second Bezier's control point.
virtual i2d::CVector2d GetDerivationEnd() const
Get derivation in end point.
virtual istd::TUniqueInterfacePtr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
const i2d::CVector2d & B() const
Get quadratic coefficient B (coefficient of t^2 term).
virtual i2d::CVector2d GetPointEnd() const
Get end point.
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
Unique ownership smart pointer for interface types.
Contains the 2D objects.
Definition CAffine2d.h:11