Apr 23, 2017

  • Ivaan Nazaroff
    While javaScript and I go way back (we made friends through trying times) I'm new to cad, new to parametric cad and new to OpenJSCad.

    Gosh I love OpenJSCad. I'm looking for ways to quit my day job. 🙂

    I ran into a limitation in followWith:
    "target cag needs same sides count as start cag"

    What are the gotchas in implementing that behaviour?

    I've forked the project and have replaced the flow through that throw with code that works at least for my purposes. I suspect, though, before issuing any sort of pull request I'd need to solve for the general case.

    What are the edge cases I've likely missed? Are there insurmountable walls on this path? Tell my why this is a dumb idea 😉


    2 plus ones
    no shares
    Shared publicly•View activity

    Jeff Gay
    Cool! The DEV branch has been broken out into several libraries, so you will have to pull and apply the changes to the correct library.

    Please start at the home page of the new JSCAD organization. github.com - Jscad

    All PRs are accepted. We are also asking developers to contribute test case as well, so be prepared.

    Apr 23, 2017
    Ivaan Nazaroff
    Yes, I noticed the dev branch after I created my feature branch. (Did I mention I'm new to git too?)

    I made a few half hearted attempts at git rebase with no luck. Should I pursue this or am I further ahead to recreate my branch off dev and manually apply my changes?

    Are there sample test cases? I'm curious if they're evaluated manually or automatically.
    Apr 23, 2017

    Jeff Gay
    Well... I wouldn't classify JavaScript as an object orientated language, but there's hope.

    If you could post a larger block of code (separate post?) then I'm certain others can suggest some things to try. There are many wants to the same answer.

    Apr 27, 2017
    Ivaan Nazaroff
    So I managed to delete my branch and recreate a new one off of dev.

    Next hurtle is node/npm - it would seem I need to run a process to get my code from /src/csg.js to /dist/imnotsure.js

    Can someone provide me the incantation to make this happen (Windows :$) and/or point me at some pertinent documentation to get me rolling in this environment?

    (I suspect my next set of questions will be around joostn but I think I'll save those for later.)


    May 1, 2017
    Ivaan Nazaroff
    +Laust Frederiksen I would rarely describe JavaScript as Object Oriented. There are a number of patterns that are OOish but they leave a bit to be desired (specifically that there are more than one!).

    Taking a wild guess I suspect that what you're looking for is less about OO and more about functional (declarative) v.s. procedural (imperative).

    When building up arrays sometimes a array.push() statements in for loop is what's easiest to understand.

    That said it is likely possible to shim some functions that would give you the operating space you're used to but this is where I stop making guesses without some indication I'm not out to lunch.

    May 1, 2017
    Ivaan Nazaroff
    Thank you for your quick reply.

    I think it may have been a lucky mistake to originally have cut my branch off of master. It allowed me to preserve my naivete and implement the changes I visualized in csg.js.
    Now on dev, with rollup packaging, changes to src/csg.js do not make it into the local OpenJSCad webpage.

    What is the prescribed way to make changes to csg.js and test them locally within OpenJSCad?
    I imagine it involves forking https://github.com/joostn/openjscad/tree/gh-pages and making changes there.
    Is there a good way to point dependencies for csg.js from @jscad/csg to a local file?


    May 2, 2017
    Ivaan Nazaroff
    That's what I'm after - making local enhancements to csg.js and testing.

    It seems as though the committed version of OpenJSCad.org on the dev branch uses /dest/index.js which as I've gathered is an output of the rollup configuration (I'm really out on thin branches here so please correct me if I'm wrong).

    I cloned the repos and tried the command above but I suspect it fell short of updating dependencies:

    PS xxxxx\GitHub\OpenJSCAD.org> npm i ..\csg.js
    openjscad@0.5.2 xxxxx\GitHub\OpenJSCAD.org
    `-- @jscad/csg@0.2.1 invalid

    Any further guidance would be appreciated.


    May 6, 2017
    Ivaan Nazaroff
    Yup, the limb broke - I didn't know what I was talking about.
    Still don't but I think I know more, maybe(?).

    npm run build-cli and npm run build-module both look to use rollup - this is where my confusion came from

    /dest/index.js gets constructed based on directives in
    /src/ui/index.js -> /src/jscad/processor.js

    I've reason to believe it's the line:
    import { CAG, CSG } from '@jscad/csg'
    Shot in the dark I changed it to:
    import { CAG, CSG } from '../csg.js/csg'
    I never expected it to work and it didn't.

    I feel I'm really close to getting this working.
    Or maybe I'm avoiding the hard way (learning all npm conventions and work flow) when actually it'd be easier.

    Again, any guidance would be great.


    May 6, 2017
    Ivaan Nazaroff
    Yes, I noticed my relative path math error and changed to
    import { CAG, CSG } from '../csg.js'
    With that npm run build-web no longer errored but still didn't put my edits to csg.js into index.js.

    Sadly, npm i ../csg.js didn't work for me
    (https://github.com/jscad/csg.js repo gets cloned as ../csg.js)

    When I try that command I get:
    openjscad@0.5.2 XXX\Documents\GitHub\OpenJSCAD.org
    `-- @jscad/csg@0.2.1 invalid

    And no files are updated.

    (I really do appreciate your help and attention with this. Thank you.)


    May 6, 2017
    Ivaan Nazaroff
    Some additional information.
    I found another command that might do what I'm after
    npm link ..\csg.js
    Documentation suggests this is for making a local copy of a package the one used by other local packages.
    I did not get an error with this command and the results spilled into the console did not seem unreasonable.
    Now, at least, there is evidence of my code changes in /dest/index.js (finally!) but sadly it still isn't reflected in the browser.
    It would seem /dest/index.js contains 3 versions of:
    _toWallPolygons: function(options) {
    One version of these contain my edits the other two do not and the local index.html uses one of the unchanged versions.

    Did this make any sense?


    May 7, 2017
    Ivaan Nazaroff
    Thank you for your patience. I'm ptesist when faced with complexity when I have someone to talk it through with.

    I'm using
    npm run build-web

    I will dig up my git cookbook and fetch dev from SpiritDude tomorrow.

    Thanks again. 🙂


    May 7, 2017
    Ivaan Nazaroff
    I noticed even though I had linked @jscad/csg.js to my local nested packages weren't pointing there (at least they didn't appear to in the output of npm ls).

    So I cloned and/or forked the rest of the @jscad dependencies and linked them.

    Now I'm stuck with @jscad/scad-api breaking:
    PS XXXX\GitHub\OpenJSCAD.org> npm run start-dev


    import * as primitives3d from './primitives3d'
    ParseError: 'import' and 'export' may appear only with 'sourceType: module'

    Also, I needed to hard code version numbers for dependencies in package.json files. "Latest" doesn't seem to work for me.

    Any thoughts on why scad-api isn't working for OpenJSCad start-dev?


    May 10, 2017
    Ivaan Nazaroff
    So spring happened and with it so too did life.

    Now that I have a break I thought I'd take another stab at it. Wouldn't you know it all just worked on nearly the first try!

    Either doing it all over again in a different order or some of the
    code reorganization or a combination of the two did the trick.

    So, the next question is how do I proceed from here? With some of the restructuring my change is no longer part of OpenJSCad but rather csg.js. I don't see a dev branch in that repository. Does that project accept pull requests to master? Are they as helpful and supportive as OpejJSCad?


    Jun 7, 2017
    Ivaan Nazaroff
    So some time passed while I built up the courage to submit my first ever open source GitHub pull request. When I came back to verify I wasn't imagining things and my local OpenJSCad environment was indeed functioning with my enhancements I found some refactoring had gone on in csg.js - though frustrating I'm glad to see this is an active project.

    Sadly, the refactoring was significant enough my changes will need to be reapplied rather than merged - meh, it's just code.

    It took a few false starts but I believe I have things back to square one - where I want to run my local copy on my test script and get the expected "target cag needs same sides count as start cag" (my enhancement is to support cags with different side counts in followWith).

    Instead I get a new error:
    "TypeError: CSG.ConnectorList is not a constructor"

    It would seem the ConnectorList interface has changed. Do you have some guidance on how to adjust an old script to work with ConnectorLists again?


    Jun 17, 2017
    Ivaan Nazaroff
    So though the course of ensuring the problems I was encountering were indeed something within OpenJSCad and not more local npm fun I started unpicking meticulously the steps to reproduce and attempted to identify where in the code base things were different between working and not working.

    In the end I found two things:

    • connectors.js is exporting Connector but not ConnectorList
    • CAG is calling new Connector rather than new CSG.Connector
      I've corrected both of these locally

    And with that my changes to _toWallPolygons work!

    Shall I issue a pull request for these changes or do you have a vision/opinion on the CAG <-> CSG cyclic dependency refactoring and would rather I wait until that was solidified?

Log in to reply