Skip to content

Commit ca71dc8

Browse files
spawniaclaude
andcommitted
feat(Plate): add coordinateSystemSize utility function
Add a new utility function that calculates the total number of positions in a coordinate system (rows.length * columns.length). Use it to simplify allCoordinateSystemPositions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4bb0a25 commit ca71dc8

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/Plate/utils.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
columnForPosition,
1111
convertPositionFromColumnToRowFlow,
1212
convertPositionFromRowToColumnFlow,
13+
coordinateSystemSize,
1314
ensureCoordinatesInRange,
1415
rowForPosition,
1516
} from './utils';
@@ -176,6 +177,13 @@ const COORDINATE_SYSTEM_2_BY_2 = {
176177
columns: [1, 2],
177178
} as const satisfies CoordinateSystem;
178179

180+
describe('coordinateSystemSize', () => {
181+
it('returns the total number of positions in a coordinate system', () => {
182+
expect(coordinateSystemSize(COORDINATE_SYSTEM_2_BY_2)).toBe(4);
183+
expect(coordinateSystemSize(COORDINATE_SYSTEM_12X8)).toBe(96);
184+
});
185+
});
186+
179187
describe('allCoordinateSystemPositions', () => {
180188
it('returns an array of all positions in a coordinate systems', () => {
181189
expect(allCoordinateSystemPositions(COORDINATE_SYSTEM_2_BY_2)).toEqual([

src/Plate/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,16 @@ export function assertUniquePositions(
164164
}
165165
}
166166

167+
export function coordinateSystemSize(
168+
coordinateSystem: CoordinateSystem,
169+
): number {
170+
return coordinateSystem.rows.length * coordinateSystem.columns.length;
171+
}
172+
167173
export function allCoordinateSystemPositions(
168174
coordinateSystem: CoordinateSystem,
169175
): Array<number> {
170-
return range(
171-
1,
172-
coordinateSystem.rows.length * coordinateSystem.columns.length + 1,
173-
);
176+
return range(1, coordinateSystemSize(coordinateSystem) + 1);
174177
}
175178

176179
export function allCoordinateSystemCoordinates<

0 commit comments

Comments
 (0)