| 12 | import java.util.function.Supplier |
| 13 | |
| 14 | class SaveForRobot { |
| 15 | fun saveForRobot(f: List<FLine>) { |
| 16 | if (f.size == 0) throw IllegalArgumentException(" no lines to save ") |
| 17 | |
| 18 | val base = System.getProperty("user.home") + File.separatorChar + "field_robot" + File.separatorChar |
| 19 | |
| 20 | var x = 1 |
| 21 | while (File(base + Saver.pad(x)).exists()) x++ |
| 22 | |
| 23 | val prefix = File(base + Saver.pad(x) + ".robot") |
| 24 | prefix.parentFile.mkdirs() |
| 25 | |
| 26 | var bounds: Rect? = null |
| 27 | f.forEach { |
| 28 | val b = FLinesAndJavaShapes.flineToJavaShape_notThickened(it).bounds2D |
| 29 | bounds = Rect.union(bounds, Rect(b.x, b.y, b.width, b.height)) |
| 30 | } |
| 31 | |
| 32 | val m = Math.max(bounds!!.w, bounds!!.h) |
| 33 | |
| 34 | println("bounds are $bounds") |
| 35 | |
| 36 | val r = Rasterizer(prefix.absolutePath, { |
| 37 | var r = Vec2((it.toVec2().x - bounds!!.x) / m, (it.toVec2().y - bounds!!.y) / m) |
| 38 | println(r) |
| 39 | r |
| 40 | }) |
| 41 | |
| 42 | f.forEach { r.append(it) } |
| 43 | r.finish() |
| 44 | |
| 45 | Desktop.getDesktop().browseFileDirectory(prefix.parentFile) |
| 46 | } |
| 47 | |
| 48 | fun saveForRobot(f: IdempotencyMap<Supplier<FLine>>) { |
nothing calls this directly
no test coverage detected