@@ -92,8 +92,6 @@ for solid CAD anyway.
92
92
93
93
*/
94
94
95
- ( function ( module ) {
96
-
97
95
var _CSGDEBUG = false ;
98
96
99
97
function fnNumberSort ( a , b ) {
@@ -1314,6 +1312,32 @@ for solid CAD anyway.
1314
1312
var newvertices = polygon . vertices . slice ( 0 ) ;
1315
1313
newvertices . splice ( insertionvertextagindex , 0 , endvertex ) ;
1316
1314
var newpolygon = new CSG . Polygon ( newvertices , polygon . shared /*polygon.plane*/ ) ;
1315
+
1316
+ // FIX
1317
+ //calculate plane with differents point
1318
+ if ( isNaN ( newpolygon . plane . w ) ) {
1319
+
1320
+ var found = false ,
1321
+ loop = function ( callback ) {
1322
+ newpolygon . vertices . forEach ( function ( item ) {
1323
+ if ( found ) return ;
1324
+ callback ( item ) ;
1325
+ } )
1326
+ } ;
1327
+
1328
+ loop ( function ( a ) {
1329
+ loop ( function ( b ) {
1330
+ loop ( function ( c ) {
1331
+ newpolygon . plane = CSG . Plane . fromPoints ( a . pos , b . pos , c . pos )
1332
+ if ( ! isNaN ( newpolygon . plane . w ) ) {
1333
+ found = true ;
1334
+ }
1335
+ } )
1336
+ } )
1337
+ } )
1338
+ }
1339
+ // FIX
1340
+
1317
1341
polygons [ polygonindex ] = newpolygon ;
1318
1342
1319
1343
// remove the original sides from our maps:
@@ -1959,11 +1983,11 @@ for solid CAD anyway.
1959
1983
this . _z = 0 ;
1960
1984
}
1961
1985
}
1962
- } else if ( ( 'x ' in x ) && ( 'y ' in x ) ) {
1963
- this . _x = parseFloat ( x . x ) ;
1964
- this . _y = parseFloat ( x . y ) ;
1965
- if ( 'z ' in x ) {
1966
- this . _z = parseFloat ( x . z ) ;
1986
+ } else if ( ( '_x ' in x ) && ( '_y ' in x ) ) {
1987
+ this . _x = parseFloat ( x . _x ) ;
1988
+ this . _y = parseFloat ( x . _y ) ;
1989
+ if ( '_z ' in x ) {
1990
+ this . _z = parseFloat ( x . _z ) ;
1967
1991
} else {
1968
1992
this . _z = 0 ;
1969
1993
}
@@ -5439,7 +5463,7 @@ for solid CAD anyway.
5439
5463
CSG . addCenteringToPrototype = function ( prot , axes ) {
5440
5464
prot . center = function ( cAxes ) {
5441
5465
cAxes = Array . prototype . map . call ( arguments , function ( a ) {
5442
- return a . toLowerCase ( ) ;
5466
+ return a ; // .toLowerCase();
5443
5467
} ) ;
5444
5468
// no args: center on all axes
5445
5469
if ( ! cAxes . length ) {
@@ -5462,15 +5486,14 @@ for solid CAD anyway.
5462
5486
this . isCanonicalized = false ;
5463
5487
} ;
5464
5488
5465
- // create from an untyped object with identical property names.
5489
+ // create from an untyped object with identical property names:
5466
5490
CAG . fromObject = function ( obj ) {
5467
5491
var sides = obj . sides . map ( function ( s ) {
5468
5492
return CAG . Side . fromObject ( s ) ;
5469
5493
} ) ;
5470
5494
var cag = CAG . fromSides ( sides ) ;
5471
- cag . isCanonicalized = obj . isCanonicalized ;
5472
5495
return cag ;
5473
- } ;
5496
+ }
5474
5497
5475
5498
// Construct a CAG from a list of `CAG.Side` instances.
5476
5499
CAG . fromSides = function ( sides ) {
@@ -5583,6 +5606,41 @@ for solid CAD anyway.
5583
5606
return CAG . fromSides ( sides ) ;
5584
5607
} ;
5585
5608
5609
+ /* Construct an ellispe
5610
+ options:
5611
+ center: a 2D center point
5612
+ radius: a 2D vector with width and height
5613
+ resolution: number of sides per 360 degree rotation
5614
+ returns a CAG object
5615
+ */
5616
+ CAG . ellipse = function ( options ) {
5617
+ options = options || { } ;
5618
+ var c = CSG . parseOptionAs2DVector ( options , "center" , [ 0 , 0 ] ) ;
5619
+ var r = CSG . parseOptionAs2DVector ( options , "radius" , [ 1 , 1 ] ) ;
5620
+ r = r . abs ( ) ; // negative radii make no sense
5621
+ var res = CSG . parseOptionAsInt ( options , "resolution" , CSG . defaultResolution2D ) ;
5622
+
5623
+ var e2 = new CSG . Path2D ( [ [ c . x , c . y + r . y ] ] ) ;
5624
+ e2 = e2 . appendArc ( [ c . x , c . y - r . y ] , {
5625
+ xradius : r . x ,
5626
+ yradius : r . y ,
5627
+ xaxisrotation : 0 ,
5628
+ resolution : res ,
5629
+ clockwise : true ,
5630
+ large : false ,
5631
+ } ) ;
5632
+ e2 = e2 . appendArc ( [ c . x , c . y + r . y ] , {
5633
+ xradius : r . x ,
5634
+ yradius : r . y ,
5635
+ xaxisrotation : 0 ,
5636
+ resolution : res ,
5637
+ clockwise : true ,
5638
+ large : false ,
5639
+ } ) ;
5640
+ e2 = e2 . close ( ) ;
5641
+ return e2 . innerToCAG ( ) ;
5642
+ } ;
5643
+
5586
5644
/* Construct a rectangle
5587
5645
options:
5588
5646
center: a 2D center point
@@ -6022,23 +6080,15 @@ for solid CAD anyway.
6022
6080
// by rotating around the plane's origin. An additional right-hand vector should be specified as well,
6023
6081
// and this is exactly a CSG.OrthoNormalBasis.
6024
6082
// orthonormalbasis: characterizes the plane in which to extrude
6025
- // depth: thickness of the extruded shape. Extrusion is done from the plane towards above (unless
6026
- // symmetrical option is set, see below)
6027
- //
6028
- // options:
6029
- // {symmetrical: true} // extrude symmetrically in two directions about the plane
6030
- extrudeInOrthonormalBasis : function ( orthonormalbasis , depth , options ) {
6083
+ // depth: thickness of the extruded shape. Extrusion is done symmetrically above and below the plane.
6084
+ extrudeInOrthonormalBasis : function ( orthonormalbasis , depth ) {
6031
6085
// first extrude in the regular Z plane:
6032
6086
if ( ! ( orthonormalbasis instanceof CSG . OrthoNormalBasis ) ) {
6033
6087
throw new Error ( "extrudeInPlane: the first parameter should be a CSG.OrthoNormalBasis" ) ;
6034
6088
}
6035
6089
var extruded = this . extrude ( {
6036
6090
offset : [ 0 , 0 , depth ]
6037
6091
} ) ;
6038
- if ( CSG . parseOptionAsBool ( options , "symmetrical" , false ) )
6039
- {
6040
- extruded = extruded . translate ( [ 0 , 0 , - depth / 2 ] ) ;
6041
- }
6042
6092
var matrix = orthonormalbasis . getInverseProjectionMatrix ( ) ;
6043
6093
extruded = extruded . transform ( matrix ) ;
6044
6094
return extruded ;
@@ -6048,8 +6098,8 @@ for solid CAD anyway.
6048
6098
// one of ["X","Y","Z","-X","-Y","-Z"]
6049
6099
// The 2d x axis will map to the first given 3D axis, the 2d y axis will map to the second.
6050
6100
// See CSG.OrthoNormalBasis.GetCartesian for details.
6051
- extrudeInPlane : function ( axis1 , axis2 , depth , options ) {
6052
- return this . extrudeInOrthonormalBasis ( CSG . OrthoNormalBasis . GetCartesian ( axis1 , axis2 ) , depth , options ) ;
6101
+ extrudeInPlane : function ( axis1 , axis2 , depth ) {
6102
+ return this . extrudeInOrthonormalBasis ( CSG . OrthoNormalBasis . GetCartesian ( axis1 , axis2 ) , depth ) ;
6053
6103
} ,
6054
6104
6055
6105
// extruded=cag.extrude({offset: [0,0,10], twistangle: 360, twiststeps: 100});
@@ -6544,14 +6594,17 @@ for solid CAD anyway.
6544
6594
6545
6595
But we'll keep CSG.Polygon2D as a stub for backwards compatibility
6546
6596
*/
6597
+
6547
6598
CSG . Polygon2D = function ( points ) {
6548
6599
var cag = CAG . fromPoints ( points ) ;
6549
6600
this . sides = cag . sides ;
6550
6601
} ;
6551
6602
CSG . Polygon2D . prototype = CAG . prototype ;
6552
6603
6553
6604
6605
+ //console.log('module', module)
6606
+ //module.CSG = CSG;
6607
+ //module.CAG = CAG;
6608
+ //})(this); //module to export to
6554
6609
6555
- module . CSG = CSG ;
6556
- module . CAG = CAG ;
6557
- } ) ( this ) ; //module to export to
6610
+ module . exports = { CSG , CAG } //({})(module)
0 commit comments