Skip to content

adds level 0 subdivision #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions che/cheL0.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export default class CheL0 {
this._triangleCount = tableV.length / 3;

//Coordinates of each vertex of the mesh
this._tableGeometry = tableG;
this._tableGeometry = []
this._tableGeometry.push(...tableG);

//Indices of the triangles in the mesh
this._tableVertices = tableV;
this._tableVertices = []
this._tableVertices.push(...tableV)
this.computeNormals();
}

Expand Down Expand Up @@ -110,6 +112,23 @@ export default class CheL0 {
return 3 * this.triangle(heId) + (heId + 2) % 3;
}

subdivide(triangleId){
if (!this.isValidTriangle(triangleId)){
throw new Error("Invalid triangle for subdivision")
}
let center = this.getTriangleCenter(triangleId)
let id = this._vertexCount
this._tableGeometry.push(center)
this._vertexCount+=1
let halfEdges = this._tableVertices.slice(3*triangleId, 3*triangleId+3)
this._tableVertices[3*triangleId] = id
for (let i = 1; i< 3; i++){
let copy = Array.from(halfEdges)
copy[i] = id
this._tableVertices.push(...copy)
}
this._triangleCount+=2
}

relation00(vertexId) {
if (!this.isValidVertex(vertexId)) {
Expand Down
8 changes: 8 additions & 0 deletions tests/che.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ test('L0: Check if vertexCount equals to geometry table size', () => {
expect(che_base.level0.testGeometryTable()).toBe(true);
})



test('L0: Check if subdivsion works', () => {
che_base.level0.subdivide(3)
expect(che_base.level0.testVertexTable()).toBe(true);
})


test('L0: Check if triangleCount * 3 equals to vertex table size', () => {
expect(che_base.level0.testVertexTable()).toBe(true);
})
Expand Down