Code Monkey home page Code Monkey logo

csg.js's People

Contributors

bebbi avatar dav-m85 avatar ingobecker avatar jeremy-brenner avatar jeromew avatar joostn avatar kaosat-dev avatar pentacular avatar plnralex avatar przemyslaw-marchewka avatar stuikomma avatar thehans avatar z3dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csg.js's Issues

Render OpenJSCAD model using three.js

I would like to use three.js to render a 3D model (in order to animate it and study its shadow). And because I like the OpenJSCAD language, I want to use it to build this 3D model. :)

Is it possible to code my 3D model in JS (using the CSG Library) and then use it as a three.js mesh?

checkIfConvex for transformed polygon is failing

From @ZhekaS on March 27, 2014 19:37

The next piece of code will fail with "Not convex" exception:

function main() {
   var points = [ 
            [ 1,  1, 0],
            [-1,  1, 0],
            [-1, -1, 0],
            [ 1, -1, 0]
    ]
   var p = CSG.Polygon.createFromPoints(points);
   var m = CSG.Matrix4x4.rotation([0,0,0], [-0.56, 0.83, 0.00], 110);

   p.transform(m).checkIfConvex();

   return cube([0,0,0], 2)
}

It looks that it is failing whenever the polygon's normal vector is changing it's sign relatively to the original plane. But I am not sure.

Copied from original issue: jscad/OpenJSCAD.org#41

OrthoNormalBasis Observations

OrthoNormalBasis...

  • a very strange class. Could this just be a bunch of functions?
  • there's test code in comments
  • uses vectors for all math, which creates new objects for each calculation

DEV Branch

Or something of the sort... Changes to the library should be made on a separate branch, reviewed, merged, tested, and released.

How about creating a 'dev' branch?

Also, there are changes in the gh-pages branch of the original repository to be reviewed and merged.

Path 2D and 3D Observations

Path2D...

  • constructor does checks for distance... no no... that should be another function
  • interesting... this class does a lot of checking and throws errors. is this an Math class? Is this a major class like CAG/CSG?
  • prototype functions that return other things should move to path2dUtils

Path3D... not found. Do we need one?

Performance: CSG.Vector3D()

From @z3dev on November 28, 2015 7:24

This is just an observation about CSG.Vector3D(x,y,z)

It seems that this is the work horse of CSG internals, converting from "points", arrays, integers, etc. Although good for usability, this function could be partitioned into smaller functions to improve performance. For example, CSG.Vector3D.fromPoint(point) or CSG.Vector3D.fromObject(object), or CSG.Vector3D.fromCoordiatest(x,y,z), etc.

It looks that CSG.Vector3D.Create(x,y,z) has started this process. I think there's even more improvement possible when the 'type" of the argument is known.

Copied from original issue: joostn/OpenJsCad#75

CAG canonicalized()

A few questions on this confusing subject

  • Is this really necessary?
  • Do the CAG.circle(), etc producer functions create already canonicalized objects? If so, why call?
  • When is canonicalized() required? After union? intersection? subtract? scale? It should only be used when necessary.

CSG.Vector3D get and set pseudo-property

  1. Sometimes it is desirable to allow access to a property that returns a dynamically computed value
    or
  2. you may want to reflect the status of an internal variable without requiring the use of explicit method calls.

In JavaScript, this can be accomplished with the use of a getter. It is not possible to simultaneously have a getter bound to a property and have that property actually hold a value, although it is possible to use a getter and a setter in conjunction to create a type of pseudo-property.

By definition, I don't believe that get and set of x/y/z are actually performing any optimizations. Vector3D is created with these values, which are immutable.

Where these added for a reason? Optimization?

Thoughts?

Restructure code, seperate 'core' from helpers & modeling api

In the following months, we need to seperate the most basic 'core' features of CSG.js from all the extra utilities and 3d modeling classes and functions, as well as make the default api for modeling a more functional oriented one :

  • seperate core features
  • organize helpers
  • possibly combine this repo with scad-api as the code currently creating the various shapes will need to be combined with that one (more in tune with the future API we are aiming for)

Is babel really needed ?

