Skip to content

Commit 28eba16

Browse files
committed
Remove default values from Generator
1 parent 3807c1c commit 28eba16

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

orx-g-code/src/commonMain/kotlin/Generator.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,34 @@ fun Double.roundedTo(decimals: Int = 3): String {
4848

4949
/**
5050
* Generates g-code for defined operations.
51-
* All operations are empty command lists on default and have to be defined explicitly.
5251
*/
5352
data class Generator(
5453

5554
/**
5655
* Setup code at the beginning of a file.
5756
*/
58-
val setup: Commands = emptyList(),
57+
val setup: Commands,
5958

6059
/**
6160
* A move operation to the given location.
6261
*/
63-
val moveTo: (Vector2) -> Commands = { emptyList() },
62+
val moveTo: (Vector2) -> Commands,
6463

6564
/**
66-
* Start drawing sequence. Pen down, laser on etc.
65+
* Start drawing sequence. Pen down, laser on, etc.
6766
*/
68-
val preDraw: Commands = emptyList(),
67+
val preDraw: Commands,
6968

7069
/**
7170
* A draw operation to the given location.
7271
*/
73-
val drawTo: (Vector2) -> Commands = { emptyList() },
72+
val drawTo: (Vector2) -> Commands,
7473

7574
/**
76-
* End draw sequence. Lift pen, turn laser off.
75+
* End draw sequence. Lift pen, turn laser off, etc.
7776
* Called after a draw action before a move is performed.
7877
*/
79-
val postDraw: Commands = emptyList(),
78+
val postDraw: Commands,
8079

8180
/**
8281
* End of file sequence.
@@ -86,9 +85,20 @@ data class Generator(
8685
/**
8786
* Insert a comment.
8887
*/
89-
val comment: (String) -> Commands = { _ -> emptyList() }
88+
val comment: (String) -> Commands
9089
)
9190

91+
/**
92+
* All operations are empty command lists on default and have to be defined explicitly.
93+
*/
94+
fun noopGenerator() = Generator(
95+
setup = emptyList(),
96+
moveTo = { _ -> emptyList() },
97+
preDraw = emptyList(),
98+
drawTo = { _ -> emptyList() },
99+
postDraw = emptyList(),
100+
) { _ -> emptyList() }
101+
92102
/**
93103
* Creates a [Generator] to be used by grbl controlled pen plotters.
94104
* [drawRate] sets the feed rate used for drawing operations.

orx-g-code/src/jvmMain/kotlin/Plot.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Plot(
4747
var origin: Origin = Origin.BOTTOM_LEFT,
4848

4949
// G-code
50-
var generator: Generator = Generator(),
50+
var generator: Generator = noopGenerator(),
5151
var distanceTolerance: Double = 0.5,
5252
var layerMode: LayerMode = LayerMode.SINGLE_FILE,
5353

@@ -159,7 +159,7 @@ class Plot(
159159
this.composition.clear()
160160
// Set default
161161
fill = ColorRGBa.TRANSPARENT
162-
strokeWeight = scaled(defaultPenWeight)
162+
strokeWeight = defaultPenWeight
163163
stroke = defaultDrawColor
164164
drawFunction(this)
165165
}
@@ -210,10 +210,15 @@ class Plot(
210210
}
211211

212212
/**
213-
* Double [v] scaled from screen space to document space.
213+
* Double [v] scaled from document space to screen space.
214214
*/
215215
fun scaled(v: Double) = v.times(scale)
216216

217+
/**
218+
* Scale from document space to screen space.
219+
*/
220+
fun scale() = scale
221+
217222
/**
218223
* Converts all layers to a single g-code string in the order they were added.
219224
*/

0 commit comments

Comments
 (0)