| 15 | import java.util.function.Function |
| 16 | |
| 17 | /** |
| 18 | * Created by marc on 6/25/17. |
| 19 | */ |
| 20 | |
| 21 | class Rasterizer(val filename: String, val transform: (Vec3) -> Vec2) { |
| 22 | private val filename_out: String |
| 23 | private var out: FileOutputStream |
| 24 | |
| 25 | init { |
| 26 | this.filename_out = filename + ".exr" |
| 27 | this.out = FileOutputStream(File(filename)) |
| 28 | } |
| 29 | |
| 30 | fun append(f: FLine) { |
| 31 | |
| 32 | val f2 = f.byTransforming { x -> transform(x).toVec3() } |
| 33 | out.write('B'.toInt()) |
| 34 | for (n in f2.nodes) { |
| 35 | when (n) { |
| 36 | is FLine.CubicTo -> { |
| 37 | out.write('c'.toInt()); F(n.c1.x); F(n.c1.y); F(n.c2.x); F(n.c2.y); F(n.to.x); F(n.to.y) |
| 38 | } |
| 39 | is FLine.LineTo -> { |
| 40 | out.write('l'.toInt()); F(n.to.x); F(n.to.y) |
| 41 | } |
| 42 | is FLine.MoveTo -> { |
| 43 | out.write('m'.toInt()); F(n.to.x); F(n.to.y) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | |
| 49 | run { |
| 50 | val c = f2.attributes.getOr(StandardFLineDrawing.color, { Vec4(1, 1, 1, 1) })?.get() |
| 51 | if (c != null) { |
| 52 | out.write('s'.toInt()) |
| 53 | F(c.x) |
| 54 | F(c.y) |
| 55 | F(c.z) |
| 56 | F(c.w) |
| 57 | out.write('f'.toInt()) |
| 58 | F(c.x) |
| 59 | F(c.y) |
| 60 | F(c.z) |
| 61 | F(c.w) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | run { |
| 66 | val c = f2.attributes.get(StandardFLineDrawing.strokeColor)?.get() |
| 67 | if (c != null) { |
| 68 | out.write('s'.toInt()) |
| 69 | F(c.x) |
| 70 | F(c.y) |
| 71 | F(c.z) |
| 72 | F(c.w) |
| 73 | } |
| 74 | } |
no test coverage detected