I noticed the package.json devdepends (a new verb) on babel for es2015 transpiling. After looking at the files, it seems this is only for having the "import" keyword in the tests. Considering swaping for good ol' require would avoid the whole transpiling stack, I think it would be nice.

Or I am missing something ?

CAG.roundedRectangle() performance

This function should be re-implemented without the use of expand()

The performance is horrible for high resolution corner archs, and the resulting set of sides(points) is also non-nonsensical.

Side Observations

Side...

  • what is _fromFakePolygon() used for? Maybe this should go into sideUtils
  • this might be the basis for a real Line2D class

catastrophic performance of array.reduce() operations returning CSG object

If you do this operation:

arrayOfCSG.reduce((acc, cur) => acc.union(cur), new CSG())

even with not very complex objects, it will likely crash browser/ node
same operation done like this does not have the same issue

result = new CSG().union(arrayOfCSG)

this is due to the implementation of the union operation which calls
.reTesselated().canonicalized() every time

Other than re-implementing union or providing a wrapper with an option to NOT do these operations, not sure how it can be solved

V2 API - 2D Primitive Shapes

Discussion about V2 API for 2D shapes.

Geometries (point / polygon based)

  • polyline2 (?)
    • points [[x,y],[x,y]], ordered
    • open with no measurable area
  • geom2
    • sides [[[x,y],[x,y]],...], unordered
    • closed with measurable area

Geometry Generation

  • triangle ==> geom2
    • sides [1,1,1]
    • angles [60,60,60]
    • center [0,0]
    • start angle 0
  • quadrangle ==> geom2
    • sides [1,1,1,1]
    • angles [90,90,90,90]
    • center [0,0]
    • start angle 0
  • ellipse ==> geom2
    • radius [1,2]
    • center [0,0]
    • segments DEFAULT
    • start angle 0
    • end angle 360
  • polygon ==> geom2
    • points [[x,y],...]

Shapes

  • path2
    • transform (?)
    • curves
    • direction
  • shape2
    • transform
    • geometry

API Declarations

  • triangle
  • quadrangle
  • ellipse
  • polygon
  • path

API Aliases

  • square
    • radius 1 => quadrangle [1,1,1,1) ...
  • rectangle
    • radius [1,2] ==> quadrangle [1,2,1,2] ...
  • circle
    • radius 1 ==> ellipse [1,1] ...

Easy performance improvement - better choice of cutting plane

I recently made a bare bones port of CSG.js to C++. While implementing it, I found that simply tweaking the index that chooses which cutting plane to use while building the BSP had dramatic performance effects. Right now, the first PolygonTreeNode in the list passed to addPolygonTreeNodes is chosen. I found that picking a random index often yielded ~2x speed improvement and even picking the half way point had similar improvements. My tests were all with STL files, so I'm not sure if that skews the results in any way. Haven't tested the effect in CSG.js, but I think it's worth investigating. It makes sense as neighboring polygons are often laid out next to each other, so choosing a random polygon is more likely to provide a balanced tree.

The line of interest is here (changing 0 to just about anything else is better):

let bestplane = polygontreenodes[0].getPolygon().plane

For those interested, my C++ port is here.

Line 2D and 3D Observations

Line2D and Line3D...

  • these reallly are non-ending, directional lines. Not very useful.
  • rename to Ray2D and Ray3D
  • create new Line2D and Line3D for use with CNC and other applications
  • this don't feel like Math classes as these contain other classes , more like User level classes.

Vertex 2D and 3D Observations

Vertex2 and Vertex3...

  • are these necessary? I don't see any additional functionality
  • if kept, shouldn't these be named Vertex2 and Vertex3? It's very confusing to have the same class names
  • can Vector2 be merged into Vertex2?
  • can Vector3 be merged into Vertex3?

Formats.js

Hello, are you planning on also bringing in the formats.js file into this repo? This file had the export formats like .toSTL() that I was using.

Feature Request: Support Colors on CAG Objects

From @z3dev on January 7, 2016 6:19

There have been many requests for this feature on the OpenJSCAD Community as users are starting to using CAG objects to create parametric driven applications for laser cutters and CNC machines.

In addition, SVG supports colors on all paths, polygons, shapes, etc. I'm sure that DXF and other formats are the same. The conversions to and from other formats really requires colors.

