@@ -2,22 +2,22 @@ import { generateBrickData } from '../path';
2
2
import type { TInputUnion } from '../path' ;
3
3
4
4
// Helper function to parse SVG path and calculate actual bounding box
5
- function calculatePathBoundingBox ( pathString : string ) : { w : number ; h : number ; debug ?: any } {
5
+ function calculatePathBoundingBox ( pathString : string ) : { w : number ; h : number ; debug ?: unknown } {
6
6
// More robust parsing - split by spaces but handle commas and multiple spaces
7
7
const pathData = pathString . trim ( ) . replace ( / , / g, ' ' ) . replace ( / \s + / g, ' ' ) ;
8
8
const tokens = pathData . split ( ' ' ) ;
9
-
9
+
10
10
let currentX = 0 ;
11
11
let currentY = 0 ;
12
12
let minX = 0 ;
13
13
let minY = 0 ;
14
14
let maxX = 0 ;
15
15
let maxY = 0 ;
16
-
16
+
17
17
let i = 0 ;
18
18
while ( i < tokens . length ) {
19
19
const command = tokens [ i ] ;
20
-
20
+
21
21
if ( command === 'm' ) {
22
22
// Relative move
23
23
const dx = parseFloat ( tokens [ i + 1 ] ) ;
@@ -58,7 +58,7 @@ function calculatePathBoundingBox(pathString: string): { w: number; h: number; d
58
58
const sweepFlag = parseFloat ( tokens [ i + 5 ] ) ;
59
59
const dx = parseFloat ( tokens [ i + 6 ] ) ;
60
60
const dy = parseFloat ( tokens [ i + 7 ] ) ;
61
-
61
+
62
62
// For bounding box calculation, we need to consider arc extremes
63
63
// Simplified: just use start and end points for now
64
64
currentX += dx ;
@@ -87,19 +87,19 @@ function calculatePathBoundingBox(pathString: string): { w: number; h: number; d
87
87
// Unknown command, skip
88
88
i += 1 ;
89
89
}
90
-
90
+
91
91
// Update bounds after each command
92
92
minX = Math . min ( minX , currentX ) ;
93
93
minY = Math . min ( minY , currentY ) ;
94
94
maxX = Math . max ( maxX , currentX ) ;
95
95
maxY = Math . max ( maxY , currentY ) ;
96
96
}
97
-
97
+
98
98
const result = {
99
99
w : Math . abs ( maxX - minX ) ,
100
- h : Math . abs ( maxY - minY )
100
+ h : Math . abs ( maxY - minY ) ,
101
101
} ;
102
-
102
+
103
103
return result ;
104
104
}
105
105
@@ -265,12 +265,15 @@ describe('Masonry: Brick > Path Generation', () => {
265
265
// NEW TEST: Validate bounding box against actual path dimensions
266
266
it ( `bounding box matches actual path dimensions: ${ name } ` , ( ) => {
267
267
const { path, boundingBox } = generateBrickData ( input as TInputUnion ) ;
268
-
268
+
269
269
// Calculate actual bounding box from path
270
270
const actualBounds = calculatePathBoundingBox ( path ) ;
271
-
271
+
272
272
// Debug output for failed tests
273
- if ( Math . abs ( boundingBox . w - actualBounds . w ) > 1 || Math . abs ( boundingBox . h - actualBounds . h ) > 1 ) {
273
+ if (
274
+ Math . abs ( boundingBox . w - actualBounds . w ) > 1 ||
275
+ Math . abs ( boundingBox . h - actualBounds . h ) > 1
276
+ ) {
274
277
console . log ( `\n=== DEBUG INFO FOR: ${ name } ===` ) ;
275
278
console . log ( 'Input:' , JSON . stringify ( input , null , 2 ) ) ;
276
279
console . log ( 'Generated Path:' , path ) ;
@@ -280,11 +283,11 @@ describe('Masonry: Brick > Path Generation', () => {
280
283
console . log ( 'Height Difference:' , Math . abs ( boundingBox . h - actualBounds . h ) ) ;
281
284
console . log ( '=====================================\n' ) ;
282
285
}
283
-
286
+
284
287
// Use larger tolerance since there might be genuine calculation differences
285
288
// Especially with arc commands and complex path geometries
286
- const tolerance = 1 ;
287
-
289
+ const tolerance = 1 ;
290
+
288
291
expect ( Math . abs ( boundingBox . w - actualBounds . w ) ) . toBeLessThanOrEqual ( tolerance ) ;
289
292
expect ( Math . abs ( boundingBox . h - actualBounds . h ) ) . toBeLessThanOrEqual ( tolerance ) ;
290
293
} ) ;
0 commit comments