Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 59f16b5

Browse files
committed
cleanup
1 parent 3e96b8f commit 59f16b5

File tree

2 files changed

+55
-136
lines changed

2 files changed

+55
-136
lines changed

desktop/interpolationEngines/src/main/kotlin/curves/ArcSpline.kt

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package curves
1818
import java.util.*
1919

2020
/**
21-
* This provides provides a curve fit system that stitches the x,y path together with
21+
* This provides a curve fit system that stitches the x,y path together with
2222
* quarter ellipses
2323
*/
2424
class ArcSpline(arcModes: IntArray, val timePoints: FloatArray, y: List<FloatArray>) {
@@ -54,7 +54,10 @@ class ArcSpline(arcModes: IntArray, val timePoints: FloatArray, y: List<FloatArr
5454
}
5555
}
5656

57-
fun getPosf(t: Float, v: FloatArray) {
57+
/**
58+
* get the values of the at t point in time.
59+
*/
60+
fun getPos(t: Float, v: FloatArray) {
5861
var t = t
5962
if (mExtrapolate) {
6063
if (t < mArcs[0]!!.mTime1) {
@@ -108,59 +111,9 @@ class ArcSpline(arcModes: IntArray, val timePoints: FloatArray, y: List<FloatArr
108111
}
109112
}
110113

111-
fun getPos(t: Float, v: FloatArray) {
112-
var t = t
113-
if (mExtrapolate) {
114-
if (t < mArcs[0]!!.mTime1) {
115-
val t0 = mArcs[0]!!.mTime1
116-
val dt = t - mArcs[0]!!.mTime1
117-
val p = 0
118-
if (mArcs[p]!!.mLinear) {
119-
v[0] = (mArcs[p]!!.getLinearX(t0) + dt * mArcs[p]!!.getLinearDX(t0))
120-
v[1] = (mArcs[p]!!.getLinearY(t0) + dt * mArcs[p]!!.getLinearDY(t0))
121-
} else {
122-
mArcs[p]!!.setPoint(t0)
123-
v[0] = (mArcs[p]!!.calcX() + dt * mArcs[p]!!.calcDX())
124-
v[1] = (mArcs[p]!!.calcY() + dt * mArcs[p]!!.calcDY())
125-
}
126-
return
127-
}
128-
if (t > mArcs[mArcs.size - 1]!!.mTime2) {
129-
val t0 = mArcs[mArcs.size - 1]!!.mTime2
130-
val dt = t - t0
131-
val p = mArcs.size - 1
132-
if (mArcs[p]!!.mLinear) {
133-
v[0] = (mArcs[p]!!.getLinearX(t0) + dt * mArcs[p]!!.getLinearDX(t0))
134-
v[1] = (mArcs[p]!!.getLinearY(t0) + dt * mArcs[p]!!.getLinearDY(t0))
135-
} else {
136-
mArcs[p]!!.setPoint(t)
137-
v[0] = mArcs[p]!!.calcX()
138-
v[1] = mArcs[p]!!.calcY()
139-
}
140-
return
141-
}
142-
} else {
143-
if (t < mArcs[0]!!.mTime1) {
144-
t = mArcs[0]!!.mTime1
145-
} else if (t > mArcs[mArcs.size - 1]!!.mTime2) {
146-
t = mArcs[mArcs.size - 1]!!.mTime2
147-
}
148-
}
149-
for (i in mArcs.indices) {
150-
if (t <= mArcs[i]!!.mTime2) {
151-
if (mArcs[i]!!.mLinear) {
152-
v[0] = mArcs[i]!!.getLinearX(t)
153-
v[1] = mArcs[i]!!.getLinearY(t)
154-
return
155-
}
156-
mArcs[i]!!.setPoint(t)
157-
v[0] = mArcs[i]!!.calcX()
158-
v[1] = mArcs[i]!!.calcY()
159-
return
160-
}
161-
}
162-
}
163-
114+
/**
115+
* Get the differential which of the curves at point t
116+
*/
164117
fun getSlope(t: Float, v: FloatArray) {
165118
var t = t
166119
if (t < mArcs[0]!!.mTime1) {
@@ -183,6 +136,9 @@ class ArcSpline(arcModes: IntArray, val timePoints: FloatArray, y: List<FloatArr
183136
}
184137
}
185138

139+
/**
140+
* get the value of the j'th curve at point in time t
141+
*/
186142
fun getPos(t: Float, j: Int): Float {
187143
var t = t
188144
if (mExtrapolate) {
@@ -232,6 +188,9 @@ class ArcSpline(arcModes: IntArray, val timePoints: FloatArray, y: List<FloatArr
232188
return Float.NaN
233189
}
234190

191+
/**
192+
* Get the slope of j'th curve at time t
193+
*/
235194
fun getSlope(t: Float, j: Int): Float {
236195
var t = t
237196
if (t < mArcs[0]!!.mTime1) {

desktop/interpolationEngines/src/main/kotlin/curves/MonoSpline.kt

Lines changed: 41 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package curves
1818
/**
1919
* This performs a spline interpolation in multiple dimensions
2020
*
21-
*
2221
*/
2322
class MonoSpline(time: FloatArray, y: List<FloatArray>) {
24-
val timePoints: FloatArray
23+
private val timePoints: FloatArray
2524
var mY: ArrayList<FloatArray>
26-
var mTangent: ArrayList<FloatArray>
25+
private var mTangent: ArrayList<FloatArray>
2726
private val mExtrapolate = true
28-
var mSlopeTemp: FloatArray
27+
private var mSlopeTemp: FloatArray
28+
2929
fun makeFloatArray(a: Int, b: Int): ArrayList<FloatArray> {
3030
val ret = ArrayList<FloatArray>() //new Float[a][b];
3131
for (i in 0 until a) {
@@ -135,59 +135,6 @@ class MonoSpline(time: FloatArray, y: List<FloatArray>) {
135135
}
136136
}
137137

138-
fun getPos2(t: Float, v: FloatArray) {
139-
val n = timePoints.size
140-
val dim = mY[0].size
141-
if (mExtrapolate) {
142-
if (t <= timePoints[0]) {
143-
getSlope(timePoints[0], mSlopeTemp)
144-
for (j in 0 until dim) {
145-
v[j] = (mY[0][j] + (t - timePoints[0]) * mSlopeTemp[j]).toFloat()
146-
}
147-
return
148-
}
149-
if (t >= timePoints[n - 1]) {
150-
getSlope(timePoints[n - 1], mSlopeTemp)
151-
for (j in 0 until dim) {
152-
v[j] = (mY[n - 1][j] + (t - timePoints[n - 1]) * mSlopeTemp[j]).toFloat()
153-
}
154-
return
155-
}
156-
} else {
157-
if (t <= timePoints[0]) {
158-
for (j in 0 until dim) {
159-
v[j] = mY[0][j].toFloat()
160-
}
161-
return
162-
}
163-
if (t >= timePoints[n - 1]) {
164-
for (j in 0 until dim) {
165-
v[j] = mY[n - 1][j].toFloat()
166-
}
167-
return
168-
}
169-
}
170-
for (i in 0 until n - 1) {
171-
if (t == timePoints[i]) {
172-
for (j in 0 until dim) {
173-
v[j] = mY[i][j].toFloat()
174-
}
175-
}
176-
if (t < timePoints[i + 1]) {
177-
val h = timePoints[i + 1] - timePoints[i]
178-
val x = (t - timePoints[i]) / h
179-
for (j in 0 until dim) {
180-
val y1 = mY[i][j]
181-
val y2 = mY[i + 1][j]
182-
val t1 = mTangent[i][j]
183-
val t2 = mTangent[i + 1][j]
184-
v[j] = interpolate(h, x, y1, y2, t1, t2).toFloat()
185-
}
186-
return
187-
}
188-
}
189-
}
190-
191138
fun getPos(t: Float, j: Int): Float {
192139
val n = timePoints.size
193140
if (mExtrapolate) {
@@ -270,30 +217,43 @@ class MonoSpline(time: FloatArray, y: List<FloatArray>) {
270217
return 0.0f // should never reach here
271218
}
272219

273-
companion object {
274-
/**
275-
* Cubic Hermite spline
276-
*/
277-
private fun interpolate(
278-
h: Float,
279-
x: Float,
280-
y1: Float,
281-
y2: Float,
282-
t1: Float,
283-
t2: Float
284-
): Float {
285-
val x2 = x * x
286-
val x3 = x2 * x
287-
return (-2 * x3 * y2 + 3 * x2 * y2 + 2 * x3 * y1 - 3 * x2 * y1 + y1 + h * t2 * x3 + h * t1 * x3 - h * t2 * x2 - 2 * h * t1 * x2
288-
+ h * t1 * x)
289-
}
220+
/**
221+
* Cubic Hermite spline
222+
*/
223+
private fun interpolate(
224+
h: Float,
225+
x: Float,
226+
y1: Float,
227+
y2: Float,
228+
t1: Float,
229+
t2: Float
230+
): Float {
231+
val x2 = x * x
232+
val x3 = x2 * x
233+
return (-2 * x3 * y2
234+
+ 3 * x2 * y2
235+
+ 2 * x3 * y1
236+
- 3 * x2 * y1
237+
+ y1 + h * t2 * x3
238+
+ h * t1 * x3
239+
- h * t2 * x2
240+
- 2 * h * t1 * x2
241+
+ h * t1 * x)
242+
}
290243

291-
/**
292-
* Cubic Hermite spline slope differentiated
293-
*/
294-
private fun diff(h: Float, x: Float, y1: Float, y2: Float, t1: Float, t2: Float): Float {
295-
val x2 = x * x
296-
return -6 * x2 * y2 + 6 * x * y2 + 6 * x2 * y1 - 6 * x * y1 + 3 * h * t2 * x2 + 3 * h * t1 * x2 - 2 * h * t2 * x - 4 * h * t1 * x + h * t1
297-
}
244+
/**
245+
* Cubic Hermite spline slope differentiated
246+
*/
247+
private fun diff(h: Float, x: Float, y1: Float, y2: Float, t1: Float, t2: Float): Float {
248+
val x2 = x * x
249+
return (-6 * x2 * y2
250+
+ 6 * x * y2
251+
+ 6 * x2 * y1
252+
- 6 * x * y1
253+
+ 3 * h * t2 * x2
254+
+ 3 * h * t1 * x2
255+
- 2 * h * t2 * x
256+
- 4 * h * t1 * x + h * t1)
298257
}
258+
299259
}

0 commit comments

Comments
 (0)