jscad / csg.js

DEPRECATED: CSG Library for JSCAD (See the link below)
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling
MIT License
217 stars 56 forks source link

Code optimization #165

Closed FishOrBear closed 4 years ago

FishOrBear commented 5 years ago

https://github.com/jscad/csg.js/blob/9fb96d33b32931d379f4d4f190ce999a3ee9f072/src/core/geometry/geom3/reTesselateCoplanarPolygons.js#L35:L85

Adding an empty array here seems to make no sense.

    vertices2d.reverse()
    minindex = numvertices - minindex - 1
    polygonvertices2d.push(vertices2d)
    polygontopvertexindexes.push(minindex)

Consider using such code?

  for (let polygonindex = 0; polygonindex < numpolygons; polygonindex++) {
    const poly3d = sourcepolygons[polygonindex]
    let numvertices = poly3d.vertices.length
    if (numvertices === 0) continue;

   //Do Something
FishOrBear commented 5 years ago
const area = function (csg) {
  let result = csg.toTriangles().map(function (triPoly) {
    return triPoly.getTetraFeatures(['area'])
  })
  console.log('area', result)
}

csgMeasurements.js

need return result

FishOrBear commented 5 years ago

cag.js Cag should not have this method reTesselated

z3dev commented 5 years ago

@FishOrBear thanks for all the comments. However, we would prefer two things...

  1. Code changes via a pull request
  2. Test cases to prove that the changes are required, as much of the code is untested

Also, we are working on the V2 version of the library now. Hopefully, we can bring any changes into V2 as well. We will let you know if possible or not.

z3dev commented 4 years ago

Yeah. V1 has lots of bugs. We have fixed these bugs in V2, and added automated tests.

Closing this issue.