As of now, only CSG and CAG objects can be exported so the critical support is for CAG.setColor()

Copied from original issue: joostn/OpenJsCad#78

Vector 2D and 3D Observations

Vector2 and Vector3...

  • those horrible constructor functions should be fromObject() functions. The constructor should take ONLY the values as required for the instance variables, i.e. x,y,z
    • and all calls to this function should be fixed to supply straight values
  • the Vector3.Create() function is not necessary. Fix the constructor
  • get() and set() functions... remove... name the instance variables correctly
    • add a warning to NEVER manipulate the instance variables directly
  • randomNonParallelVector() might be better as a separate function

Isolating/Refactoring the math library

This is to open a discussion and try to help in the work that has started around the math/geometry library.

Maybe at one point it will be interesting to switch the library to one of the existing js math libraries. Nevertheless, it seems that there are still some unclear (to me at least) dependencies between the math part and the library and the rest of the csg library.

After a first look, something unclear appeared to me : primitive2d.js is a big user of math primitives to construct 2d objects. It builds the objects as "points", "path", "cag"

I tend to agree that when building a primitive, I would like to have access to all the math, cag, csg API.

but one unclear dependency appears in this list

  • return CAG.fromPoints(points) -> ok
  • return e2.innerToCAG() -> ?
  • ..

The innerToCAG is implemented in https://github.com/jscad/csg.js/blob/master/src/math/Path2.js#L160 and could probably be replaced with a function to get the points + an isClosed function to check if the path is closed.

On the same vein, expandToCAG and rectangularExtrude probably should'nt be in path. A function "getSides" may help to remove expandToCAG but I don't know what to do of rectangularExtrude. This seems pretty high-level.

So maybe the "primitive" level could include both the building of objects and the transformation of objects like extrusion (or maybe there are already somewhere else)

what do you think ? I could try and send a PR on this.

Matrix4x4 Observations

Matrix4x4

  • rightMultiply1x3Vector & leftMultiply1x3Vector should NOT know Vector3, instead use arguments Array and return Array
  • rightMultiply1x2Vector & leftMultiply1x2Vector should NOT know Vector2, instead use arguments Array and return Array

Matrix4x4:

  • rightMultiply1x3Vector() --> rightMultiply1x3() and adjust for array parameter and Array return
    • same for other such routines
  • translation() rotate(), scale() should not rely on Vector classes

On second thought, how about moving these non-Matrix functions to matrixUtils.js? Then Matrix4x4 becomes "pure".

CSG.Path2D.append{Point,Points,Bezier} are inconsistent and underdocumented

From @fischman on August 9, 2016 21:46

CSG.Path2D's appendPoints and appendBezier methods are not mentioned in https://en.wikibooks.org/wiki/OpenJSCAD_User_Guide (only appendPoint (singular) is documented). More confusingly, appendBezier and appendPoint don't modify their |this| parameter, while appendPoints (plural) does. It would be nice if:

  • all methods were documented; and
  • appendFoo methods were all consistent one way or the other about whether they affect |this| or whether their return value needs to be assigned back to the callee. (IMO appendFoo should affect their callee)

Code below demonstrates the issue in pairs: bezier in 1&2, point in 3&4, points in 5&6.

function test1() {
    var path = new CSG.Path2D([[0,0], [0, 5]]);
    path = path.appendBezier([null, [10,0]]);
    return path.close().innerToCAG();
}

function test2() {
    var path = new CSG.Path2D([[0,0], [0, 5]]);
    /* path = */ path.appendBezier([null, [10,0]]);
    return path.close().innerToCAG();
}

function test3() {
    var path = new CSG.Path2D([[0,0], [0, 5]]);
    path = path.appendPoint([10,0]);
    return path.close().innerToCAG();
}

function test4() {
    var path = new CSG.Path2D([[0,0], [0, 5]]);
    /* path = */ path.appendPoint([10,0]);
    return path.close().innerToCAG();
}

function test5() {
    var path = new CSG.Path2D([[0,0], [0, 5]]);
    path = path.appendPoints([[10,0]]);
    return path.close().innerToCAG();
}

function test6() {
    var path = new CSG.Path2D([[0,0], [0, 5]]);
    /* path = */ path.appendPoints([[10,0]]);
    return path.close().innerToCAG();
}

