| 9 | import java.util.* |
| 10 | |
| 11 | class CSV2(val directory: String, val suffix: String) { |
| 12 | |
| 13 | var points = mutableListOf<TCB3>() |
| 14 | |
| 15 | init { |
| 16 | |
| 17 | val vv = File(directory).listFiles { dir, n -> n.endsWith(suffix) } |
| 18 | |
| 19 | if (vv == null) throw IllegalArgumentException("can't list '$directory'") |
| 20 | if (vv.size == 0) throw IllegalArgumentException("'$directory' has no matching files") |
| 21 | |
| 22 | Arrays.sort(vv) |
| 23 | |
| 24 | val numPoints = Files.readAllLines(vv[0].toPath()) |
| 25 | |
| 26 | (0 until numPoints.size).forEach { points.add(TCB3()) } |
| 27 | |
| 28 | for (i in 0 until vv.size) { |
| 29 | val reader = BufferedReader(FileReader(vv[i])) |
| 30 | |
| 31 | var index = 0 |
| 32 | while (reader.ready()) { |
| 33 | val l = reader.readLine() |
| 34 | |
| 35 | val pieces = l.split(",") |
| 36 | |
| 37 | points[index].newNode(i.toDouble(), Vec3(pieces[0].toDouble(), pieces[1].toDouble(), pieces[2].toDouble())) |
| 38 | index++ |
| 39 | } |
| 40 | |
| 41 | } |
| 42 | |
| 43 | (0 until numPoints.size).forEach { points[it].tcbAll() } |
| 44 | |
| 45 | } |
| 46 | |
| 47 | |
| 48 | fun atTime(time: Double): List<Vec3> { |
| 49 | return points.map { it.evaluate(time * it.duration(), Vec3()) } |
| 50 | } |
| 51 | |
| 52 | fun duration(): Double { |
| 53 | return points[0].duration() |
| 54 | } |
| 55 | |
| 56 | |
| 57 | } |