[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft/
0

Configure Feed

Select the types of activity you want to include in your feed.

shapecraft / tests / ops.test.ts
2.0 kB 57 lines
1import { describe, it, expect } from 'vitest' 2import * as THREE from 'three' 3import { box, sphere } from '../src/primitives' 4import { merge, center, clone, decimate } from '../src/ops' 5 6describe('ops', () => { 7 it('merge combines vertex counts', () => { 8 const b = box() 9 const s = sphere() 10 const merged = merge(b, s) 11 expect(merged.vertexCount).toBe(b.vertexCount + s.vertexCount) 12 }) 13 14 it('merge handles mixed color/no-color meshes', () => { 15 const colored = box().vertexColor('#ff0000') 16 const plain = sphere() 17 const merged = merge(colored, plain) 18 expect(merged.colors).not.toBeNull() 19 expect(merged.colors!.length).toBe(merged.vertexCount * 3) 20 }) 21 22 it('center puts bounding box center at origin', () => { 23 const b = box().translate(10, 10, 10) 24 const centered = center(b) 25 centered.geometry.computeBoundingBox() 26 const c = new THREE.Vector3() 27 centered.geometry.boundingBox!.getCenter(c) 28 expect(c.x).toBeCloseTo(0) 29 expect(c.y).toBeCloseTo(0) 30 expect(c.z).toBeCloseTo(0) 31 }) 32 33 it('clone produces independent copy', () => { 34 const b = box() 35 const c = clone(b) 36 expect(c.vertexCount).toBe(b.vertexCount) 37 expect(c.geometry).not.toBe(b.geometry) 38 }) 39 40 it('decimate reduces face count while preserving the silhouette', () => { 41 const s = sphere({ radius: 1, widthSegments: 32, heightSegments: 24 }) 42 const before = s.faceCount 43 const d = decimate(s, { ratio: 0.3 }) 44 expect(d.faceCount).toBeLessThan(before) 45 expect(d.vertexCount).toBeGreaterThan(0) 46 // Bounding box (silhouette) stays close to the original sphere. 47 const bb = d.boundingBox 48 expect(bb.max.x).toBeGreaterThan(0.85) 49 expect(bb.max.x).toBeLessThan(1.15) 50 }) 51 52 it('decimate hits an explicit target count', () => { 53 const s = sphere({ radius: 1, widthSegments: 24, heightSegments: 16 }) 54 const d = decimate(s, { count: 80 }) 55 expect(d.vertexCount).toBeLessThanOrEqual(120) 56 }) 57})