function main() {
    // return test1();  // PASS
    // return test2();  // FAIL: Uncaught Error: CAG shape needs at least 3 points
    // return test3();  // PASS
    // return test4();  // FAIL: Uncaught Error: CAG shape needs at least 3 points
    // return test5();  // PASS
    return test6();  // PASS!
}

Thanks for providing this great resource, BTW :)

Copied from original issue: jscad/OpenJSCAD.org#165

Polygon 2D and 3D Observations

Polygon3...

  • all prototype functions that return other things should move to general functions
    • maybe polygonUtils ?
  • constructor should take exactly what's required only
  • is CSGDEBUG really supported?

Polygon 2D... current just stubs. Do we need one for proper 2D functionality?

Feature Request: RoundRadius on CSG.roundedCylinder()

From @z3dev on October 1, 2015 2:6

This is a very useful function to make rounded cylinders of a given radius, but the rounded end of the cylinder should also be configurable. Currently, the rounded end of the cylinder is the same as the radius of the cylinder. But anything between 0 < rounded end radius <= radius is possible.

Parameters:
// start: start point of cylinder (default [0, -1, 0])
// end: end point of cylinder (default [0, 1, 0])
// radius: radius of cylinder (default 1), must be a scalar
// resolution: determines the number of polygons per 360 degree revolution (default 12)
// normal: a vector determining the starting angle for tesselation. Should be non-parallel to start.minus(end)

Add...
// roundedRadius: radius of rounded end of cylinder, default radius of cylinder

1

Copied from original issue: joostn/OpenJsCad#72

Performance Test Suite

I have a few tests that are executed for each release of OpenJSCAD.org.

It would be great if others could supply a few words of wisdom, guidance, caution, etc.

Feature Request: Correct closure mistakes in Path2D

From @z3dev on November 2, 2015 4:25

I came across an issue while writing the conversion routine for SVG to CAG. SVG supports the concept of 'closure" via the 'z' command in PATH elements. The 'z' command functionality is the same as Path2D.close().

However, SVG also supports 'manual' closure of paths by joining the last line segment to the starting point. This is not possible in Path2D.

I think that Path2D.appendPoint(), etc routines could check for the 'manual' closure. Or Path2D.close() could correct the internal set of points if start and end points are the same.

Copied from original issue: joostn/OpenJsCad#74

Issue with core Matrix4x4.translation function

From @rasmuskr on April 27, 2016 22:9

Hey

I am pretty sure that the function CSG.Matrix4x4.translation is broken from:
https://github.com/Spiritdude/OpenJSCAD.org/blob/master/csg.js#L3586

// Create an affine matrix for translation:
    CSG.Matrix4x4.translation = function(v) {
        // parse as CSG.Vector3D, so we can pass an array or a CSG.Vector3D
        var vec = new CSG.Vector3D(v);
        var els = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vec.x, vec.y, vec.z, 1];
        return new CSG.Matrix4x4(els);
    };

The matrix should look like this

var els = [1, 0, 0, vec.x, 0, 1, 0, vec.y, 0, 0, 1, vec.z, 0, 0, 0, 1];

I may fix this and open a PR but dont have the tools at the computer I am currently on.

Copied from original issue: jscad/OpenJSCAD.org#148

Question: clarify orientation of skew cylinders/cones

From @BenW0 on July 26, 2016 10:10

When I create a CSG.cylinder object, I expect a cylinder parallel to the line between start and end, with flat end caps perpendicular to the line. However, when I execute the following in openjscad.org (or the debugger on openjscad.github.io), I obtain a cylinder with skewed end caps, not at all what I was expecting.

function main(){
    return CSG.cylinder({start:[0,0,0], end:[2, 2, 2], radiusStart:1, radiusEnd:1});
}

Output as I see it:

cylinder

This is not the case if any one of the end coordinate elements is 0 (i.e. the cylinder lies in one of the x/y/z planes).

If this is the intended behavior, could you help me understand what is going on? I will be happy to submit a documentation patch once I get my head around what CSG.cylinder() is supposed to do so I can write one.

Thanks

Copied from original issue: jscad/OpenJSCAD.org#163

