Skip to content

Instantly share code, notes, and snippets.

@kaosat-dev
Last active July 11, 2017 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaosat-dev/dfad0f50aa4e844e0958d7c7cf308799 to your computer and use it in GitHub Desktop.
Save kaosat-dev/dfad0f50aa4e844e0958d7c7cf308799 to your computer and use it in GitHub Desktop.
CSG.js restructuring notes

CSG.js notes:

  • CAG : any boolean ops converts to CSG and back again !
    • sides are very inneficient data structures : there are duplicates of every points! (end of one side, start of next)
    • CAG’s could retain api by just providing accessors to underlying data structures
  • Vertex vs Vector :
    • potentially redundant ? needs more investigating
    • “only” has an extra ‘tag’ field nothing more
  • methods that can be easily extracted (barely any ‘this’ references, if at all, etc)
    • overCutInsideCorners
      • used in tests only => good candidate
    • getOutlinePaths
      • used in tests
      • used in examples(user api)
      • used in dxf serializer
      • used in svg serializer
    • toCompactBinary
      • used in tests
      • used in jscad core
    • expandedShell
      • used in tests
      • main function underlying expand()
  • dependencies:
    • extruder => _toPlanePolygons
    • _toPlanePolygons => _toCSGWall
    • union => _toCSGWall
    • subtract => _toCSGWall
    • intersect => _toCSGWall
  • Shapes:
    • Cylinders:
      • RoundedCylinder has no start & end radius specifiable
      • RoundedCylinder default resolution is different from other cylinders
      • Repeated , complex internal code
      • how is cylinderEliptic any different from a standard cylinder ? => can specify 2D radius
        • should still be merged
      • roundedCylinder has sectorAngle parameter: resolution is NOT adapted to angle size : i.e. small angle seems higher res than high angle
      • SCAD-API: cylinderEliptic is not wrapped

Higher level operations, closer to 'standard cad':
Revolve feature:

  • can 'replace' current rotateExtrude (can only do a full 360 extrude)
  • can be emulated with solidFromSlices: (because it can 'close' shapes) ex
function revolve (shape, options = {}) {
  const defaults = {
    revolveAngle: 90,
    resolution: 10
  }
  const {revolveAngle, resolution} = Object.assign({}, defaults, options)

  return shape.solidFromSlices({
    numslices: resolution,
    loop: false,
    callback: function (t, slice) {
      return this.rotate([0, 20, 0], [-1, 0, 0], revolveAngle / (resolution - 1) * slice)
    }
  })
}

Problem: currently it needs 3d polygons (????)

@z3dev
Copy link

z3dev commented Jun 12, 2017

Vector2D and Vector3D... _x,_y,_x attributes to [1,2,3] internal storage

@z3dev
Copy link

z3dev commented Jun 12, 2017

Test functions to prove correctness of CAG; closed, rotation, etc.

Hopefully, this will find bugs in logic, and remove the need for canonicalize()

@z3dev
Copy link

z3dev commented Jun 12, 2017

Decide on common checks for parameters to API functions.

  • perform checks, throw exceptions
  • perform checks, use defaults
  • no checks, continue processing

Possibly, checks are controlled by Debug settings. This would allow designers to get more information about incorrectly passed values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment