import { describe, expect, it } from 'vitest'; import * as THREE from 'three'; import { flipTexture } from './flipTexture'; describe('flipTexture', () => { it('negates repeat.x and shifts offset.x to keep the region in place', () => { const tex = new THREE.Texture(); tex.repeat.set(0.5, 0.25); tex.offset.set(0.3, 0.4); const flipped = flipTexture(tex); expect(flipped.repeat.x).toBeCloseTo(-0.5, 5); expect(flipped.repeat.y).toBeCloseTo(0.25, 5); // offset.x = 0.3 + 0.5 = 0.8; the visible region stays put while mirrored. expect(flipped.offset.x).toBeCloseTo(0.8, 5); expect(flipped.offset.y).toBeCloseTo(0.4, 5); }); it('clones the source so the original is untouched', () => { const tex = new THREE.Texture(); tex.repeat.set(1, 1); tex.offset.set(0, 0); const flipped = flipTexture(tex); expect(flipped).not.toBe(tex); expect(tex.repeat.x).toBe(1); expect(tex.offset.x).toBe(0); }); it('flips a sprite cell correctly', () => { // A sprite cell: repeat 1/6, offset col/6. Flipping should mirror within // the cell, not shift it off the sheet. const tex = new THREE.Texture(); tex.repeat.set(1 / 6, 1 / 4); tex.offset.set(2 / 6, 3 / 4); const flipped = flipTexture(tex); expect(flipped.repeat.x).toBeCloseTo(-1 / 6, 5); expect(flipped.offset.x).toBeCloseTo(2 / 6 + 1 / 6, 5); expect(flipped.offset.y).toBeCloseTo(3 / 4, 5); }); });