General Observations

utils.js ...

  • move solve2Linear() to lineUtils
  • the remainder looks like sort utility functions... HINT

CagValidation.js...

  • isSelfIntersecting() has if (debug)... what is this? Dead code?

CsgProjections.js ...

  • projectToOrthoNormalBasis() is horribly inefficient. ๐Ÿ’€

FixTJuctions.js...

  • deleteSides() has throw statements... why? Debugging? If so then _CSGDEBG should be used

Inconsistent detection of Array
- obj instanceof Array
- isArray(obj
- length in obj
- obj.prototype is Array
Maybe there are more but we should use the JavaScript standard. Whatever that is...

CSG.js...

  • getFeatures() seems like a nice function, but should this be in Utils
    • also, can this be applied to CAG?
  • toPolygons() returns the instance variable. Why? This breaks from the standard of being immutable. Is this used?

General...

  • the split of factories is good. But there are more... Vector, Lines, etc.
  • functions that convert from on class to another should be split out, for example extrude, toPoints, projection, etc.
    • a general toPoints() maybe possible
  • functions that convert to non-core or non-math should be come API, such as toTriangles()
  • where should toCompactBinary and fromCompactBinary exist? These are really special and should live separately
    • toObject() and fromObject() as well? There may be special logic required, like now.

Properties...

  • a totally unused class? I know nothing about this

Connector...

  • rename connectors.js to Connectors.js for consistency

ConnectorList...

  • this is one strange thing... is this used internally, or something bolted on?

Object Prototype Mutators...

  • I understand these but really question the worth of this morphing of classes
    • is maintaining these directly in each class difficult? Is this just being lazy?
    • can JavaScript engines optimize these functions?
    • how to add documentation for these?
    • is this really the way objects should be "extended"?

Trees...

  • there are some checks that throw which are not wrapped by _CSGDEBUG

General...

  • the unreliability of instanceOf shows that we should not use it
  • just wondering... we test for array parameter... but could the API also accept iterable objects?

Scalability Issue with csg.js

Hi,

It looks like the scalability of csg.js is O(n^2). See code in https://github.com/mtippett/jscad-test/tree/master/jscad-csg-perf, this includes both the nodejs application and a svg created with Brendan Gregg's flamegraph tool.

Basically this is an array of coplanar cubes.

screen shot 2017-02-12 at 1 28 29 am

Looking at the flamegraph generated for a 40x40 square (1600 elements), the scalability issue is clear in the code searching for a union. The original npm jscad code would not re-tesselate and optimize, so would result in larger files. The file size is workable with jscad/csg.js, however the scalability needs to be improved.

screen shot 2017-02-12 at 1 38 17 am

Copyrights and Licences

@joostn The original repository has copyrights from both you and Evan. Those will be honored and presented to others.

We hope that this contribution to the jscad organization can be released under the MIT license.

Is that fine?

Spurious CAG "area is not closed!" error

From @fischman on October 26, 2016 8:15

The code below generates a DXF just fine if the final statement returns either of the two CAGs, but when both are returned the DXF generation dies with:
Uncaught Error: Area is not closed!

function main() {
    const c = CAG.fromSides([
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-45.82118740347841168159, -16.85726810555620147625)), new CAG.Vertex(new CSG.Vector2D(-49.30331715865012398581, -14.68093629710870118288))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.10586702080816223770, -15.27604177352110781385)), new CAG.Vertex(new CSG.Vector2D(-48.16645938811709015681, -15.86317173589183227023))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.60419521731581937729, -14.89550781504266296906)), new CAG.Vertex(new CSG.Vector2D(-49.42407001323204696064, -15.67605088949303393520))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.05727291218684626983, -15.48661638542171203881)), new CAG.Vertex(new CSG.Vector2D(-49.10586702080816223770, -15.27604177352110781385))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.30706235399220815907, -15.81529674600091794900)), new CAG.Vertex(new CSG.Vector2D(-46.00505780290426827150, -17.21108547999804727624))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-46.00505780290426827150, -17.21108547999804727624)), new CAG.Vertex(new CSG.Vector2D(-45.85939703723252591772, -17.21502856394236857795))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-45.85939703723252591772, -17.21502856394236857795)), new CAG.Vertex(new CSG.Vector2D(-45.74972032664388166268, -17.11909303495791334626))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-45.74972032664388166268, -17.11909303495791334626)), new CAG.Vertex(new CSG.Vector2D(-45.73424573227583067592, -16.97420292661295349035))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-45.73424573227583067592, -16.97420292661295349035)), new CAG.Vertex(new CSG.Vector2D(-45.82118740347841168159, -16.85726810555620147625))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.30331715865012398581, -14.68093629710870118288)), new CAG.Vertex(new CSG.Vector2D(-49.45428884427643367871, -14.65565769658912387285))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.45428884427643367871, -14.65565769658912387285)), new CAG.Vertex(new CSG.Vector2D(-49.57891661679624917269, -14.74453612941635327616))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.57891661679624917269, -14.74453612941635327616)), new CAG.Vertex(new CSG.Vector2D(-49.60419521731581937729, -14.89550781504266296906))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.42407001323204696064, -15.67605088949303393520)), new CAG.Vertex(new CSG.Vector2D(-49.30706235399220815907, -15.81529674600091794900))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-48.16645938811709015681, -15.86317173589183227023)), new CAG.Vertex(new CSG.Vector2D(-49.05727291218684626983, -15.48661638542171203881))),
    ]);

    const d = CAG.fromSides([
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.03431352173912216585, -15.58610714407888764299)), new CAG.Vertex(new CSG.Vector2D(-49.21443872582289458251, -14.80556406962851667686))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-68.31614651314507113966, -3.10790373951434872879)), new CAG.Vertex(new CSG.Vector2D(-49.34036769611472550423, -15.79733157434056778357))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.58572929483430868913, -14.97552686612213790340)), new CAG.Vertex(new CSG.Vector2D(-49.53755741140093959984, -15.18427183431472826669))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.53755741140093959984, -15.18427183431472826669)), new CAG.Vertex(new CSG.Vector2D(-54.61235529924312714911, -11.79066769321313756791))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.30227466841120076424, -14.68159232649114187552)), new CAG.Vertex(new CSG.Vector2D(-68.09792828135776687759, -2.77270756611528668145))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.21443872582289458251, -14.80556406962851667686)), new CAG.Vertex(new CSG.Vector2D(-49.30227466841120076424, -14.68159232649114187552))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.34036769611472550423, -15.79733157434056778357)), new CAG.Vertex(new CSG.Vector2D(-49.18823337756091262918, -15.82684012194931710837))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.18823337756091262918, -15.82684012194931710837)), new CAG.Vertex(new CSG.Vector2D(-49.06069007212390431505, -15.73881563386780157998))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-49.06069007212390431505, -15.73881563386780157998)), new CAG.Vertex(new CSG.Vector2D(-49.03431352173912216585, -15.58610714407888764299))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-68.09792828135776687759, -2.77270756611528668145)), new CAG.Vertex(new CSG.Vector2D(-68.24753735887460948106, -2.74623350179570024920))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-68.24753735887460948106, -2.74623350179570024920)), new CAG.Vertex(new CSG.Vector2D(-68.37258141465594007968, -2.83253376987636329432))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-68.37258141465594007968, -2.83253376987636329432)), new CAG.Vertex(new CSG.Vector2D(-68.40089829889257089235, -2.98180502037078554167))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-68.40089829889257089235, -2.98180502037078554167)), new CAG.Vertex(new CSG.Vector2D(-68.31614651314507113966, -3.10790373951434872879))),
        new CAG.Side(new CAG.Vertex(new CSG.Vector2D(-54.61235529924312714911, -11.79066769321313756791)), new CAG.Vertex(new CSG.Vector2D(-49.58572929483430868913, -14.97552686612213790340))),
    ]);

    return [c];  // "Generate DXF" works.
    return [d];  // "Generate DXF" works
    return [c, d];  // "Generate DXF" doesn't work.
}

Copied from original issue: jscad/OpenJSCAD.org#185

Tolerances

@joostn I'm revisiting all the hard coded tolerances in the library, and trying to make sense out of the values being applied.

I've introduced CSG.ESP = 1e-5 for the default value, but think there should be a few more tolerances available. Maybe...

CSG.distanceEPS = 1e-5
CSG.areaEPS = (CSG.distanceEPS*CSG.distanceEPS)/2;
CSG.angleEPS = 1e-3; // percent of angle

Thoughts?

Remove Object Mutators

The mutator functions for adding functions to the objects is improper, and should be corrected.

csg.js/csg.js

Line 178 in e5b922c

addTransformationMethodsToPrototype(CSG.prototype)

they are evil because they are done OUTSIDE the object, so that when you directly import the 'original' objects, (CSG) they are actually missing pieces.

  • I understand these but really question the worth of this morphing of classes
  • is maintaining these directly in each class difficult? Is this just being lazy?
  • can JavaScript engines optimize these functions?
  • how to add documentation for these?
  • is this really the way objects should be "extended"?

Self-documenting Comments

I ran into JSDOC last week, and decided to try generating documentation from the comments in the code. The results were really good, with full explanations for constructors, parameters, return values, and examples. And the README can be integrated into the documentation as well.

Very impressed.

