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

Reorganization of Expansions #182

Closed z3dev closed 4 years ago

z3dev commented 5 years ago

WORK IN PROGRESS. DO NOT MERGE.

This pull request adds the expansion functions as a seperate module. The goals are:

Expansions:

expand

Fixes #66

offset

Fixes #75 Fixes #131 Fixes OpenJSCAD #351

Some small changes to math and geometry modulese are included.

z3dev commented 5 years ago

Examples of offset on paths.

Segments of 0 (chamfer) offset_path_1 offset_path_2

Segments of 1 (edges meet at intersection) offset_path_3

Segments of 32 (fillet with with rounded segments) offset_path_4

kaosat-dev commented 5 years ago

This is gorgeous @z3dev ! Reviewing asap !

z3dev commented 5 years ago

250E4424-9176-49C6-8BB0-D4B0EE10CC1B

(This is actually from a wood working website.)

z3dev commented 5 years ago

For CAG V1, here's what expand() does to a shape with a hole (10x10 square with 5x5 hole). Notice that the hole is getting smaller, not larger.

    let obj1 = CAG.rectangle({radius: [10,10]});
    obj1 = obj1.subtract(CAG.rectangle({radius: [5,5]}));

    let obj2 = obj1.expand(1.0, 8);

V1expand

z3dev commented 5 years ago

For V2, I think the same functionality should be offset. (See expand below)

  let obj1 = primitives.square({size: 10})
  obj1 = booleans.subtract(obj1, primitives.rectangle({size: [5, 5], center: [0,0]}))
  obj1.color = [1,1,0,1] // YELLOW

  let obj2 = expansions.offset({delta: 1}, obj1)
  obj2.color = [0,1,0,1] // GREEN

V2offset

z3dev commented 5 years ago

For V2, the expand makes the whole shape expand (enlarge), including the holes. Note, this is very simular to scale however scale cannot chamfer corners.

  let obj1 = primitives.square({size: 10})
  obj1 = booleans.subtract(obj1, primitives.rectangle({size: [5, 5], center: [0,0]}))
  obj1.color = [1,1,0,1] // YELLOW

  let obj2 = expansions.expand({delta: 1}, obj1)
  obj2.color = [0,1,0,1] // GREEN

V2expand

z3dev commented 4 years ago

@kaosat-dev please review the changes to the API again.

Summary:

In addition, poly2 geometry has been created. And, all expansion functions now use poly2 for measureArea and arePointsInside.

z3dev commented 4 years ago

@kaosat-dev please merge. :)