Skip to content

Commit

Permalink
fix(CAG): reverted back CAG to default to canonicalized = false
Browse files Browse the repository at this point in the history
- this fixed some issues dealing in some official OpenJSCAD examples
- enables .canonicalized() to work correctly again
- added tests to cover cases
- updated existing tests to match new default
  • Loading branch information
kaosat-dev committed May 20, 2017
1 parent c660d13 commit 68a0558
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
11 changes: 3 additions & 8 deletions csg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5592,7 +5592,7 @@ for solid CAD anyway.
*/
var CAG = function() {
this.sides = [];
this.isCanonicalized = true;
this.isCanonicalized = false;
};

/** Reconstruct a CAG from an object with identical property names.
Expand All @@ -5617,7 +5617,7 @@ for solid CAD anyway.
cag.sides = sides;
return cag;
};

/** Construct a CAG from a list of points (a polygon).
* The rotation direction of the points is not relevant.
* The points can define a convex or a concave polygon.
Expand Down Expand Up @@ -6751,10 +6751,5 @@ for solid CAD anyway.
};
CSG.Polygon2D.prototype = CAG.prototype;

module.exports = {CSG, CAG}

//console.log('module', module)
//module.CSG = CSG;
//module.CAG = CAG;
//})(this); //module to export to

module.exports = {CSG,CAG}//({})(module)
6 changes: 3 additions & 3 deletions test/cag-conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ test('CAG should convert to and from sides', t => {
var f1 = CAG.fromSides(s1)
t.deepEqual(c1, f1)
var s2 = c2.sides
var f2 = CAG.fromSides(s2)
var f2 = CAG.fromSides(s2).canonicalized()
t.deepEqual(c2, f2)
var s3 = c3.sides
var f3 = CAG.fromSides(s3)
var f3 = CAG.fromSides(s3).canonicalized()
t.deepEqual(c3, f3)
var s4 = c4.sides
var f4 = CAG.fromSides(s4)
var f4 = CAG.fromSides(s4).canonicalized()
t.deepEqual(c4, f4)
})

Expand Down
6 changes: 3 additions & 3 deletions test/cag-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {CSG, CAG} from '../csg'
// - verify that the CAG converts to/from properly
//
test('New CAG should contain nothing', t => {
var cag = new CAG()
const cag = new CAG()

// conversion functions
t.is(cag.toString(), 'CAG (0 sides):\n')
Expand Down Expand Up @@ -36,7 +36,7 @@ test('New CAG should contain nothing', t => {
test('New CAG should do nothing', t => {
var cag = new CAG()

t.deepEqual(cag.canonicalized(), cag)
//t.deepEqual(cag.canonicalized(), cag)

// test for basic transforms
var cagB = CAG.rectangle()
Expand All @@ -57,7 +57,7 @@ test('New CAG should do nothing', t => {
})

test('New CAG should return empty values', t => {
var cag = new CAG()
var cag = new CAG().canonicalized()

// test internals
var csg1 = cag._toCSGWall(0, 0)
Expand Down
16 changes: 16 additions & 0 deletions test/cag-various.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const test = require('ava')
const {CAG, CSG} = require('../csg')

test('CAG getOutlinePaths should work correctly', t => {
const radius = 10
const cag = CAG.fromPoints([
[-radius, -radius, 0],
[radius, -radius, 0],
[radius, radius, 0]
]).expand(2, CSG.defaultResolution2D)

const result = cag.getOutlinePaths()

t.deepEqual(cag.sides.length, 35)
t.deepEqual(cag.isCanonicalized, true)
})

0 comments on commit 68a0558

Please sign in to comment.