Skip to content

Commit 3a12364

Browse files
committed
Add tests
1 parent 9e01f2d commit 3a12364

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { test, expect } from 'vitest';
2+
import { BufferGeometry, Vector3 } from 'three';
3+
import { ExtrusionGeometry } from '../extrusion-geometry';
4+
5+
test('ExtrusionGeometry should be defined', () => {
6+
expect(ExtrusionGeometry).toBeDefined();
7+
});
8+
9+
test('ExtrusionGeometry extends BufferGeometry', () => {
10+
const geometry = new ExtrusionGeometry();
11+
expect(geometry).toBeInstanceOf(ExtrusionGeometry);
12+
expect(geometry).toBeInstanceOf(BufferGeometry);
13+
});
14+
15+
test('ExtrusionGeometry should be of type "ExtrusionGeometry"', () => {
16+
const geometry = new ExtrusionGeometry();
17+
expect(geometry.type).toBe('ExtrusionGeometry');
18+
});
19+
20+
test('ExtrusionGeometry should have default values', () => {
21+
const geometry = new ExtrusionGeometry();
22+
expect(geometry.parameters.points).toEqual([new Vector3()]);
23+
expect(geometry.parameters.lineWidth).toBe(0.6);
24+
expect(geometry.parameters.lineHeight).toBe(0.2);
25+
expect(geometry.parameters.radialSegments).toBe(8);
26+
});
27+
28+
test('ExtrusionGeometry constructor should set values', () => {
29+
const points = [new Vector3(), new Vector3()];
30+
const lineWidth = 0.5;
31+
const lineHeight = 0.3;
32+
const radialSegments = 10;
33+
const geometry = new ExtrusionGeometry(points, lineWidth, lineHeight, radialSegments);
34+
expect(geometry.parameters.points).toEqual(points);
35+
expect(geometry.parameters.lineWidth).toBe(lineWidth);
36+
expect(geometry.parameters.lineHeight).toBe(lineHeight);
37+
expect(geometry.parameters.radialSegments).toBe(radialSegments);
38+
});
39+
40+
test('ExtrusionGeometry should set normals, uvs and indices', () => {
41+
const points = [new Vector3(0, 0, 0), new Vector3(1, 0, 0)];
42+
const geometry = new ExtrusionGeometry(points);
43+
expect(geometry.attributes.position).toBeDefined();
44+
expect(geometry.attributes.normal).toBeDefined();
45+
expect(geometry.attributes.uv).toBeDefined();
46+
});
47+
48+
test('ExtrusionGeometry should generate buffer data', () => {
49+
const points = [new Vector3(0, 0, 0), new Vector3(1, 0, 0)];
50+
const geometry = new ExtrusionGeometry(points);
51+
expect(geometry.attributes.position.array.length).toBeGreaterThan(0);
52+
expect(geometry.attributes.normal.array.length).toBeGreaterThan(0);
53+
expect(geometry.attributes.uv.array.length).toBeGreaterThan(0);
54+
});

src/extrusion-geometry.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
import { BufferGeometry, Float32BufferAttribute, Vector2, Vector3 } from 'three';
22

33
class ExtrusionGeometry extends BufferGeometry {
4-
constructor(points: Vector3[] = [], lineWidth: number = 0.6, lineHeight: number = 0.2, radialSegments: number = 8) {
4+
parameters: {
5+
points: Vector3[];
6+
lineWidth: number;
7+
lineHeight: number;
8+
radialSegments: number;
9+
closed: boolean;
10+
};
11+
constructor(
12+
points: Vector3[] = [new Vector3()],
13+
lineWidth: number = 0.6,
14+
lineHeight: number = 0.2,
15+
radialSegments: number = 8
16+
) {
517
super();
618

719
this.type = 'ExtrusionGeometry';
820

21+
this.parameters = {
22+
points: points,
23+
lineWidth: lineWidth,
24+
lineHeight: lineHeight,
25+
radialSegments: radialSegments,
26+
closed: false
27+
};
28+
929
// helper variables
1030

1131
const vertex = new Vector3();

0 commit comments

Comments
 (0)