@@ -104,48 +104,59 @@ describe("TilesetManager.getTileUV", () => {
104104 const manager = new TilesetManager ( ) ;
105105 manager . registerTexture ( makeDef ( "terrain" , 16 , 4 , 4 ) , mockTexture ( 64 , 64 ) ) ;
106106
107- it ( "tile (col=0, row=0): offsetU=0, offsetV=0.75, scaleU=0.25, scaleV=0.25" , ( ) => {
108- // offsetV = 1 - (0+1)/4 = 0.75
107+ it ( "tile (col=0, row=0): offsetU/offsetV/scale (inset by half-texel)" , ( ) => {
108+ // halfTexel = 0.5 / (cols*tileSize) = 0.5 / 64 = 0.0078125
109+ // offsetU = 0 + halfTexel = 0.0078125
110+ // offsetV = 1 - (0+1)/4 + halfTexel = 0.7578125
111+ // scaleU = scaleV = (tileSize - 1) / imgW = 15/64 = 0.234375
109112 const uv = manager . getTileUV ( { col : 0 , row : 0 } ) ;
110- assert . ok ( approxEqual ( uv . offsetU , 0 ) ) ;
111- assert . ok ( approxEqual ( uv . offsetV , 0.75 ) ) ;
112- assert . ok ( approxEqual ( uv . scaleU , 0.25 ) ) ;
113- assert . ok ( approxEqual ( uv . scaleV , 0.25 ) ) ;
113+ assert . ok ( approxEqual ( uv . offsetU , 0.0078125 ) ) ;
114+ assert . ok ( approxEqual ( uv . offsetV , 0.7578125 ) ) ;
115+ assert . ok ( approxEqual ( uv . scaleU , 15 / 64 ) ) ;
116+ assert . ok ( approxEqual ( uv . scaleV , 15 / 64 ) ) ;
114117 } ) ;
115118
116- it ( "tile (col=1, row=0): offsetU=0.25" , ( ) => {
119+ it ( "tile (col=1, row=0): offsetU/offsetV (inset by half-texel)" , ( ) => {
120+ // offsetU = 1*16/64 + halfTexel = 0.2578125
121+ // offsetV = 0.7578125
117122 const uv = manager . getTileUV ( { col : 1 , row : 0 } ) ;
118- assert . ok ( approxEqual ( uv . offsetU , 0.25 ) ) ;
119- assert . ok ( approxEqual ( uv . offsetV , 0.75 ) ) ;
123+ assert . ok ( approxEqual ( uv . offsetU , 0.2578125 ) ) ;
124+ assert . ok ( approxEqual ( uv . offsetV , 0.7578125 ) ) ;
120125 } ) ;
121126
122- it ( "tile (col=0, row=3) is the bottom row: offsetV=0 " , ( ) => {
123- // offsetV = 1 - (3+1)/4 = 0
127+ it ( "tile (col=0, row=3) is the bottom row: offsetV (inset by half-texel) " , ( ) => {
128+ // offsetV = 1 - (3+1)/4 + halfTexel = 0.0078125
124129 const uv = manager . getTileUV ( { col : 0 , row : 3 } ) ;
125- assert . ok ( approxEqual ( uv . offsetV , 0 ) ) ;
130+ assert . ok ( approxEqual ( uv . offsetV , 0.0078125 ) ) ;
126131 } ) ;
127132
128- it ( "tile (col=3, row=3): offsetU=0.75, offsetV=0" , ( ) => {
133+ it ( "tile (col=3, row=3): offsetU/offsetV (inset by half-texel)" , ( ) => {
134+ // offsetU = 3*16/64 + halfTexel = 0.7578125
135+ // offsetV = halfTexel = 0.0078125
129136 const uv = manager . getTileUV ( { col : 3 , row : 3 } ) ;
130- assert . ok ( approxEqual ( uv . offsetU , 0.75 ) ) ;
131- assert . ok ( approxEqual ( uv . offsetV , 0 ) ) ;
137+ assert . ok ( approxEqual ( uv . offsetU , 0.7578125 ) ) ;
138+ assert . ok ( approxEqual ( uv . offsetV , 0.0078125 ) ) ;
132139 } ) ;
133140 } ) ;
134141
135142 describe ( "UV computation — 2-col 2-row atlas (tileSize=16, image=32×32)" , ( ) => {
136143 const manager = new TilesetManager ( ) ;
137144 manager . registerTexture ( makeDef ( "small" , 16 , 2 , 2 ) , mockTexture ( 32 , 32 ) ) ;
138145
139- it ( "scaleU = scaleV = 0.5" , ( ) => {
146+ it ( "scaleU = scaleV (inset by half-texel)" , ( ) => {
147+ // cols=2, tileSize=16 => imgW=32, halfTexel=0.5/32=0.015625
148+ // scale = (16 - 1) / 32 = 15/32 = 0.46875
140149 const uv = manager . getTileUV ( { col : 0 , row : 0 } ) ;
141- assert . ok ( approxEqual ( uv . scaleU , 0.5 ) ) ;
142- assert . ok ( approxEqual ( uv . scaleV , 0.5 ) ) ;
150+ assert . ok ( approxEqual ( uv . scaleU , 15 / 32 ) ) ;
151+ assert . ok ( approxEqual ( uv . scaleV , 15 / 32 ) ) ;
143152 } ) ;
144153
145- it ( "tile (col=1, row=1): offsetU=0.5, offsetV=0" , ( ) => {
154+ it ( "tile (col=1, row=1): offsetU/offsetV (inset by half-texel)" , ( ) => {
155+ // offsetU = 1*16/32 + halfTexel = 0.515625
156+ // offsetV = 1 - ((1+1)*16/32) + halfTexel = 0.015625
146157 const uv = manager . getTileUV ( { col : 1 , row : 1 } ) ;
147- assert . ok ( approxEqual ( uv . offsetU , 0.5 ) ) ;
148- assert . ok ( approxEqual ( uv . offsetV , 0 ) ) ;
158+ assert . ok ( approxEqual ( uv . offsetU , 0.515625 ) ) ;
159+ assert . ok ( approxEqual ( uv . offsetV , 0.015625 ) ) ;
149160 } ) ;
150161 } ) ;
151162
@@ -155,8 +166,8 @@ describe("TilesetManager.getTileUV", () => {
155166 manager . registerTexture ( makeDef ( "walls" , 16 , 2 , 2 ) , mockTexture ( 32 , 32 ) ) ;
156167
157168 const uv = manager . getTileUV ( { col : 0 , row : 0 , tilesetId : "walls" } ) ;
158- // walls is 2-col, 2-row → scaleU=0.5
159- assert . ok ( approxEqual ( uv . scaleU , 0.5 ) ) ;
169+ // walls is 2-col, 2-row → scaleU=(tileSize-1)/(cols*tileSize)=15/32
170+ assert . ok ( approxEqual ( uv . scaleU , 15 / 32 ) ) ;
160171 } ) ;
161172} ) ;
162173
0 commit comments