@@ -135,11 +135,15 @@ export interface Point {
135
135
136
136
export class BoardLayouter {
137
137
readonly placements : Rectangle < PartToCut > [ ] = [ ] ;
138
+ private readonly paddedStock : Rectangle < Stock > ;
138
139
139
140
constructor (
140
141
readonly stock : Rectangle < Stock > ,
141
142
readonly config : Config ,
142
- ) { }
143
+ ) {
144
+ const padding = - new Distance ( config . extraSpace ) . m ;
145
+ this . paddedStock = stock . pad ( { right : padding , top : padding } ) ;
146
+ }
143
147
144
148
tryAddPart ( part : PartToCut ) : boolean {
145
149
if ( part . material !== this . stock . data . material ) return false ;
@@ -161,7 +165,7 @@ export class BoardLayouter {
161
165
const possiblePositions : Point [ ] =
162
166
this . placements . length === 0
163
167
? // Always position bottom left when empty
164
- [ { x : this . stock . x , y : this . stock . y } ]
168
+ [ { x : this . paddedStock . x , y : this . paddedStock . y } ]
165
169
: // Get possible locations from callback
166
170
getPossiblePositions ( ) ;
167
171
@@ -172,7 +176,7 @@ export class BoardLayouter {
172
176
)
173
177
. find (
174
178
( placement ) =>
175
- placement . isInside ( this . stock ) &&
179
+ placement . isInside ( this . paddedStock ) &&
176
180
this . placements . every ( ( p ) => ! placement . isIntersecting ( p ) ) ,
177
181
) ;
178
182
@@ -191,9 +195,9 @@ export class BoardLayouter {
191
195
const bladeWidth = new Distance ( this . config . bladeWidth ) . m ;
192
196
return [
193
197
// Left of stock and top of existing
194
- { x : this . stock . x , y : existing . top + bladeWidth } ,
198
+ { x : this . paddedStock . x , y : existing . top + bladeWidth } ,
195
199
// left of existing, bottom of stock
196
- { x : existing . right + bladeWidth , y : this . stock . y } ,
200
+ { x : existing . right + bladeWidth , y : this . paddedStock . y } ,
197
201
198
202
// Left of existing, top of other existing
199
203
...this . placements . map ( ( existing2 ) => ( {
@@ -262,7 +266,7 @@ export class BoardLayouter {
262
266
263
267
reduceStock ( allStock : Rectangle < Stock > [ ] ) : BoardLayouter {
264
268
const validStock = allStock . filter (
265
- ( stock ) => stock . data . material === this . stock . data . material ,
269
+ ( stock ) => stock . data . material === this . paddedStock . data . material ,
266
270
) ;
267
271
const validLayouts = validStock
268
272
. map ( ( stock ) => {
0 commit comments