This directory contains the Sequence namespace with classes for manipulating 1D and 2D sequences of interlacement values. Sequences provide a different, and more fluid and sequential way of manipulating patterns used throughout AdaCAD's operations.
For example, consider the twill operation. if provided with numeric values for the number of warps raised, and lowered, a boolean for direction called sz and a boolean for the side of the twill that is facing, you can create the corresponding twill in the following way:
//initialize a plan 1d sequence object - []
const first_row = new Sequence.OneD();
//push values to that object based on the values of raised and lowered.
first_row.pushMultiple(1, raised).pushMultiple(0, lowered);
//if raised is 3 and lowered is 2, the object now reads [1, 1, 1, 0, 0]
//depending on the face that should be shown, invert the pattern
if (facing) first_row.invert(); //[0, 0, 0, 1, 1]
//create a 2D object that will hold the sequences as "rows"
const pattern = new Sequence.TwoD();
const shift_dir = (sz) ? -1 : 1;
//loop through the total number of rows in the twill, on each row, shift the sequence by 1 and push the result
for (let i = 0; i < (raised + lowered); i++) {
pattern.pushWeftSequence(first_row.shift(shift_dir).val());
}
//would result in
// [1, 1, 1, 0, 0]
// [0, 1, 1, 1, 0]
// [0, 0, 1, 1, 1]
// [1, 0, 0, 1, 1]
// [1, 1, 0, 0, 1]
//call pattern.export to covert this 2D numeric array to a drawdown object.
const draft = initDraftFromDrawdown(pattern.export())Contains the Sequence namespace with two main classes:
Sequence.OneD: One-dimensional sequence class for manipulating rows or columns of interlacement values.
Sequence.TwoD: Two-dimensional sequence class for manipulating full drawdown patterns.
Exports the Sequence namespace.
Sequences use numeric values to represent cell states:
0: Heddle down (white cell)1: Heddle up (black cell)2: Unset (no weft at this location)
const seq = new Sequence.OneD([0, 1, 0, 1]); // Initialize with array
const empty = new Sequence.OneD(); // Empty sequencepush(val: number | boolean): Adds value to endunshift(val: number | boolean): Adds value to beginningpushMultiple(val: number | boolean, multiple: number): Pushes multiple copiesunshiftMultiple(val: number | boolean, multiple: number): Unshifts multiple copiesresize(n: number): Resizes sequence to length n (repeats or truncates)padTo(n: number): Pads sequence to length n with unset values (2)invert(): Inverts all values (0↔1, 2 stays 2)slice(start: number, end: number): Slices sequenceshift(val: number): Shifts sequence by val positionsrepeat(val: number): Repeats sequence val timesreverse(): Reverses sequence orderdeleteAndDrawIn(val: number): Deletes value at index and moves to front
import(row: Array<Cell> | Array<number>): Imports from cell array or number arraypushRow(row: Array<Cell> | Array<number>): Pushes row without clearing state
val(): Returns sequence as number arrayget(i: number): Gets value at index iset(i: number, val: number | boolean): Sets value at index ilength(): Returns sequence length
matchSize(seq: OneD): Matches size with another sequence by padding with unsetcomputeFilter(filter: string, seq: OneD): Applies binary filter operation (AND, OR, XOR, etc.)
const seq2d = new Sequence.TwoD([[0, 1], [1, 0]]); // Initialize with 2D array
const blank = new Sequence.TwoD().setBlank(2).fill(10, 10); // 10x10 blankwefts(): Returns number of wefts (rows)warps(): Returns number of warps (columns)fill(w: number, h: number): Fills rectangle, repeating pattern as neededsetBlank(val: number | boolean): Sets blank pattern value
get(i: number, j: number): Gets value at position (i, j)set(i: number, j: number, val: number, can_overwrite_set: boolean): Sets valuegetWeft(i: number): Gets entire weft (row) as arraygetWarp(j: number): Gets entire warp (column) as array
deleteWeft(i: number): Deletes a weft rowdeleteWarp(j: number): Deletes a warp columnpushWeftSequence(seq: Array<number>): Adds weft row to endunshiftWeftSequence(seq: Array<number>): Adds weft row to beginningpushWarpSequence(seq: Array<number>): Adds warp column to endunshiftWarpSequence(seq: Array<number>): Adds warp column to beginningshiftRow(i: number, val: number): Shifts a rowshiftCol(j: number, val: number): Shifts a column
overlay(seq: TwoD, consider_heddle_down_as_unset: boolean): Overlays another sequencesetUnsetOnWeft(i: number, val: number): Sets all unset values in a weftsetUnsetOnWarp(j: number, val: number): Sets all unset values in a warp
mapToSystems(weftsys, warpsys, weft_system_map, warp_system_map, ends, pics): Maps sequence to specific warp/weft systemsmapToWarpSystems(...): Maps to warp systems onlymapToWeftSystems(...): Maps to weft systems onlyplaceInLayerStack(...): Places sequence in layer stack considering previous layers
import(dd: Drawdown): Imports from drawdown formatexport(): Exports to drawdown formatcopy(): Creates a deep copy
import { Sequence } from './sequence';
// Create and manipulate a pattern
const pattern = new Sequence.OneD([0, 1, 0, 1])
.repeat(3) // [0,1,0,1,0,1,0,1,0,1,0,1]
.invert() // [1,0,1,0,1,0,1,0,1,0,1,0]
.shift(2) // Shift by 2 positions
.resize(8); // Resize to 8 elements
const values = pattern.val(); // Get final arrayimport { Sequence } from './sequence';
// Create a 2D pattern
const twill = new Sequence.TwoD()
.setBlank(2)
.fill(4, 4);
// Set a twill pattern
twill.set(0, 0, 1, true);
twill.set(1, 1, 1, true);
twill.set(2, 2, 1, true);
twill.set(3, 3, 1, true);
// Export to drawdown
const drawdown = twill.export();// Map a pattern to specific systems
const pattern = new Sequence.TwoD([[1, 0], [0, 1]]);
const weftSystems = new Sequence.OneD([0, 1]); // Systems a, b
const warpSystems = new Sequence.OneD([0]); // System a
pattern.mapToSystems(
[0], // Weft systems to map to
[0], // Warp systems to map to
weftSystems, // Weft system map
warpSystems, // Warp system map
4, // Output ends
4 // Output pics
);Sequences are primarily used in operations to:
- Pattern Manipulation: Transform patterns before applying to drafts
- System Mapping: Apply patterns to specific warp/weft systems
- Layer Management: Handle multi-layer structures
- Pattern Generation: Build complex patterns from simple sequences
// In sequence.ts, add to Sequence.OneD class
mirror(): OneD {
const reversed = this.state.slice().reverse();
this.state = this.state.concat(reversed);
return this;
}
count(val: number): number {
return this.state.filter(el => el === val).length;
}// In sequence.ts, add to Sequence.TwoD class
rotate90(): TwoD {
const rotated: Array<Array<number>> = [];
const w = this.warps();
const h = this.wefts();
for (let j = 0; j < w; j++) {
rotated.push([]);
for (let i = h - 1; i >= 0; i--) {
rotated[j].push(this.get(i, j));
}
}
this.state = rotated;
return this;
}- Method Chaining: Sequences use fluent API - methods return
thisfor chaining - Immutability Consideration: Most methods mutate internal state. Use
copy()if you need to preserve original - Bounds Checking: The classes include bounds checking with error logging
- LCM Handling: When sequences need to be compatible sizes, use LCM (least common multiple) calculations
- Unset Values: Remember that 2 represents unset - handle appropriately in transformations
Sequences integrate with:
- Operations: Used extensively in operation implementations
- Drafts: Can import/export to/from drawdown format
- Systems: System mapping is a core feature
- Utils: Uses
lcm()andcomputeFilter()from utils