diff --git a/src/main/kotlin/com/martianwabbit/hpglWriter.kt b/src/main/kotlin/com/martianwabbit/hpglWriter.kt index c91496e..d89576b 100644 --- a/src/main/kotlin/com/martianwabbit/hpglWriter.kt +++ b/src/main/kotlin/com/martianwabbit/hpglWriter.kt @@ -49,8 +49,7 @@ class HPGL( hpgl.cmd("PU", segment.start) // Go to shape start hpgl.cmd("PD", segment.end) } else { - hpgl.cmd("PD", segment.start) // PD coordinates for all other segments - hpgl.cmd("PD", segment.end) // PD coordinates for all other segments + hpgl.cmd("PD", segment.start, segment.end) // PD coordinates for all other segments } } @@ -58,13 +57,8 @@ class HPGL( } } - is SelectPen -> { - hpgl.cmd("SP", this.penNumber) - } - - is VelocitySelect -> { - hpgl.cmd("VS", this.velocity) - } + is SelectPen -> hpgl.cmd("SP", this.penNumber) + is VelocitySelect -> hpgl.cmd("VS", this.velocity) } } } @@ -89,29 +83,31 @@ private fun CompositionNode.traverse(cb: CompositionNode.(stage: Stage) -> Unit) this.cb(Stage.After) } +private val Vector2.coords: String + get() { + return "$x,$y" + } + + // HPGL Custom Instructions -class SelectPen(val penNumber: Int) : GroupNode() +private class SelectPen(val penNumber: Int) : GroupNode() fun CompositionDrawer.selectPen(pen: Int) { require(pen >= 0) { "The pen can only be 0 or greater." } this.root.children.add(SelectPen(pen)) } -class VelocitySelect(val velocity: Double) : GroupNode() +private class VelocitySelect(val velocity: Double) : GroupNode() fun CompositionDrawer.velocitySelect(velocity: Double) { require(velocity in 0.0..127.9999) { "Invalid velocity value. The velocity should be a value between 0 and 127.9999" } this.root.children.add(VelocitySelect(velocity)) } +// StringBuilder Extensions private fun StringBuilder.cmd(cmd: String) = this.appendln("$cmd;") private fun StringBuilder.cmd(cmd: String, i: Int) = this.appendln("$cmd${i};") private fun StringBuilder.cmd(cmd: String, i: Double) = this.appendln("$cmd${i};") private fun StringBuilder.cmd(cmd: String, vararg vectors: Vector2) { this.appendln(vectors.joinToString(prefix = cmd, postfix = ";") { it.coords }) } - -private val Vector2.coords: String - get() { - return "$x,$y" - }