Skip to content

Commit e712b13

Browse files
committedDec 8, 2023
Added repeat method to interlock patterns.
Minor changes.
1 parent 39e5f7f commit e712b13

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed
 

‎src/interlock.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export interface PartialTabsOptions {
77
/** Kerf correction, affecting connection tightness. */
88
kerf: Kerf;
99
/**
10-
* How much the tabs protrude from the edge (typically equal to
11-
* the thickness of the material).
10+
* How much the tabs protrude from the edge (typically equal to the thickness of the material).
1211
*/
1312
tabWidth: number;
1413
/** To which side should the tabs go from the base line; or the edge of the material. */

‎src/interlock_patterns.ts

+15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export class InterlockPattern {
5050
return interlock;
5151
}
5252

53+
repeat(count: number) {
54+
let res = InterlockPattern.EMPTY;
55+
for (let i = 0; i < count; i++)
56+
res = res.addPattern(this);
57+
return res;
58+
}
59+
5360
reverse() {
5461
return new InterlockPattern([...this.items].reverse());
5562
}
@@ -172,6 +179,10 @@ export class TabsPattern {
172179
return TabsPattern.create(this.pattern.addPattern(other.pattern));
173180
}
174181

182+
repeat(count: number) {
183+
return TabsPattern.create(this.pattern.repeat(count));
184+
}
185+
175186
reverse() {
176187
return TabsPattern.create(this.pattern.reverse());
177188
}
@@ -348,6 +359,10 @@ export class SlotsPattern {
348359
this.pattern.addPattern(other.pattern), {startOpen: this.startOpen});
349360
}
350361

362+
repeat(count: number) {
363+
return TabsPattern.create(this.pattern.repeat(count));
364+
}
365+
351366
reverse() {
352367
return SlotsPattern.create(this.pattern.reverse(), {
353368
startOpen: this.endOpen,

‎src/layouts.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function row(...args: OrArrayRest<Piece | undefined> | [{
152152
return column({...parseArgs(args), axis: Axis.X});
153153
}
154154

155-
export type OutlinePiece = Piece | OutlinePiece[];
155+
export type PackPiece = Piece | PackPiece[];
156156

157157
const DEFAULT_PACK_NORMALISE_ITEMS: NormaliseArgs = "default";
158158

@@ -161,7 +161,7 @@ const DEFAULT_PACK_NORMALISE_ITEMS: NormaliseArgs = "default";
161161
* an array, is first packed in a column, similar to what the `column` function does - and so on,
162162
* recursively.
163163
*/
164-
export function pack(...piecesRow: OutlinePiece[]): Piece;
164+
export function pack(...piecesRow: PackPiece[]): Piece;
165165
/**
166166
* Packs the piece items in a row (or column, if the Y axis is specified), similar to
167167
* what the `row` (or `column`) function does. Each item that is an array, is first packed
@@ -171,30 +171,30 @@ export function pack(...piecesRow: OutlinePiece[]): Piece;
171171
* by default.
172172
*/
173173
export function pack(args: {
174-
pieces: OutlinePiece[],
174+
pieces: PackPiece[],
175175
axis?: Axis,
176176
normaliseItems?: NormaliseArgs | "none",
177177
gap?: number,
178178
}): Piece;
179-
export function pack(...params: OutlinePiece[] | [{
180-
pieces: OutlinePiece[],
179+
export function pack(...params: PackPiece[] | [{
180+
pieces: PackPiece[],
181181
axis?: Axis,
182182
normaliseItems?: NormaliseArgs | "none",
183183
gap?: number,
184184
}]) {
185-
function isOutlinePieces(params: OutlinePiece[] | [{}]): params is OutlinePiece[] {
185+
function isPackPieces(params: PackPiece[] | [{}]): params is PackPiece[] {
186186
return params.length !== 1 || params[0] instanceof Piece || Array.isArray(params[0]);
187187
}
188188
const {
189189
pieces,
190190
axis = Axis.X,
191191
normaliseItems = DEFAULT_PACK_NORMALISE_ITEMS,
192192
gap = 1,
193-
} = isOutlinePieces(params) ? {pieces: params} : params[0];
193+
} = isPackPieces(params) ? {pieces: params} : params[0];
194194
function norm(pc: Piece) {
195195
return normaliseItems === "none" ? pc : pc.normalise(normaliseItems);
196196
}
197-
function subPack(pieces: OutlinePiece[], axis: Axis): Piece {
197+
function subPack(pieces: PackPiece[], axis: Axis): Piece {
198198
return column({
199199
pieces: pieces.map(o =>
200200
(o instanceof Piece ? o : subPack(o, otherAxis(axis))).andThen(norm)),

0 commit comments

Comments
 (0)
Please sign in to comment.