Skip to content

Commit 68a0558

Browse files
authored
fix(CAG): reverted back CAG to default to canonicalized = false
- 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
1 parent c660d13 commit 68a0558

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

csg.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,7 +5592,7 @@ for solid CAD anyway.
55925592
*/
55935593
var CAG = function() {
55945594
this.sides = [];
5595-
this.isCanonicalized = true;
5595+
this.isCanonicalized = false;
55965596
};
55975597

55985598
/** Reconstruct a CAG from an object with identical property names.
@@ -5617,7 +5617,7 @@ for solid CAD anyway.
56175617
cag.sides = sides;
56185618
return cag;
56195619
};
5620-
5620+
56215621
/** Construct a CAG from a list of points (a polygon).
56225622
* The rotation direction of the points is not relevant.
56235623
* The points can define a convex or a concave polygon.
@@ -6751,10 +6751,5 @@ for solid CAD anyway.
67516751
};
67526752
CSG.Polygon2D.prototype = CAG.prototype;
67536753

6754+
module.exports = {CSG, CAG}
67546755

6755-
//console.log('module', module)
6756-
//module.CSG = CSG;
6757-
//module.CAG = CAG;
6758-
//})(this); //module to export to
6759-
6760-
module.exports = {CSG,CAG}//({})(module)

test/cag-conversions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ test('CAG should convert to and from sides', t => {
6161
var f1 = CAG.fromSides(s1)
6262
t.deepEqual(c1, f1)
6363
var s2 = c2.sides
64-
var f2 = CAG.fromSides(s2)
64+
var f2 = CAG.fromSides(s2).canonicalized()
6565
t.deepEqual(c2, f2)
6666
var s3 = c3.sides
67-
var f3 = CAG.fromSides(s3)
67+
var f3 = CAG.fromSides(s3).canonicalized()
6868
t.deepEqual(c3, f3)
6969
var s4 = c4.sides
70-
var f4 = CAG.fromSides(s4)
70+
var f4 = CAG.fromSides(s4).canonicalized()
7171
t.deepEqual(c4, f4)
7272
})
7373

test/cag-new.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {CSG, CAG} from '../csg'
88
// - verify that the CAG converts to/from properly
99
//
1010
test('New CAG should contain nothing', t => {
11-
var cag = new CAG()
11+
const cag = new CAG()
1212

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

39-
t.deepEqual(cag.canonicalized(), cag)
39+
//t.deepEqual(cag.canonicalized(), cag)
4040

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

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

6262
// test internals
6363
var csg1 = cag._toCSGWall(0, 0)

test/cag-various.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const test = require('ava')
2+
const {CAG, CSG} = require('../csg')
3+
4+
test('CAG getOutlinePaths should work correctly', t => {
5+
const radius = 10
6+
const cag = CAG.fromPoints([
7+
[-radius, -radius, 0],
8+
[radius, -radius, 0],
9+
[radius, radius, 0]
10+
]).expand(2, CSG.defaultResolution2D)
11+
12+
const result = cag.getOutlinePaths()
13+
14+
t.deepEqual(cag.sides.length, 35)
15+
t.deepEqual(cag.isCanonicalized, true)
16+
})

0 commit comments

Comments
 (0)