Moving a couple of things around.
This commit is contained in:
parent
5e2d9fccd2
commit
6140d5d0d6
|
|
@ -49,8 +49,7 @@ class HPGL(
|
||||||
hpgl.cmd("PU", segment.start) // Go to shape start
|
hpgl.cmd("PU", segment.start) // Go to shape start
|
||||||
hpgl.cmd("PD", segment.end)
|
hpgl.cmd("PD", segment.end)
|
||||||
} else {
|
} else {
|
||||||
hpgl.cmd("PD", segment.start) // PD coordinates for all other segments
|
hpgl.cmd("PD", segment.start, segment.end) // PD coordinates for all other segments
|
||||||
hpgl.cmd("PD", segment.end) // PD coordinates for all other segments
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,13 +57,8 @@ class HPGL(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is SelectPen -> {
|
is SelectPen -> hpgl.cmd("SP", this.penNumber)
|
||||||
hpgl.cmd("SP", this.penNumber)
|
is VelocitySelect -> hpgl.cmd("VS", this.velocity)
|
||||||
}
|
|
||||||
|
|
||||||
is VelocitySelect -> {
|
|
||||||
hpgl.cmd("VS", this.velocity)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -89,29 +83,31 @@ private fun CompositionNode.traverse(cb: CompositionNode.(stage: Stage) -> Unit)
|
||||||
this.cb(Stage.After)
|
this.cb(Stage.After)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val Vector2.coords: String
|
||||||
|
get() {
|
||||||
|
return "$x,$y"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// HPGL Custom Instructions
|
// HPGL Custom Instructions
|
||||||
class SelectPen(val penNumber: Int) : GroupNode()
|
private class SelectPen(val penNumber: Int) : GroupNode()
|
||||||
|
|
||||||
fun CompositionDrawer.selectPen(pen: Int) {
|
fun CompositionDrawer.selectPen(pen: Int) {
|
||||||
require(pen >= 0) { "The pen can only be 0 or greater." }
|
require(pen >= 0) { "The pen can only be 0 or greater." }
|
||||||
this.root.children.add(SelectPen(pen))
|
this.root.children.add(SelectPen(pen))
|
||||||
}
|
}
|
||||||
|
|
||||||
class VelocitySelect(val velocity: Double) : GroupNode()
|
private class VelocitySelect(val velocity: Double) : GroupNode()
|
||||||
|
|
||||||
fun CompositionDrawer.velocitySelect(velocity: Double) {
|
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" }
|
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))
|
this.root.children.add(VelocitySelect(velocity))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StringBuilder Extensions
|
||||||
private fun StringBuilder.cmd(cmd: String) = this.appendln("$cmd;")
|
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: Int) = this.appendln("$cmd${i};")
|
||||||
private fun StringBuilder.cmd(cmd: String, i: Double) = 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) {
|
private fun StringBuilder.cmd(cmd: String, vararg vectors: Vector2) {
|
||||||
this.appendln(vectors.joinToString(prefix = cmd, postfix = ";") { it.coords })
|
this.appendln(vectors.joinToString(prefix = cmd, postfix = ";") { it.coords })
|
||||||
}
|
}
|
||||||
|
|
||||||
private val Vector2.coords: String
|
|
||||||
get() {
|
|
||||||
return "$x,$y"
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue