11import { describe , expect , it } from 'vitest' ;
22import { d } from '../src/index.ts' ;
33import { sizeOf } from '../src/data/sizeOf.ts' ;
4- import { getOffsetInfoAt } from '../src/data/offsetUtils.ts' ;
54
6- describe ( 'getOffsetInfoAt (default)' , ( ) => {
5+ describe ( 'd.memoryLayoutOf (default)' , ( ) => {
76 it ( 'returns offset 0 and full contiguous size for a scalar' , ( ) => {
8- const info = getOffsetInfoAt ( d . u32 ) ;
7+ const info = d . memoryLayoutOf ( d . u32 ) ;
98
109 expect ( info . offset ) . toBe ( 0 ) ;
1110 expect ( info . contiguous ) . toBe ( sizeOf ( d . u32 ) ) ;
@@ -17,34 +16,34 @@ describe('getOffsetInfoAt (default)', () => {
1716 b : d . vec3f ,
1817 } ) ;
1918
20- const info = getOffsetInfoAt ( Schema ) ;
19+ const info = d . memoryLayoutOf ( Schema ) ;
2120
2221 expect ( info . offset ) . toBe ( 0 ) ;
2322 expect ( info . contiguous ) . toBe ( 4 ) ;
2423 } ) ;
2524} ) ;
2625
27- describe ( 'getOffsetInfoAt (vectors)' , ( ) => {
26+ describe ( 'd.memoryLayoutOf (vectors)' , ( ) => {
2827 it ( 'computes component offsets and remaining contiguous bytes' , ( ) => {
29- const info = getOffsetInfoAt ( d . vec4u , ( v ) => v . z ) ;
28+ const info = d . memoryLayoutOf ( d . vec4u , ( v ) => v . z ) ;
3029
3130 expect ( info . offset ) . toBe ( 8 ) ;
3231 expect ( info . contiguous ) . toBe ( 8 ) ;
3332 } ) ;
3433
3534 it ( 'supports numeric component access' , ( ) => {
36- const info = getOffsetInfoAt ( d . vec3f , ( v ) => v [ 1 ] ) ;
35+ const info = d . memoryLayoutOf ( d . vec3f , ( v ) => v [ 1 ] ) ;
3736
3837 expect ( info . offset ) . toBe ( 4 ) ;
3938 expect ( info . contiguous ) . toBe ( 8 ) ;
4039 } ) ;
4140} ) ;
4241
43- describe ( 'getOffsetInfoAt (arrays)' , ( ) => {
42+ describe ( 'd.memoryLayoutOf (arrays)' , ( ) => {
4443 it ( 'computes offsets for array elements without padding' , ( ) => {
4544 const Schema = d . arrayOf ( d . u32 , 6 ) ;
4645
47- const info = getOffsetInfoAt ( Schema , ( a ) => a [ 3 ] as number ) ;
46+ const info = d . memoryLayoutOf ( Schema , ( a ) => a [ 3 ] as number ) ;
4847
4948 expect ( info . offset ) . toBe ( 12 ) ;
5049 expect ( info . contiguous ) . toBe ( 12 ) ;
@@ -53,22 +52,22 @@ describe('getOffsetInfoAt (arrays)', () => {
5352 it ( 'limits contiguous bytes to element size when array stride has padding' , ( ) => {
5453 const Schema = d . arrayOf ( d . vec3u , 3 ) ;
5554
56- const info = getOffsetInfoAt ( Schema , ( a ) => a [ 1 ] ?. x as number ) ;
55+ const info = d . memoryLayoutOf ( Schema , ( a ) => a [ 1 ] ?. x as number ) ;
5756
5857 expect ( info . offset ) . toBe ( 16 ) ;
5958 expect ( info . contiguous ) . toBe ( 12 ) ;
6059 } ) ;
6160} ) ;
6261
63- describe ( 'getOffsetInfoAt (struct runs)' , ( ) => {
62+ describe ( 'd.memoryLayoutOf (struct runs)' , ( ) => {
6463 it ( 'returns contiguous bytes within a packed run' , ( ) => {
6564 const Schema = d . struct ( {
6665 a : d . u32 ,
6766 b : d . u32 ,
6867 c : d . u32 ,
6968 } ) ;
7069
71- const info = getOffsetInfoAt ( Schema , ( s ) => s . b ) ;
70+ const info = d . memoryLayoutOf ( Schema , ( s ) => s . b ) ;
7271
7372 expect ( info . offset ) . toBe ( 4 ) ;
7473 expect ( info . contiguous ) . toBe ( 8 ) ;
@@ -80,14 +79,14 @@ describe('getOffsetInfoAt (struct runs)', () => {
8079 b : d . vec3u ,
8180 } ) ;
8281
83- const info = getOffsetInfoAt ( Schema , ( s ) => s . a ) ;
82+ const info = d . memoryLayoutOf ( Schema , ( s ) => s . a ) ;
8483
8584 expect ( info . offset ) . toBe ( 0 ) ;
8685 expect ( info . contiguous ) . toBe ( 4 ) ;
8786 } ) ;
8887} ) ;
8988
90- describe ( 'getOffsetInfoAt (nested layouts)' , ( ) => {
89+ describe ( 'd.memoryLayoutOf (nested layouts)' , ( ) => {
9190 // offset calculator for this struct: https://shorturl.at/NQggS
9291 const DeepStruct = d . struct ( {
9392 someData : d . arrayOf ( d . f32 , 13 ) ,
@@ -110,7 +109,7 @@ describe('getOffsetInfoAt (nested layouts)', () => {
110109 } ) ;
111110
112111 it ( 'tracks offsets and contiguous bytes within nested arrays' , ( ) => {
113- const info = getOffsetInfoAt (
112+ const info = d . memoryLayoutOf (
114113 DeepStruct ,
115114 ( s ) => s . someData [ 11 ] as number ,
116115 ) ;
@@ -120,7 +119,7 @@ describe('getOffsetInfoAt (nested layouts)', () => {
120119 } ) ;
121120
122121 it ( 'tracks offsets for nested structs inside arrays' , ( ) => {
123- const info = getOffsetInfoAt (
122+ const info = d . memoryLayoutOf (
124123 DeepStruct ,
125124 ( s ) => s . nested . innerNested [ 1 ] ?. myVec . x as number ,
126125 ) ;
@@ -130,7 +129,7 @@ describe('getOffsetInfoAt (nested layouts)', () => {
130129 } ) ;
131130
132131 it ( 'tracks offsets inside a later struct run' , ( ) => {
133- const info = getOffsetInfoAt (
132+ const info = d . memoryLayoutOf (
134133 DeepStruct ,
135134 ( s ) => s . nested . additionalData [ 1 ] as number ,
136135 ) ;
@@ -140,7 +139,7 @@ describe('getOffsetInfoAt (nested layouts)', () => {
140139 } ) ;
141140} ) ;
142141
143- describe ( 'getOffsetInfoAt (edge cases)' , ( ) => {
142+ describe ( 'd.memoryLayoutOf (edge cases)' , ( ) => {
144143 it ( 'tracks offsets between array elements' , ( ) => {
145144 const E = d . struct ( {
146145 x : d . u32 ,
@@ -151,7 +150,7 @@ describe('getOffsetInfoAt (edge cases)', () => {
151150 arr : d . arrayOf ( E , 3 ) ,
152151 } ) ;
153152
154- const info = getOffsetInfoAt (
153+ const info = d . memoryLayoutOf (
155154 S ,
156155 ( s ) => s . arr [ 1 ] ?. vec . x as number ,
157156 ) ;
@@ -170,7 +169,7 @@ describe('getOffsetInfoAt (edge cases)', () => {
170169 r : I ,
171170 } ) ;
172171
173- const info = getOffsetInfoAt (
172+ const info = d . memoryLayoutOf (
174173 S ,
175174 ( s ) => s . l . vec . z ,
176175 ) ;
@@ -191,7 +190,7 @@ describe('getOffsetInfoAt (edge cases)', () => {
191190 arr : d . arrayOf ( E , 4 ) ,
192191 } ) ;
193192
194- const info = getOffsetInfoAt (
193+ const info = d . memoryLayoutOf (
195194 S ,
196195 ( s ) => s . arr [ 1 ] ?. x . x as number ,
197196 ) ;
@@ -210,7 +209,7 @@ describe('getOffsetInfoAt (edge cases)', () => {
210209 s : I ,
211210 } ) ;
212211
213- const info = getOffsetInfoAt (
212+ const info = d . memoryLayoutOf (
214213 S ,
215214 ( s ) => s . arr [ 0 ] ?. y as number ,
216215 ) ;
0 commit comments