[OpenSCAD] Can I get some code review up in here?

Andrew Plumb andrew at plumb.org
Mon Apr 13 16:34:40 EDT 2015


As it relates to your hash() function, see search():  http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Search <http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Search>

For a flat list structure, you’d code your hash() function to filter off any odd-index return value(s) before returning the first index+1 result.

Andrew.


> On Apr 13, 2015, at 9:51 AM, runsun <runsun at gmail.com> wrote:
> 
> Or you can try a little more OOP-ish approach using a hash, in which parameters are encapsulated in a list, described in details here : http://forum.openscad.org/parameterized-models-tp8303p8306.html <http://forum.openscad.org/parameterized-models-tp8303p8306.html>
> 
> (1) 
> 
>     default = ["Height", 7, "Thickness", 5, "PinDiameter", 2 ... ];
> 
> Retrieve value: hash( default, "Height") ==> 7 // Need function hash()
> 
> (2) 
> 
> Then expand default as needed:
> 
>     boxHinge_opt = default;
>     controlArm_opt = update( default, [ "Height", 8, "ArmColor", "gray" ... ] );  // Need function update()
> ...
> 
> (3) 
> 
> In the module:
> 
>     module boxHinge( user_opt=[ ] ){
> 
>        opt = update( boxHinge_opt, user_opt ); // User can change them
>        h = hash( opt, "Height");
>        ...
>     }
> 
>     module controlArm( user_opt=[ ] ){
> 
>        opt = update( controlArm_opt, user_opt );
>        h = hash( opt, "Height");
>        ...
>     }
> 
> The hash-like structure is the main parameter model in my own code. With that I can pack parameters and throw them around all together, reuse them easily, or update them when needed. It makes complicated model codes much easier to handle, especially when dealing with objects with multiple level sub-objects ( like Human.Arms.leftArms.Fingers .... )
> $ <http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1> Runsun Pan, PhD 
> $ -- OpenScad_DocTest: doc and unit test ( Github <https://github.com/runsun/openscad_doctest>, Thingiverse <https://www.thingiverse.com/thing:410831> )
> $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15
> $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.04.01.nightly
> 
> View this message in context: Re: Can I get some code review up in here? <http://forum.openscad.org/Can-I-get-some-code-review-up-in-here-tp12341p12355.html>
> Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> at Nabble.com.
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20150413/fc8fc993/attachment-0002.html>


More information about the Discuss mailing list