I'd like to propose a shift to use JSDOC, which means a slow migration to the comment styles in the code. I think this will improve not only user documentation, but also allow others to understand this library quickly.

http://usejsdoc.org

exported stl object is not sliceable with slic3r

I am moving issue jscad/io#19

basically the model

function main() {
   return difference(
         cube({size: 2, center: true}),
         cube({size: [1,1,10], center: true})
      )
}

cannot be sliced by slic3r apparently because of "manifold" problems when exported as stl or amf.
The same model exported as stl with openscad can be sliced correctly.

The problem could be in the way csg.js builds the model (ordering of vertexes, normals,)

I am currently trying to compare the models as exported by openscad & jscad to understand what is happening.

MATH Observations

Classes...

  • constructor functions should be minimal, expecting exact arguments and performing no checks
  • from* functions should exist for anything more, with full checks

Utils...

  • does iPolygon3.isStrictlyConvexPoint() belong here?
  • does Polygon3.isConvexPoint() belong here?
  • does Vector3.randomNonParallelVector() belong here?
  • does lineUtils belong here?
  • does Math reTesselateCoplanarPolygons() belong here?

General...

  • a lot of the math is performed by Vector, even for non-vectored classes. There must be a lot of "new Vector" calls for any math. Horrible for memory and performance

Bug: Compact Binary Format ignores Properties

From @z3dev on January 16, 2016 6:10

Applications may want to add properties to CSG and CAG objects, which can then be used when converting to different formats, etc. Even the internal "connectors" are silently ignored in the compact binary format.

For example, I want to set and save special properties for large designs, i.e. position of buttons, sizes of curves, etc. The JSON.stringify() will convert the property values to strings easily, but there are NO properties because the compact binary format doesn't save/restore properties.

Copied from original issue: joostn/OpenJsCad#79

CSG.subtract yield artefact polygons sometimes

I am working on a prototype project currently and make heavy use of csg. Prior tests with this lib resulted in perfect results as long as the test-solids where "handcrafted" and placed around 0/0/0 coordinates. The same operations where performed on those test-solids as under runtime conditions and resulted in 100% correct results.
Now with procedurally generated solids under runtime conditions problems with subtract and cutByPlane started to appear. Interestingly even slight changes to the sizes, positions or angles of the solids resulted either in a perfect result or a problem.

The problem yields something I would describe as shadow or artefact polygons that spill over from the subtracted solid or in case of cutByPlane, seem like a mirrored reflection. These shadow-polygons are thin/one-sided, so the problem seems not to come from very-thin proximities. I guess these edge cases result from numbers that close down to the Epsilon-constants. Changing them did not change anything of the behaviour however, so I am not certain here yet.

The solids I work with are all very simple and basic cube-likes with very low poly count. Exporting them as JSON objects into a testbed resulted in the same problems there.

I would like to contribute to this project and maybe find/solve the problem myself however I do not really understand the inner workings of this lib and could use a hint or two to get me going. Is this problem a known issue?
Secondly if this issue is yet unknown/unresolved, is there a simple way to share such problems (i.g. jsfiddle like - dump json-csg-solids onto live-test-system ) so that others can see and reproduce the problem fast?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.