├── .eslintignore
├── .eslintrc.json
├── .github
└── workflows
│ └── node_test.yml
├── .gitignore
├── .openscad-format
├── .tern-project
├── LICENSE
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── test
├── clean
│ ├── constant.scad
│ ├── function.scad
│ ├── include.scad
│ ├── integration-basic.scad
│ ├── integration.scad
│ ├── module.scad
│ ├── source.scad
│ ├── style-google-integration-basic.scad
│ ├── style-llvm-integration-basic.scad
│ ├── style-tab-integration-basic.scad
│ └── walkytalky.scad
├── comparing
│ ├── integration-basic.scad
│ └── source.scad
├── configs
│ ├── google-style
│ ├── llvm-style
│ └── tab-style
├── dirty
│ ├── constant.scad
│ ├── function.scad
│ ├── include.scad
│ ├── integration-basic.scad
│ ├── integration.scad
│ ├── module.scad
│ ├── source.scad
│ └── walkytalky.scad
└── main.js
└── yarn.lock
/.eslintignore:
--------------------------------------------------------------------------------
1 | **/node_modules/**
2 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "airbnb-base"
3 | }
--------------------------------------------------------------------------------
/.github/workflows/node_test.yml:
--------------------------------------------------------------------------------
1 | # https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
2 | name: Node.js Test
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 | jobs:
9 | build:
10 | strategy:
11 | matrix:
12 | os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
13 | node-version: [14.x, 16.x, 17.x, 18.x]
14 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
15 | runs-on: ${{ matrix.os }}
16 | name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
17 | steps:
18 | - uses: actions/checkout@v3
19 | - name: Use Node.js ${{ matrix.node-version }}
20 | uses: actions/setup-node@v3
21 | with:
22 | node-version: ${{ matrix.node-version }}
23 | cache: 'npm'
24 | - run: npm ci
25 | - run: npm run build --if-present
26 | - run: npm test
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | # vscode settings
64 | .vscode/
65 |
--------------------------------------------------------------------------------
/.openscad-format:
--------------------------------------------------------------------------------
1 | ---
2 | BasedOnStyle: Mozilla
3 | ColumnLimit: 80
4 | # SortIncludes: true
5 | IndentWidth: 4
6 | AccessModifierOffset: -4
7 | ContinuationIndentWidth: 4
8 | TabWidth: 4
9 | UseTab: Never
10 |
--------------------------------------------------------------------------------
/.tern-project:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaVersion": 6,
3 | "libs": [],
4 | "loadEagerly": [
5 | "index.js"
6 | ],
7 | "dontLoad": [],
8 | "plugins": {
9 | "requirejs": {
10 | "baseURL": "./",
11 | "paths": {}
12 | },
13 | "node": {},
14 | "doc_comment": {
15 | "fullDocs": true,
16 | "strong": true
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # openscad-format
2 | A source code formatter for the OpenSCAD language.
3 |
4 | ## Install
5 | The utility is available on [npm](https://www.npmjs.com/package/openscad-format), you can install it like so:
6 | ```
7 | $ npm install -g openscad-format
8 | ```
9 | It packages `clang-format` with it for most platforms, so you don't need to
10 | worry about installing it.
11 |
12 | ## Use
13 | `openscad-format` is designed to be simple and flexible to use:
14 | ```
15 | $ openscad-format --help
16 | Usage: openscad-format [options]
17 |
18 | Options:
19 | --version Show version number [boolean]
20 | -i, --input Input file to read, file globs allowed (quotes recommended)
21 | [string]
22 | -o, --output Output file to write [string]
23 | -c, --config Use the specified path to a config using the .openscad-format
24 | style file [string]
25 | -j, --javadoc Automatically add {Java,JS}doc-style comment templates to
26 | functions and modules where missing [boolean]
27 | -f, --force Forcibly overwrite (or "fix") the source file [boolean]
28 | -d, --dry Perform a dry run, without writing [boolean]
29 | -h, --help Show help [boolean]
30 |
31 | Examples:
32 | openscad-format -i input.scad -o Formats input.scad and saves it as
33 | output.scad output.scad
34 | openscad-format < input.scad > Formats input.scad and saves it as
35 | output.scad output.scad
36 | openscad-format < input.scad Formats input.scad and writes to
37 | stdout
38 | cat input.scad | openscad-format | less Formats input.scad and displays in
39 | less
40 | openscad-format -i './**/*.scad' Formats all *.scad files recursively
41 | and writes them to their respective
42 | files
43 |
44 | This utility requires clang-format, but this is automatically installed for most
45 | platforms.
46 | ```
47 | ## Configuration
48 | This utility by default will search for the configuration file .openscad-format in one of the parent directories. If none is found it will fall back to the default.
49 |
50 | The format used is identical to that of clang-format, the easiest way to create the .openscad-format file is using clang-format.
51 |
52 | ```
53 | clang-format -style=llvm -dump-config > .openscad-format
54 | ```
55 |
56 | See the clang-format docs for the full list of options. At the time of writing this the current styles supported are: LLVM, Google, Chromium, Mozilla, andWebKit.
57 |
58 | ## Contribute
59 | Make sure your PR's pass the unit tests and are free of ESLint errors. To check,
60 | run `npm run all` and it will guide you through what needs to be done.
61 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /* eslint-disable no-console */
3 | const fs = require('fs-extra');
4 | const getStdin = require('get-stdin');
5 | const assert = require('assert');
6 | const globby = require('globby');
7 | const clangFormat = require('clang-format');
8 | const tmp = require('tmp-promise');
9 | const path = require('path');
10 | const find = require('find-file-recursively-up');
11 |
12 | let { argv } = require('yargs')
13 | .usage('Usage: $0 [options]')
14 | .example('$0 -i input.scad -o output.scad', 'Formats input.scad and saves it as output.scad')
15 | .example('$0 < input.scad > output.scad', 'Formats input.scad and saves it as output.scad')
16 | .example('$0 < input.scad', 'Formats input.scad and writes to stdout')
17 | .example('cat input.scad | $0 | less', 'Formats input.scad and displays in less')
18 | .example('$0 -i \'./**/*.scad\'', 'Formats all *.scad files recursively and writes them to their respective files')
19 | .alias('i', 'input')
20 | .nargs('i', 1)
21 | .describe('i', 'Input file to read, file globs allowed (quotes recommended)')
22 | .string('i') // We parse this path ourselves (might have wildcards).
23 | .alias('o', 'output')
24 | .nargs('o', 1)
25 | .describe('o', 'Output file to write')
26 | .normalize('o') // Normalizes to a path.
27 | .alias('c', 'config')
28 | .nargs('c', 1)
29 | .describe('c', 'Use the specified path to a config using the .openscad-format style file')
30 | .normalize('c') // Normalizes to a path.
31 | .alias('j', 'javadoc')
32 | .boolean('j')
33 | .describe('j', 'Automatically add {Java,JS}doc-style comment templates to functions and modules where missing')
34 | .alias('f', 'force')
35 | .boolean('f')
36 | .describe('f', 'Forcibly overwrite (or "fix") the source file')
37 | .alias('d', 'dry')
38 | .boolean('d')
39 | .describe('d', 'Perform a dry run, without writing')
40 | .help('h')
41 | .alias('h', 'help')
42 | .epilog('This utility requires clang-format, but this is automatically installed for most platforms.');
43 | // .default(argsDefault)
44 |
45 | tmp.setGracefulCleanup();
46 |
47 | async function convertIncludesToClang(str) {
48 | // eslint-disable-next-line no-useless-escape
49 | const regex = /^\s*(include|use)\s*<([_\-\.\w\/]*)>;{0,1}\s*$/gm;
50 |
51 | // {type: 'include' | 'use', path: 'cornucopia/../source.scad'}
52 | const backup = [];
53 | let matches = regex.exec(str);
54 | let updated = str;
55 |
56 | while (matches !== null) {
57 | if (matches.index === regex.lastIndex) {
58 | regex.lastIndex += 1;
59 | }
60 |
61 | let entry = {};
62 | // eslint-disable-next-line no-loop-func
63 | matches.forEach((match, groupIndex) => {
64 | if (groupIndex === 0) {
65 | entry = {};
66 | entry.full = match;
67 | } else if (groupIndex === 1) {
68 | entry.type = match;
69 | } else if (groupIndex === 2) {
70 | entry.path = match;
71 | updated = updated.replace(entry.full.trim(), `#include <${entry.path}>`);
72 | backup.push(entry);
73 | }
74 | });
75 |
76 | matches = regex.exec(str);
77 | }
78 |
79 | return { result: updated, backup };
80 | }
81 |
82 | async function addDocumentation(str) {
83 | return str;
84 | }
85 |
86 | async function convertIncludesToScad(str, backup) {
87 | // eslint-disable-next-line no-useless-escape
88 | const regex = /^\s*#include\s*<([_\-\.\w\/]*)>;{0,1}\s*$/gmi;
89 | let fixed = str;
90 | let matches = regex.exec(str);
91 |
92 | while (matches !== null) {
93 | if (matches.index === regex.lastIndex) {
94 | regex.lastIndex += 1;
95 | }
96 |
97 | let entry = {};
98 | // eslint-disable-next-line no-loop-func
99 | matches.forEach((match, groupIndex) => {
100 | if (groupIndex === 0) {
101 | entry = { full: match };
102 | } else if (groupIndex === 1) {
103 | entry.path = match;
104 |
105 | // Must traverse in order.
106 | for (let i = 0; i < backup.length; i += 1) {
107 | if (backup[i].path === entry.path) {
108 | // Replace only _a single occurance_.
109 | fixed = fixed.replace(new RegExp(entry.full.trim(), ''), `${backup[i].type} <${backup[i].path}>`, '');
110 |
111 | // Splice out the one we just performed.
112 | backup.splice(i, 1);
113 | break;
114 | }
115 | }
116 | }
117 | });
118 |
119 | matches = regex.exec(str);
120 | }
121 |
122 | return fixed;
123 | }
124 |
125 | async function format(str, tmpDir) {
126 | function getClangFormattedString(file) {
127 | return new Promise((resolve, reject) => {
128 | const result = [];
129 | clangFormat(file, 'utf-8', 'file', (err) => {
130 | if (err) {
131 | reject(err);
132 | } else {
133 | resolve(result.join());
134 | }
135 | })
136 | .on('data', buffer => result.push(buffer.toString()))
137 | .on('err', err => reject(err));
138 | });
139 | }
140 |
141 | try {
142 | assert(str, 'Did not receive string to format');
143 |
144 | // eslint-disable-next-line prefer-const
145 | let { result, backup } = await convertIncludesToClang(str);
146 | assert(result, 'Failed to convert OpenSCAD includes to Clang includes');
147 |
148 | if (argv.javadoc) {
149 | result = await addDocumentation(result);
150 | assert(result, 'Javadoc failed to format source');
151 | }
152 |
153 | const { path: tmpFilePath, cleanup: cleanupTmpFile } = await tmp.file({ dir: tmpDir.path, postfix: '.scad' });
154 |
155 | const virtualFile = {
156 | path: tmpFilePath,
157 | };
158 | await fs.writeFile(virtualFile.path, result);
159 |
160 | result = await getClangFormattedString(virtualFile);
161 | assert(result, 'Clang failed to format source');
162 |
163 | result = await convertIncludesToScad(result, backup);
164 | assert(result, 'Failed to convert Clang includes to OpenSCAD includes');
165 |
166 | try {
167 | await fs.remove(virtualFile.path);
168 | } catch (err) {
169 | console.error('Failed to remove temporary input file', err);
170 | }
171 |
172 | cleanupTmpFile();
173 |
174 | return result;
175 | } catch (err) {
176 | if (err.message.indexOf('clang-format exited with exit code 1.') >= 0) {
177 | throw new Error('Syntax error in .openscad-format (Clang failed to parse it)');
178 | } else {
179 | console.error('Failure while formatting with Clang', err);
180 | throw err;
181 | }
182 | }
183 | }
184 |
185 | async function feed(input, output, tmpDir) {
186 | let str = null;
187 |
188 | if (input) {
189 | str = await fs.readFile(input);
190 | } else {
191 | str = await getStdin();
192 | }
193 |
194 | str = str.toString();
195 |
196 | if (!str) {
197 | // Do not write to output since we sometimes use stdout.
198 | // console.warn(`Contents of ${input} is empty; skipping ...`);
199 | return '';
200 | }
201 |
202 | try {
203 | const result = await format(str, tmpDir);
204 |
205 | if (result) {
206 | if (!argv.dry && output && argv.input && argv.input.length > 1) {
207 | await fs.outputFile(path.join(argv.output, path.basename(input)), result);
208 | } else if (!argv.dry && output) {
209 | await fs.writeFile(output, result);
210 | } else if (!argv.dry && argv.force && input) {
211 | // Write it back to the source location.
212 | await fs.writeFile(input, result);
213 | } else if (argv.dry && argv.isCLI) {
214 | process.stdout.write(result);
215 | }
216 | return result;
217 | }
218 |
219 | throw new Error('Failed to format content string');
220 | } catch (err) {
221 | console.error('Failed to feed to formatter and write output', err);
222 | throw err;
223 | }
224 | }
225 |
226 | async function findFormatFile() {
227 | return new Promise((resolve, reject) => {
228 | find('.openscad-format', (err, foundPath) => {
229 | if (err) {
230 | reject(err);
231 | return;
232 | }
233 |
234 | if (foundPath) {
235 | resolve(foundPath);
236 | } else {
237 | reject(new Error('unable to find .openscad-format'));
238 | }
239 | });
240 | });
241 | }
242 |
243 | async function main(params) {
244 | if (params) {
245 | argv = params;
246 | }
247 |
248 | if (argv.input) {
249 | try {
250 | argv.input = await globby(argv.input, {
251 | deep: true,
252 | gitignore: true,
253 | });
254 | } catch (err) {
255 | console.error(`Failed to glob input using ${argv.input}`, err);
256 | }
257 | }
258 |
259 | try {
260 | if (argv.output && argv.input && argv.input.length > 1) {
261 | await fs.ensureDir(argv.output);
262 | } else if (argv.output && argv.input && argv.input.length === 1) {
263 | await fs.ensureFile(argv.output);
264 | }
265 | } catch (err) {
266 | console.error('Failure while ensuring proper output pathing', err);
267 | }
268 |
269 | const resultList = [];
270 |
271 | try {
272 | const tmpDir = await tmp.dir({ unsafeCleanup: true });
273 |
274 | try {
275 | if (argv.config) {
276 | await fs.copy(argv.config, path.join(tmpDir.path, '.clang-format'));
277 | } else {
278 | let foundConfig;
279 | try {
280 | foundConfig = await findFormatFile();
281 | } catch (e) {
282 | foundConfig = undefined;
283 | }
284 |
285 | if (foundConfig) {
286 | await fs.copy(foundConfig, path.join(tmpDir.path, '.clang-format'));
287 | } else {
288 | await fs.copy(path.join(__dirname, '.openscad-format'), path.join(tmpDir.path, '.clang-format'));
289 | }
290 | }
291 |
292 | if (argv.input) {
293 | await Promise.all(argv.input.map(async (file) => {
294 | try {
295 | const result = await feed(file, argv.output, tmpDir);
296 | resultList.push({ source: file, formatted: result });
297 | } catch (err) {
298 | console.error('Failed to feed input files', err);
299 | }
300 | }));
301 | } else {
302 | // Use stdin.
303 | try {
304 | const result = await feed(null, argv.output, tmpDir);
305 | resultList.push({ source: 'stdin', formatted: result });
306 | } catch (err) {
307 | console.error('Failed to feed stdin', err);
308 | }
309 | }
310 |
311 | try {
312 | await fs.remove(path.join(tmpDir.path, '.clang-format'));
313 | } catch (err) {
314 | console.error('Failed to remove temporary clang format config file');
315 | }
316 |
317 | try {
318 | tmpDir.cleanup();
319 | } catch (err) {
320 | console.error('Failed to cleanup temporary directory');
321 | }
322 |
323 | return resultList;
324 | } catch (err) {
325 | console.error(err);
326 | throw err;
327 | }
328 | } catch (err) {
329 | console.error(err);
330 | throw err;
331 | }
332 | }
333 |
334 | if (require.main === module) {
335 | // Called via CLI.
336 | argv.isCLI = true;
337 | if (!argv.help) {
338 | main();
339 | }
340 | } else {
341 | // Called via require.
342 | argv.isCLI = false;
343 | module.exports = main;
344 | }
345 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "openscad-format",
3 | "version": "1.0.0",
4 | "description": "An opinionated formatter for the OpenSCAD language.",
5 | "main": "./index.js",
6 | "bin": {
7 | "openscad-format": "./index.js"
8 | },
9 | "scripts": {
10 | "lint": "eslint .",
11 | "fix": "eslint . --fix",
12 | "test": "mocha",
13 | "reset-clean": "./index.js -i './test/dirty/*.scad' -o ./test/clean/",
14 | "all": "eslint . --fix && mocha"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "git+https://github.com/Maxattax97/openscad-format.git"
19 | },
20 | "keywords": [
21 | "openscad",
22 | "format",
23 | "cad",
24 | "3d"
25 | ],
26 | "author": "Max O'Cull",
27 | "license": "GPL-3.0",
28 | "bugs": {
29 | "url": "https://github.com/Maxattax97/openscad-format/issues"
30 | },
31 | "homepage": "https://github.com/Maxattax97/openscad-format#readme",
32 | "dependencies": {
33 | "clang-format": "^1.2.4",
34 | "diff-match-patch": "^1.0.4",
35 | "find-file-recursively-up": "^1.1.2",
36 | "fs-extra": "^8.0.0",
37 | "get-stdin": "^6.0.0",
38 | "globby": "^9.1.0",
39 | "tmp-promise": "^1.0.5",
40 | "yargs": "^13.2.2"
41 | },
42 | "devDependencies": {
43 | "chai": "^4.2.0",
44 | "eslint": "^5.15.1",
45 | "eslint-config-airbnb-base": "^13.1.0",
46 | "eslint-plugin-import": "^2.16.0",
47 | "mocha": "^6.0.2"
48 | },
49 | "peerDependencies": {
50 | "eslint-config-airbnb-base": "^13.1.0"
51 | },
52 | "engines": {
53 | "node": ">=8.0.0"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/test/clean/constant.scad:
--------------------------------------------------------------------------------
1 | E = 2.71828182845904523536028747135266249775724709369995; // Natural number.
2 |
3 | // Ratio of a circle's circumference to it's diameter.
4 | PI = 3.14159265358979323846264338327950288419716939937510;
5 |
6 | // Golden ratio.
7 | PHI = 1.61803398874989484820458683436563811772030917980576;
8 |
9 | // A set of common square roots.
10 | SQRT_2 = 1.41421356237309504880168872420969807856967187537694;
11 | SQRT_3 = 1.73205080756887729352744634150587236694280525381038;
12 | SQRT_5 = 2.23606797749978969640917366873127623544061835961152;
13 | SQRT_7 = 2.64575131106459059050161575363926042571025918308245;
14 |
15 | IN = 25.4 * MM;
16 | FT = 304.8 * MM;
17 | YD = 914.4 * MM;
18 | MI = 1609344.0 * MM;
19 | THOU = 0.0254 * MM;
20 | MIL = THOU;
21 |
22 | INCH = IN;
23 | FOOT = FT;
24 | FEET = FT;
25 | YARD = YD;
26 | MILE = MI;
27 |
--------------------------------------------------------------------------------
/test/clean/function.scad:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * Computes the exponent of a base and a power.
5 | *
6 | * @param base The number to be multiplied power times.
7 | * @param power The number of times to multiply the base together.
8 | * @return The base risen the the power.
9 | */
10 | function MTH_power(base, power) = pow(base, power); // exp(ln(base) * power);
11 |
12 | /**
13 | * Measures the distance between two 3D vectors.
14 | *
15 | * @param vector_a The first 3D vector to compare.
16 | * @param vector_b The second 3D vector to compare.
17 | * @return The distance between vector_a and vector_b.
18 | */
19 | function MTH_distance3D(vector_a, vector_b) =
20 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
21 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
22 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
23 |
24 | /**
25 | * Measures the distance between two 2D vectors.
26 | *
27 | * @param vector_a The first 2D vector to compare.
28 | * @param vector_b The second 2D vector to compare.
29 | * @return The distance between vector_a and vector_b.
30 | */
31 | function MTH_distance2D(vector_a, vector_b) =
32 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
33 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]));
34 |
35 | function MTH_distance1D(vector_a, vector_b) = abs(vector_a - vector_b);
36 | function MTH_normalize(vector) =
37 | norm(vector); // vector / (max(MTH_distance3D(ORIGIN, vector), EPSILON));
38 | function MTH_normalVectorAngle(vector) = [
39 | 0,
40 | -1 * atan2(vector[2], MTH_distance1D([ vector[0], vector[1] ])),
41 | atan2(vector[1], vector[0])
42 | ];
43 |
--------------------------------------------------------------------------------
/test/clean/include.scad:
--------------------------------------------------------------------------------
1 | include
2 | include
3 | use
4 |
5 | include
6 |
7 | use
8 |
9 | module
10 | testUnitTest()
11 | {
12 | include
13 | include
14 | echo(TST_equal("Equality", [ 1, 2, 4, 8 ], [ 1, 2, 4, 8 ]));
15 | echo(TST_notEqual("Non-equality", [ 1, 2, 4, 8 ], [ 0, 1, 1, 2 ]));
16 | echo(TST_true("Truthiness", 1 + 1 == 2));
17 | echo(TST_false("Falseness", 1 + 1 == 3));
18 | echo(TST_in("Presence", 4, [ 1, 2, 4, 8 ]));
19 | echo(TST_notIn("Absence", 16, [ 1, 2, 4, 8 ]));
20 | echo(TST_approximately("Approximately Equal", 15 + (EPSILON / 2), 15));
21 | }
22 |
--------------------------------------------------------------------------------
/test/clean/integration-basic.scad:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Some header comment
4 | *
5 | */
6 |
7 | include
8 | include
9 |
10 | module
11 | polyhole_demo()
12 | {
13 | difference()
14 | {
15 | cube(size = [ 100, 27, 3 ]);
16 | union()
17 | {
18 | for (i = [1:10]) {
19 | translate([ (i * i + i) / 2 + 3 * i, 8, -1 ])
20 | mcad_polyhole(h = 5, d = i);
21 |
22 | assign(d = i + 0.5)
23 | translate([ (d * d + d) / 2 + 3 * d, 19, -1 ])
24 | mcad_polyhole(h = 5, d = d);
25 | }
26 | }
27 | }
28 | }
29 |
30 | /**
31 | * Measures the distance between two 3D vectors.
32 | *
33 | * @param vector_a The first 3D vector to compare.
34 | * @param vector_b The second 3D vector to compare.
35 | * @return The distance between vector_a and vector_b.
36 | */
37 | function MTH_distance3D(vector_a, vector_b) =
38 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
39 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
40 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
41 |
42 | polyhole_demo();
43 |
44 | // examples of usage
45 | // include this in your code:
46 | // use
47 | // then:
48 | // a simple rack
49 | rack(4,
50 | 20,
51 | 10,
52 | 1); // CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
53 | // a simple pinion and translation / rotation to make it mesh the rack
54 | translate([ 0, -8.5, 0 ]) rotate([ 0, 0, 360 / 10 / 2 ])
55 | pinion(MTH_distance3D([ 1, 2, 3 ], [ 4, 5, 6 ]), 10, 10, 5);
56 |
--------------------------------------------------------------------------------
/test/clean/integration.scad:
--------------------------------------------------------------------------------
1 |
2 | echo(TST_true("Iterable", UTL_iterable([ 1, 2, 3 ])));
3 | echo(TST_false("Not iterable", UTL_iterable(1)));
4 |
5 | echo(TST_true("Empty", UTL_empty([])));
6 | echo(TST_false("Not empty", UTL_empty([ 1, 2, 3 ])));
7 |
8 | echo(TST_equal("Head", UTL_head([ 1, 2, 3 ]), 1));
9 |
10 | echo(TST_equal("Tail some", UTL_tail([ 1, 2, 3 ]), [ 2, 3 ]));
11 | echo(TST_equal("Tail one", UTL_tail([1]), []));
12 | echo(TST_equal("Tail zero", UTL_tail([]), undef));
13 |
14 | echo(TST_equal("Last some", UTL_last([ 1, 2, 3 ]), 3));
15 | echo(TST_equal("Last one", UTL_last([1]), 1));
16 | echo(TST_equal("Last zero", UTL_last([]), undef));
17 |
18 | echo(TST_equal("Reverse some", UTL_reverse([ 1, 2, 3 ]), [ 3, 2, 1 ]));
19 | echo(TST_equal("Reverse zero", UTL_reverse([]), []));
20 |
21 | echo(TST_true("Equal number", UTL_equal(0, 0), true));
22 | echo(TST_false("Not equal number", UTL_equal(0, 5)));
23 | echo(TST_true("Equal empty list", UTL_equal([], [])));
24 | echo(TST_true("Equal list", UTL_equal([ 1, 2, 4 ], [ 1, 2, 4 ])));
25 | echo(TST_false("Not equal list", UTL_equal([ 1, 2, 3 ], [ 1, 2, 4 ])));
26 | echo(TST_true("Equal nested list",
27 | UTL_equal([ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
28 | [ [ 1, 2, 3 ], [ 4, 5, 6 ] ])));
29 | echo(TST_false("Not equal nested list",
30 | UTL_equal([ [ 1, 2, 3 ], [ 4, 5, 6 ] ],
31 | [ [ 1, 2, 4 ], [ 4, 5, 6 ] ])));
32 | echo(TST_false("Equal unbalanced list",
33 | UTL_equal([ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 7, [ 4, 5, 6 ] ])));
34 |
35 | echo(TST_true("All", UTL_all([ true, true, true ])));
36 | echo(TST_false("Not all", UTL_all([ true, true, false ])));
37 |
38 | echo(TST_true("Any", UTL_any([ false, false, true ])));
39 | echo(TST_false("Not any", UTL_any([ false, false, false ])));
40 |
41 | echo(TST_true("Contains", UTL_contains([ 1, 2, 3 ], 2)));
42 | echo(TST_false("Doesn't contain", UTL_contains([ 1, 2, 3 ], 6)));
43 |
44 | echo(TST_equal("Zip zero", UTL_zip([]), []));
45 | echo(TST_equal("Zip zero 2", UTL_zip([ [], [], [] ]), []));
46 | echo(TST_equal("Zip zero 3", UTL_zip([ [], [1], [2] ]), []));
47 | echo(TST_equal("Zip equal length",
48 | UTL_zip([ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]),
49 | [ [ 1, 4, 7 ], [ 2, 5, 8 ], [ 3, 6, 9 ] ]));
50 | echo(TST_equal("Zip different length",
51 | UTL_zip([ [ 1, 2, 3 ], [ 4, 5 ], [ 7, 8, 9 ] ]),
52 | [ [ 1, 4, 7 ], [ 2, 5, 8 ] ]));
53 |
54 | echo(TST_equal("Sort zero", UTL_sort([]), []));
55 | echo(TST_equal("Sort some", UTL_sort([ 4, 2, 8, 16, 1 ]), [ 1, 2, 4, 8, 16 ]));
56 |
57 | echo(TST_equal("One Pole Filter Zero", UTL_onePoleFilter([], 0), []));
58 | echo(TST_equal("One Pole Filter Some",
59 | UTL_onePoleFilter([ 1, 2, 3 ], 0),
60 | [ 1, 2, 3 ]));
61 | echo(TST_equal("One Pole Filter Positive",
62 | UTL_onePoleFilter([ 4, 2, 5 ], 0.5),
63 | [ 4, 3, 4 ]));
64 | echo(TST_equal("One Pole Filter Negative",
65 | UTL_onePoleFilter([ 4, 2, 5 ], -0.5),
66 | [ 4, 1, 7 ]));
67 |
68 | rod(20);
69 | translate([ rodsize * 2.5, 0, 0 ]) rod(20, true);
70 | translate([ rodsize * 5, 0, 0 ]) screw(10, true);
71 | translate([ rodsize * 7.5, 0, 0 ]) bearing();
72 | translate([ rodsize * 10, 0, 0 ]) rodnut();
73 | translate([ rodsize * 12.5, 0, 0 ]) rodwasher();
74 | translate([ rodsize * 15, 0, 0 ]) nut();
75 | translate([ rodsize * 17.5, 0, 0 ]) washer();
76 |
77 | // examples
78 | linearBearing(model = "LM8UU");
79 | translate([ 20, 0, 0 ]) linearBearing(model = "LM10UU");
80 |
81 | module metric_ruler(millimeters)
82 | {
83 | difference()
84 | {
85 | // Body of ruler
86 | color("Beige")
87 | cube(size = [ length_mm(millimeters), length_cm(3), length_mm(1) ]);
88 | // Centimeter markings
89 | for (i = [0:length_cm(1):length_mm(millimeters) + epsilon]) {
90 | translate([ i, length_cm(2.5), length_mm(0.75) ]) color("Red")
91 | cube(size =
92 | [
93 | length_mm(0.5),
94 | length_cm(1) + epsilon,
95 | length_mm(0.5) +
96 | epsilon
97 | ],
98 | center = true);
99 | }
100 | // Half centimeter markings
101 | for (i = [length_cm(0.5):length_cm(1):length_mm(millimeters) +
102 | epsilon]) {
103 | tran,slate([ i, length_cm(2.7), length_mm(0.875) ]) color("Red")
104 | cube(size =
105 | [
106 | length_mm(0.5),
107 | length_cm(0.6) + epsilon,
108 | length_mm(0.25) +
109 | epsilon
110 | ],
111 | center = true);
112 | }
113 | // Millimeter markings
114 | for (i = [length_mm(1):length_mm(1):length_mm(millimeters) + epsilon]) {
115 | translate([ i, length_cm(2.85), length_mm(0.9375) ]) color("Red")
116 | cube(size =
117 | [
118 | length_mm(0.5),
119 | length_cm(0.3) + epsilon,
120 | length_mm(0.125) +
121 | epsilon
122 | ],
123 | center = true);
124 | }
125 | }
126 | }
127 |
128 | metric_ruler(100);
129 |
130 | include
131 |
132 | module
133 | polyhole_demo()
134 | {
135 | difference()
136 | {
137 | cube(size = [ 100, 27, 3 ]);
138 | union()
139 | {
140 | for (i = [1:10]) {
141 | translate([ (i * i + i) / 2 + 3 * i, 8, -1 ])
142 | mcad_polyhole(h = 5, d = i);
143 |
144 | assign(d = i + 0.5)
145 | translate([ (d * d + d) / 2 + 3 * d, 19, -1 ])
146 | mcad_polyhole(h = 5, d = d);
147 | }
148 | }
149 | }
150 | }
151 |
152 | polyhole_demo();
153 |
154 | include
155 |
156 | // examples of usage
157 | // include this in your code:
158 | // use
159 | // then:
160 | // a simple rack
161 | rack(4,
162 | 20,
163 | 10,
164 | 1); // CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
165 | // a simple pinion and translation / rotation to make it mesh the rack
166 | translate([ 0, -8.5, 0 ]) rotate([ 0, 0, 360 / 10 / 2 ]) pinion(4, 10, 10, 5);
167 |
--------------------------------------------------------------------------------
/test/clean/module.scad:
--------------------------------------------------------------------------------
1 | module gear(number_of_teeth,
2 | circular_pitch = false,
3 | diametral_pitch = false,
4 | pressure_angle = 20,
5 | clearance = 0,
6 | verbose = false)
7 | {
8 | if (verbose) {
9 | echo("gear arguments:");
10 | echo(str(" number_of_teeth: ", number_of_teeth));
11 | echo(str(" circular_pitch: ", circular_pitch));
12 | echo(str(" diametral_pitch: ", diametral_pitch));
13 | echo(str(" pressure_angle: ", pressure_angle));
14 | echo(str(" clearance: ", clearance));
15 | }
16 | if (circular_pitch == false && diametral_pitch == false)
17 | echo("MCAD ERROR: gear module needs either a diametral_pitch or "
18 | "circular_pitch");
19 | if (verbose)
20 | echo("gear calculations:");
21 |
22 | // Convert diametrial pitch to our native circular pitch
23 | circular_pitch =
24 | (circular_pitch != false ? circular_pitch : 180 / diametral_pitch);
25 |
26 | // Pitch diameter: Diameter of pitch circle.
27 | pitch_diameter = pitch_circular2diameter(number_of_teeth, circular_pitch);
28 | if (verbose)
29 | echo(str(" pitch_diameter: ", pitch_diameter));
30 | pitch_radius = pitch_diameter / 2;
31 |
32 | // Base Circle
33 | base_diameter = pitch_diameter * cos(pressure_angle);
34 | if (verbose)
35 | echo(str(" base_diameter: ", base_diameter));
36 | base_radius = base_diameter / 2;
37 |
38 | // Diametrial pitch: Number of teeth per unit length.
39 | pitch_diametrial = number_of_teeth / pitch_diameter;
40 | if (verbose)
41 | echo(str(" pitch_diametrial: ", pitch_diametrial));
42 |
43 | // Addendum: Radial distance from pitch circle to outside circle.
44 | addendum = 1 / pitch_diametrial;
45 | if (verbose)
46 | echo(str(" addendum: ", addendum));
47 |
48 | // Outer Circle
49 | outer_radius = pitch_radius + addendum;
50 | outer_diameter = outer_radius * 2;
51 | if (verbose)
52 | echo(str(" outer_diameter: ", outer_diameter));
53 |
54 | // Dedendum: Radial distance from pitch circle to root diameter
55 | dedendum = addendum + clearance;
56 | if (verbose)
57 | echo(str(" dedendum: ", dedendum));
58 |
59 | // Root diameter: Diameter of bottom of tooth spaces.
60 | root_radius = pitch_radius - dedendum;
61 | root_diameter = root_radius * 2;
62 | if (verbose)
63 | echo(str(" root_diameter: ", root_diameter));
64 |
65 | half_thick_angle = 360 / (4 * number_of_teeth);
66 | if (verbose)
67 | echo(str(" half_thick_angle: ", half_thick_angle));
68 |
69 | union()
70 | {
71 | rotate(half_thick_angle)
72 | circle($fn = number_of_teeth * 2, r = root_radius * 1.001);
73 |
74 | for (i = [1:number_of_teeth])
75 | // for (i = [0])
76 | {
77 | rotate([ 0, 0, i * 360 / number_of_teeth ])
78 | {
79 | involute_gear_tooth(pitch_radius = pitch_radius,
80 | root_radius = root_radius,
81 | base_radius = base_radius,
82 | outer_radius = outer_radius,
83 | half_thick_angle = half_thick_angle);
84 | }
85 | }
86 | }
87 | }
88 |
89 | module involute_gear_tooth(pitch_radius,
90 | root_radius,
91 | base_radius,
92 | outer_radius,
93 | half_thick_angle)
94 | {
95 | pitch_to_base_angle = involute_intersect_angle(base_radius, pitch_radius);
96 |
97 | outer_to_base_angle = involute_intersect_angle(base_radius, outer_radius);
98 |
99 | base1 = 0 - pitch_to_base_angle - half_thick_angle;
100 | pitch1 = 0 - half_thick_angle;
101 | outer1 = outer_to_base_angle - pitch_to_base_angle - half_thick_angle;
102 |
103 | b1 = polar_to_cartesian([ base1, base_radius ]);
104 | p1 = polar_to_cartesian([ pitch1, pitch_radius ]);
105 | o1 = polar_to_cartesian([ outer1, outer_radius ]);
106 |
107 | b2 = polar_to_cartesian([ -base1, base_radius ]);
108 | p2 = polar_to_cartesian([ -pitch1, pitch_radius ]);
109 | o2 = polar_to_cartesian([ -outer1, outer_radius ]);
110 |
111 | // ( root_radius > base_radius variables )
112 | pitch_to_root_angle = pitch_to_base_angle -
113 | involute_intersect_angle(base_radius, root_radius);
114 | root1 = pitch1 - pitch_to_root_angle;
115 | root2 = -pitch1 + pitch_to_root_angle;
116 | r1_t = polar_to_cartesian([ root1, root_radius ]);
117 | r2_t = polar_to_cartesian([ -root1, root_radius ]);
118 |
119 | // ( else )
120 | r1_f = polar_to_cartesian([ base1, root_radius ]);
121 | r2_f = polar_to_cartesian([ -base1, root_radius ]);
122 |
123 | if (root_radius > base_radius) {
124 | // echo("true");
125 | polygon(points = [ r1_t, p1, o1, o2, p2, r2_t ], convexity = 3);
126 | } else {
127 | polygon(points = [ r1_f, b1, p1, o1, o2, p2, b2, r2_f ], convexity = 3);
128 | }
129 | }
130 |
131 | module
132 | test_gears()
133 | {
134 | gear(number_of_teeth = 51, circular_pitch = 200);
135 | translate([ 0, 50 ]) gear(number_of_teeth = 17, circular_pitch = 200);
136 | translate([ -50, 0 ]) gear(number_of_teeth = 17, diametral_pitch = 1);
137 | }
138 |
139 | module
140 | demo_3d_gears()
141 | {
142 | // double helical gear
143 | // (helics don't line up perfectly - for display purposes only ;)
144 | translate([ 50, 0 ])
145 | {
146 | linear_extrude(height = 10, center = true, convexity = 10, twist = -45)
147 | gear(number_of_teeth = 17, diametral_pitch = 1);
148 | translate([ 0, 0, 10 ]) linear_extrude(
149 | height = 10, center = true, convexity = 10, twist = 45)
150 | gear(number_of_teeth = 17, diametral_pitch = 1);
151 | }
152 |
153 | // spur gear
154 | translate([ 0, -50 ])
155 | linear_extrude(height = 10, center = true, convexity = 10, twist = 0)
156 | gear(number_of_teeth = 17, diametral_pitch = 1);
157 | }
158 |
159 | module
160 | test_involute_curve()
161 | {
162 | for (i = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]) {
163 | translate(polar_to_cartesian([ involute_intersect_angle(0.1, i), i ]))
164 | circle($fn = 15, r = 0.5);
165 | }
166 | }
167 |
168 | module
169 | mcad_test_nuts_and_bolts_1()
170 | {
171 | $fn = 360;
172 |
173 | translate([ 0, 15 ]) mcad_nut_hole(3, proj = -1);
174 |
175 | mcad_bolt_hole(3, length = 30, tolerance = 10, proj = -1);
176 | }
177 | // mcad_test_nuts_and_bolts_1 ();
178 |
179 | module
180 | mcad_test_nuts_and_bolts_2()
181 | {
182 | $fn = 360;
183 |
184 | difference()
185 | {
186 | cube(size = [ 10, 20, 10 ], center = true);
187 | union()
188 | {
189 | translate([ 0, 15 ]) mcad_nut_hole(3, proj = 2);
190 |
191 | linear_extrude(
192 | height = 20, center = true, convexity = 10, twist = 0)
193 | mcad_bolt_hole(3, length = 30, proj = 2);
194 | }
195 | }
196 | }
197 | // mcad_test_nuts_and_bolts_2 ();
198 |
199 | module
200 | mcad_test_nuts_and_bolts_3()
201 | {
202 | $fn = 360;
203 |
204 | mcad_bolt_hole_with_nut(size = 3, length = 10);
205 | }
206 |
--------------------------------------------------------------------------------
/test/clean/source.scad:
--------------------------------------------------------------------------------
1 | include
2 | include
3 | use
4 |
5 | include
6 |
7 | use
8 |
9 | // This file is placed under the public domain
10 |
11 | // from: http://www.thingiverse.com/thing:9512
12 | // Author: nefercheprure
13 |
14 | // Examples:
15 | // standard LEGO 2x1 tile has no pin
16 | // block(1,2,1/3,reinforcement=false,flat_top=true);
17 | // standard LEGO 2x1 flat has pin
18 | // block(1,2,1/3,reinforcement=true);
19 | // standard LEGO 2x1 brick has pin
20 | // block(1,2,1,reinforcement=true);
21 | // standard LEGO 2x1 brick without pin
22 | // block(1,2,1,reinforcement=false);
23 | // standard LEGO 2x1x5 brick has no pin and has hollow knobs
24 | // block(1,2,5,reinforcement=false,hollow_knob=true);
25 |
26 | knob_diameter = 4.8; // knobs on top of blocks
27 | knob_height = 2;
28 | knob_spacing = 8.0;
29 | wall_thickness = 1.45;
30 | roof_thickness = 1.05;
31 | block_height = 9.5;
32 | pin_diameter = 3; // pin for bottom blocks with width or length of 1
33 | post_diameter = 6.5;
34 | reinforcing_width = 1.5;
35 | axle_spline_width = 2.0;
36 | axle_diameter = 5;
37 | cylinder_precision = 0.5;
38 |
39 | /* EXAMPLES:
40 | block(2,1,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true);
41 | translate([50,-10,0])
42 | block(1,2,1/3,axle_hole=false,circular_hole=true,reinforcement=false,hollow_knob=true,flat_top=true);
43 | translate([10,0,0])
44 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true);
45 | translate([30,0,0])
46 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=false,flat_top=false);
47 | translate([50,0,0])
48 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false);
49 | translate([0,20,0])
50 | block(3,2,2/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false);
51 | translate([20,20,0])
52 | block(3,2,1,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false);
53 | translate([40,20,0])
54 | block(3,2,1/3,axle_hole=false,circular_hole=false,reinforcement=false,hollow_knob=false,flat_top=false);
55 | translate([0,-10,0])
56 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false);
57 | translate([0,-20,0])
58 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=false);
59 | translate([0,-30,0])
60 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=true);
61 | //*/
62 |
63 | module block(width,
64 | length,
65 | height,
66 | axle_hole = false,
67 | reinforcement = false,
68 | hollow_knob = false,
69 | flat_top = false,
70 | circular_hole = false,
71 | solid_bottom = true,
72 | center = false)
73 | {
74 | overall_length =
75 | (length - 1) * knob_spacing + knob_diameter + wall_thickness * 2;
76 | overall_width =
77 | (width - 1) * knob_spacing + knob_diameter + wall_thickness * 2;
78 | center = center == true ? 1 : 0;
79 | translate(center * [ -overall_length / 2, -overall_width / 2, 0 ]) union()
80 | {
81 | difference()
82 | {
83 | union()
84 | {
85 | // body:
86 | cube([ overall_length, overall_width, height * block_height ]);
87 | // knobs:
88 | if (flat_top != true)
89 | translate([
90 | knob_diameter / 2 + wall_thickness,
91 | knob_diameter / 2 + wall_thickness,
92 | 0
93 | ]) for (ycount = [0:width - 1]) for (xcount =
94 | [0:length - 1])
95 | {
96 | translate(
97 | [ xcount * knob_spacing, ycount * knob_spacing, 0 ])
98 | difference()
99 | {
100 | cylinder(r = knob_diameter / 2,
101 | h = block_height * height + knob_height,
102 | $fs = cylinder_precision);
103 | if (hollow_knob == true)
104 | translate([ 0, 0, -roof_thickness ]) cylinder(
105 | r = pin_diameter / 2,
106 | h = block_height * height + knob_height +
107 | 2 * roof_thickness,
108 | $fs = cylinder_precision);
109 | }
110 | }
111 | }
112 | // hollow bottom:
113 | if (solid_bottom == false)
114 | translate([ wall_thickness, wall_thickness, -roof_thickness ])
115 | cube([
116 | overall_length - wall_thickness * 2,
117 | overall_width - wall_thickness * 2,
118 | block_height *
119 | height
120 | ]);
121 | // flat_top -> groove around bottom
122 | if (flat_top == true) {
123 | translate([
124 | -wall_thickness / 2,
125 | -wall_thickness * 2 / 3,
126 | -wall_thickness / 2
127 | ])
128 | cube([
129 | overall_length + wall_thickness,
130 | wall_thickness,
131 | wall_thickness
132 | ]);
133 | translate([
134 | -wall_thickness / 2,
135 | overall_width - wall_thickness / 3,
136 | -wall_thickness / 2
137 | ])
138 | cube([
139 | overall_length + wall_thickness,
140 | wall_thickness,
141 | wall_thickness
142 | ]);
143 |
144 | translate([
145 | -wall_thickness * 2 / 3,
146 | -wall_thickness / 2,
147 | -wall_thickness / 2
148 | ])
149 | cube([
150 | wall_thickness,
151 | overall_width + wall_thickness,
152 | wall_thickness
153 | ]);
154 | translate([
155 | overall_length - wall_thickness / 3,
156 | 0,
157 | -wall_thickness / 2
158 | ])
159 | cube([
160 | wall_thickness,
161 | overall_width + wall_thickness,
162 | wall_thickness
163 | ]);
164 | }
165 | if (axle_hole == true)
166 | if (width > 1 && length > 1)
167 | for (ycount = [1:width - 1])
168 | for (xcount = [1:length - 1])
169 | translate([
170 | xcount * knob_spacing,
171 | ycount * knob_spacing,
172 | roof_thickness
173 | ]) axle(height);
174 | if (circular_hole == true)
175 | if (width > 1 && length > 1)
176 | for (ycount = [1:width - 1])
177 | for (xcount = [1:length - 1])
178 | translate([
179 | xcount * knob_spacing,
180 | ycount * knob_spacing,
181 | roof_thickness
182 | ]) cylinder(r = knob_diameter / 2,
183 | h = height * block_height +
184 | roof_thickness / 4,
185 | $fs = cylinder_precision);
186 | }
187 |
188 | if (reinforcement == true && width > 1 && length > 1)
189 | difference()
190 | {
191 | for (ycount = [1:width - 1])
192 | for (xcount = [1:length - 1])
193 | translate(
194 | [ xcount * knob_spacing, ycount * knob_spacing, 0 ])
195 | reinforcement(height);
196 | for (ycount = [1:width - 1])
197 | for (xcount = [1:length - 1])
198 | translate([
199 | xcount * knob_spacing,
200 | ycount * knob_spacing,
201 | -,roof_thickness / 2
202 | ]) cylinder(r = knob_diameter / 2,
203 | h = height * block_height + roof_thickness,
204 | $fs = cylinder_precision);
205 | }
206 | // posts:
207 | if (solid_bottom == false)
208 | if (width > 1 && length > 1)
209 | for (ycount = [1:width - 1])
210 | for (xcount = [1:length - 1])
211 | translate(
212 | [ xcount * knob_spacing, ycount * knob_spacing, 0 ])
213 | post(height);
214 |
215 | if (reinforcement == true && width == 1 && length != 1)
216 | for (xcount = [1:length - 1])
217 | translate([ xcount * knob_spacing, overall_width / 2, 0 ])
218 | cylinder(r = pin_diameter / 2,
219 | h = block_height * height,
220 | $fs = cylinder_precision);
221 |
222 | if (reinforcement == true && length == 1 && width != 1)
223 | for (ycount = [1:width - 1])
224 | translate([ overall_length / 2, ycount * knob_spacing, 0 ])
225 | cylinder(r = pin_diameter / 2,
226 | h = block_height * height,
227 | $fs = cylinder_precision);
228 | }
229 | }
230 |
231 | module post(height)
232 | {
233 | difference()
234 | {
235 | cylinder(r = post_diameter / 2,
236 | h = height * block_height - roof_thickness / 2,
237 | $fs = cylinder_precision);
238 | translate([ 0, 0, -roof_thickness / 2 ])
239 | cylinder(r = knob_diameter / 2,
240 | h = height * block_height + roof_thickness / 4,
241 | $fs = cylinder_precision);
242 | }
243 | }
244 |
245 | module reinforcement(height)
246 | {
247 | union()
248 | {
249 | translate([ 0, 0, height * block_height / 2 ]) union()
250 | {
251 | cube(
252 | [
253 | reinforcing_width,
254 | knob_spacing + knob_diameter + wall_thickness / 2,
255 | height *
256 | block_height
257 | ],
258 | center = true);
259 | rotate(v = [ 0, 0, 1 ], a = 90) cube(
260 | [
261 | reinforcing_width,
262 | knob_spacing + knob_diameter + wall_thickness / 2,
263 | height *
264 | block_height
265 | ],
266 | center = true);
267 | }
268 | }
269 | }
270 |
271 | module axle(height)
272 | {
273 | translate([ 0, 0, height * block_height / 2 ]) union()
274 | {
275 | cube([ axle_diameter, axle_spline_width, height * block_height ],
276 | center = true);
277 | cube([ axle_spline_width, axle_diameter, height * block_height ],
278 | center = true);
279 | }
280 | }
281 |
282 | /**
283 | * Calculate the number of facets to generate for radius `r`. This is intended
284 | * to mimic OpenSCAD's internal get_fragments_from_r() function.
285 | *
286 | * @param r Radius of circle
287 | */
288 | function get_fragments_from_r(r) =
289 | (($fn > 0) ? $fn
290 | : (r < 0.00000095367431640625)
291 | ? 3
292 | : ceil(max(min(360 / $fa, r * 2 * PI / $fs), 5)));
293 |
294 | /**
295 | * This is a function that generates a series of values ala $t for use as facet
296 | * IDs.
297 | *
298 | * @param r Radius of circle
299 | */
300 | function gen_facet_series(r) = [0:1.0 / get_fragments_from_r(r):1.0001];
301 |
302 | // example
303 | translate([ 0, 0, 10 ]) linear_extrude(1) circle(10, $fn = 10);
304 |
305 | linear_extrude(1) polygon([let(r = 10) for (t = gen_facet_series(r, $fn = 10))
306 | let(angle = t * 360)[cos(angle) * r, sin(angle) * r]]);
307 |
308 | post(5);
309 | reinforcement(10);
310 |
311 | MTH_triangleAreaFromLengths(3, 3, 9);
312 |
313 | /* function gen_facet_series_asdf (r) = [0 : 1.0 / ;get_fragments_from_r (r)
314 | * : 1.0001]; */
315 |
316 | MTH_triangleAreaFromLengths(3, 3, 9);
317 |
--------------------------------------------------------------------------------
/test/clean/style-google-integration-basic.scad:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Some header comment
4 | *
5 | */
6 |
7 | include
8 | include
9 |
10 | module polyhole_demo() {
11 | difference() {
12 | cube(size = [ 100, 27, 3 ]);
13 | union() {
14 | for (i = [1:10]) {
15 | translate([ (i * i + i) / 2 + 3 * i, 8, -1 ])
16 | mcad_polyhole(h = 5, d = i);
17 |
18 | assign(d = i + 0.5) translate([ (d * d + d) / 2 + 3 * d, 19, -1 ])
19 | mcad_polyhole(h = 5, d = d);
20 | }
21 | }
22 | }
23 | }
24 |
25 | /**
26 | * Measures the distance between two 3D vectors.
27 | *
28 | * @param vector_a The first 3D vector to compare.
29 | * @param vector_b The second 3D vector to compare.
30 | * @return The distance between vector_a and vector_b.
31 | */
32 | function MTH_distance3D(vector_a, vector_b) =
33 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
34 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
35 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
36 |
37 | polyhole_demo();
38 |
39 | // examples of usage
40 | // include this in your code:
41 | // use
42 | // then:
43 | // a simple rack
44 | rack(4, 20, 10,
45 | 1); // CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
46 | // a simple pinion and translation / rotation to make it mesh the rack
47 | translate([ 0, -8.5, 0 ]) rotate([ 0, 0, 360 / 10 / 2 ])
48 | pinion(MTH_distance3D([ 1, 2, 3 ], [ 4, 5, 6 ]), 10, 10, 5);
49 |
--------------------------------------------------------------------------------
/test/clean/style-llvm-integration-basic.scad:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Some header comment
4 | *
5 | */
6 |
7 | include
8 | include
9 |
10 | module polyhole_demo() {
11 | difference() {
12 | cube(size = [ 100, 27, 3 ]);
13 | union() {
14 | for (i = [1:10]) {
15 | translate([ (i * i + i) / 2 + 3 * i, 8, -1 ])
16 | mcad_polyhole(h = 5, d = i);
17 |
18 | assign(d = i + 0.5) translate([ (d * d + d) / 2 + 3 * d, 19, -1 ])
19 | mcad_polyhole(h = 5, d = d);
20 | }
21 | }
22 | }
23 | }
24 |
25 | /**
26 | * Measures the distance between two 3D vectors.
27 | *
28 | * @param vector_a The first 3D vector to compare.
29 | * @param vector_b The second 3D vector to compare.
30 | * @return The distance between vector_a and vector_b.
31 | */
32 | function MTH_distance3D(vector_a, vector_b) =
33 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
34 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
35 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
36 |
37 | polyhole_demo();
38 |
39 | // examples of usage
40 | // include this in your code:
41 | // use
42 | // then:
43 | // a simple rack
44 | rack(4, 20, 10,
45 | 1); // CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
46 | // a simple pinion and translation / rotation to make it mesh the rack
47 | translate([ 0, -8.5, 0 ]) rotate([ 0, 0, 360 / 10 / 2 ])
48 | pinion(MTH_distance3D([ 1, 2, 3 ], [ 4, 5, 6 ]), 10, 10, 5);
49 |
--------------------------------------------------------------------------------
/test/clean/style-tab-integration-basic.scad:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Some header comment
4 | *
5 | */
6 |
7 | include
8 | include
9 |
10 | module polyhole_demo() {
11 | difference() {
12 | cube(size = [ 100, 27, 3 ]);
13 | union() {
14 | for (i = [1:10]) {
15 | translate([ (i * i + i) / 2 + 3 * i, 8, -1 ])
16 | mcad_polyhole(h = 5, d = i);
17 |
18 | assign(d = i + 0.5)
19 | translate([ (d * d + d) / 2 + 3 * d, 19, -1 ])
20 | mcad_polyhole(h = 5, d = d);
21 | }
22 | }
23 | }
24 | }
25 |
26 | /**
27 | * Measures the distance between two 3D vectors.
28 | *
29 | * @param vector_a The first 3D vector to compare.
30 | * @param vector_b The second 3D vector to compare.
31 | * @return The distance between vector_a and vector_b.
32 | */
33 | function MTH_distance3D(vector_a, vector_b) =
34 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
35 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
36 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
37 |
38 | polyhole_demo();
39 |
40 | // examples of usage
41 | // include this in your code:
42 | // use
43 | // then:
44 | // a simple rack
45 | rack(4, 20, 10,
46 | 1); // CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
47 | // a simple pinion and translation / rotation to make it mesh the rack
48 | translate([ 0, -8.5, 0 ]) rotate([ 0, 0, 360 / 10 / 2 ])
49 | pinion(MTH_distance3D([ 1, 2, 3 ], [ 4, 5, 6 ]), 10, 10, 5);
50 |
--------------------------------------------------------------------------------
/test/clean/walkytalky.scad:
--------------------------------------------------------------------------------
1 | DXF = true; // set to true to see the DXF projection, for a laser cutter for
2 | // example
3 |
4 | file = "makercase-50-30-105-inside-3-5mm-thickness.dxf";
5 | thickness = 3.5;
6 |
7 | inner_width = 50;
8 | inner_height = 30;
9 | inner_depth = 105;
10 |
11 | outer_width = inner_width + 2 * thickness;
12 | outer_height = inner_height + 2 * thickness;
13 | outer_depth = inner_depth + 2 * thickness;
14 |
15 | spacing = 6;
16 |
17 | module dxf(layer)
18 | {
19 | import(file = "makercase-50-30-105-inside-3-5mm-thickness.dxf",
20 | layer = layer);
21 | }
22 |
23 | module
24 | back()
25 | {
26 | linear_extrude(height = thickness, center = true) difference()
27 | {
28 | dxf("back_outsideCutPath", 0); // , - outer_height - spacing
29 | plug_radius = 3.5;
30 | translate([
31 | outer_width / 2,
32 | outer_height + spacing / 2 * 2 + outer_height / 2
33 | ]) circle(plug_radius, $fn = 20);
34 | }
35 | }
36 |
37 | module
38 | top()
39 | {
40 | radius = 16;
41 | circle_y_offset = 24;
42 | offset_x = outer_depth + outer_width + 1 * spacing;
43 | offset_y = 3;
44 | linear_extrude(height = thickness, center = true)
45 |
46 | difference()
47 | {
48 | dxf("top_outsideCutPath", 0);
49 |
50 | // Speaker
51 | translate([ offset_x + (outer_width / 2), offset_y + circle_y_offset ])
52 | circle(r = radius, $fn = 50);
53 |
54 | // Holes
55 | distance = 29 / 2;
56 | translate([
57 | offset_x + (outer_width / 2) - distance,
58 | offset_y + circle_y_offset -
59 | distance
60 | ]) circle(r = 1, $fn = 20);
61 | translate([
62 | offset_x + (outer_width / 2) + distance,
63 | offset_y + circle_y_offset -
64 | distance
65 | ]) circle(r = 1, $fn = 20);
66 | translate([
67 | offset_x + (outer_width / 2) - distance,
68 | offset_y + circle_y_offset +
69 | distance
70 | ]) circle(r = 1, $fn = 20);
71 | translate([
72 | offset_x + (outer_width / 2) + distance,
73 | offset_y + circle_y_offset +
74 | distance
75 | ]) circle(r = 1, $fn = 20);
76 |
77 | // LED
78 | led_radius = 2.3;
79 | led_offset = 7;
80 | translate([
81 | offset_x + (outer_width / 2),
82 | offset_y + circle_y_offset + radius +
83 | led_offset
84 | ]) circle(r = led_radius, $fn = 20);
85 |
86 | // Mic
87 | mic_offset = led_offset + led_radius + 7;
88 | translate([
89 | offset_x + (outer_width / 2),
90 | offset_y + circle_y_offset + radius +
91 | mic_offset
92 | ]) circle(r = .5, $fn = 20);
93 | }
94 | }
95 |
96 | module
97 | front()
98 | {
99 |
100 | socket_width = 7.5;
101 | chip_height = 12;
102 |
103 | linear_extrude(height = thickness, center = true) difference()
104 | {
105 | dxf("front_outsideCutPath", 0);
106 |
107 | // Microusb
108 | chip_width = 17;
109 | chip_offset = 12.5;
110 | translate([
111 | outer_width - chip_width / 2 - chip_offset,
112 | spacing / 2 +
113 | chip_height
114 | ]) square([ chip_width, 1 ], center = true);
115 | translate([
116 | outer_width - chip_width / 2 - chip_offset,
117 | spacing / 2 + chip_height + 1.5
118 | ]) square([ socket_width, 3 ], center = true);
119 |
120 | // Switch
121 | switch_height = 25;
122 | switch_radius = 3;
123 | translate([
124 | outer_width - chip_width / 2 - chip_offset,
125 | spacing / 2 +
126 | switch_height
127 | ]) circle(switch_radius, $fn = 50);
128 |
129 | // Charging indicator
130 | charging_radius = .8;
131 | translate([
132 | outer_width - chip_width - chip_offset + 1,
133 | spacing / 2 + chip_height + 4
134 | ]) circle(charging_radius, $fn = 20);
135 | }
136 | }
137 |
138 | module
139 | left()
140 | {
141 |
142 | linear_extrude(height = thickness, center = true) difference()
143 | {
144 | dxf("left_outsideCutPath", 0);
145 | button_radius = 3.3;
146 | button_distance = 14;
147 | button_offset = 35;
148 | translate([
149 | outer_width + spacing / 2 + button_offset,
150 | spacing / 2 + outer_height / 2
151 | ]) circle(button_radius, $fn = 20);
152 | translate([
153 | outer_width + spacing / 2 + button_offset + button_distance,
154 | spacing / 2 + outer_height / 2
155 | ]) circle(button_radius, $fn = 20);
156 | }
157 | }
158 |
159 | module
160 | right()
161 | {
162 | linear_extrude(height = thickness, center = true)
163 | dxf("right_outsideCutPath", 0);
164 | }
165 |
166 | module
167 | bottom()
168 | {
169 | linear_extrude(height = thickness, center = true)
170 | dxf("bottom_outsideCutPath", 0);
171 | }
172 |
173 | module
174 | box()
175 | {
176 | front();
177 | back();
178 | right();
179 | left();
180 | bottom();
181 | top();
182 | }
183 |
184 | if (DXF) {
185 | projection(cut = true) box();
186 | } else {
187 | box();
188 | }
189 |
--------------------------------------------------------------------------------
/test/comparing/integration-basic.scad:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Some header comment
4 | *
5 | */
6 |
7 | include
8 | include
9 |
10 | module
11 | polyhole_demo()
12 | {
13 | difference()
14 | {
15 | cube(size = [ 100, 27, 3 ]);
16 | union()
17 | {
18 | for (i = [1:10]) {
19 | translate([ (i * i + i) / 2 + 3 * i, 8, -1 ])
20 | mcad_polyhole(h = 5, d = i);
21 |
22 | assign(d = i + 0.5)
23 | translate([ (d * d + d) / 2 + 3 * d, 19, -1 ])
24 | mcad_polyhole(h = 5, d = d);
25 | }
26 | }
27 | }
28 | }
29 |
30 | /**
31 | * Measures the distance between two 3D vectors.
32 | *
33 | * @param vector_a The first 3D vector to compare.
34 | * @param vector_b The second 3D vector to compare.
35 | * @return The distance between vector_a and vector_b.
36 | */
37 | function MTH_distance3D(vector_a, vector_b) =
38 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
39 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
40 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
41 |
42 | polyhole_demo();
43 |
44 | // examples of usage
45 | // include this in your code:
46 | // use
47 | // then:
48 | // a simple rack
49 | rack(4,
50 | 20,
51 | 10,
52 | 1); // CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
53 | // a simple pinion and translation / rotation to make it mesh the rack
54 | translate([ 0, -8.5, 0 ]) rotate([ 0, 0, 360 / 10 / 2 ])
55 | pinion(MTH_distance3D([ 1, 2, 3 ], [ 4, 5, 6 ]), 10, 10, 5);
56 |
--------------------------------------------------------------------------------
/test/comparing/source.scad:
--------------------------------------------------------------------------------
1 | include
2 | include
3 | use
4 |
5 | include
6 |
7 | use
8 |
9 | // This file is placed under the public domain
10 |
11 | // from: http://www.thingiverse.com/thing:9512
12 | // Author: nefercheprure
13 |
14 | // Examples:
15 | // standard LEGO 2x1 tile has no pin
16 | // block(1,2,1/3,reinforcement=false,flat_top=true);
17 | // standard LEGO 2x1 flat has pin
18 | // block(1,2,1/3,reinforcement=true);
19 | // standard LEGO 2x1 brick has pin
20 | // block(1,2,1,reinforcement=true);
21 | // standard LEGO 2x1 brick without pin
22 | // block(1,2,1,reinforcement=false);
23 | // standard LEGO 2x1x5 brick has no pin and has hollow knobs
24 | // block(1,2,5,reinforcement=false,hollow_knob=true);
25 |
26 | knob_diameter = 4.8; // knobs on top of blocks
27 | knob_height = 2;
28 | knob_spacing = 8.0;
29 | wall_thickness = 1.45;
30 | roof_thickness = 1.05;
31 | block_height = 9.5;
32 | pin_diameter = 3; // pin for bottom blocks with width or length of 1
33 | post_diameter = 6.5;
34 | reinforcing_width = 1.5;
35 | axle_spline_width = 2.0;
36 | axle_diameter = 5;
37 | cylinder_precision = 0.5;
38 |
39 | /* EXAMPLES:
40 | block(2,1,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true);
41 | translate([50,-10,0])
42 | block(1,2,1/3,axle_hole=false,circular_hole=true,reinforcement=false,hollow_knob=true,flat_top=true);
43 | translate([10,0,0])
44 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true);
45 | translate([30,0,0])
46 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=false,flat_top=false);
47 | translate([50,0,0])
48 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false);
49 | translate([0,20,0])
50 | block(3,2,2/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false);
51 | translate([20,20,0])
52 | block(3,2,1,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false);
53 | translate([40,20,0])
54 | block(3,2,1/3,axle_hole=false,circular_hole=false,reinforcement=false,hollow_knob=false,flat_top=false);
55 | translate([0,-10,0])
56 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false);
57 | translate([0,-20,0])
58 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=false);
59 | translate([0,-30,0])
60 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=true);
61 | //*/
62 |
63 | module block(width,
64 | length,
65 | height,
66 | axle_hole = false,
67 | reinforcement = false,
68 | hollow_knob = false,
69 | flat_top = false,
70 | circular_hole = false,
71 | solid_bottom = true,
72 | center = false)
73 | {
74 | overall_length =
75 | (length - 1) * knob_spacing + knob_diameter + wall_thickness * 2;
76 | overall_width =
77 | (width - 1) * knob_spacing + knob_diameter + wall_thickness * 2;
78 | center = center == true ? 1 : 0;
79 | translate(center * [ -overall_length / 2, -overall_width / 2, 0 ]) union()
80 | {
81 | difference()
82 | {
83 | union()
84 | {
85 | // body:
86 | cube([ overall_length, overall_width, height * block_height ]);
87 | // knobs:
88 | if (flat_top != true)
89 | translate([
90 | knob_diameter / 2 + wall_thickness,
91 | knob_diameter / 2 + wall_thickness,
92 | 0
93 | ]) for (ycount = [0:width - 1]) for (xcount =
94 | [0:length - 1])
95 | {
96 | translate(
97 | [ xcount * knob_spacing, ycount * knob_spacing, 0 ])
98 | difference()
99 | {
100 | cylinder(r = knob_diameter / 2,
101 | h = block_height * height + knob_height,
102 | $fs = cylinder_precision);
103 | if (hollow_knob == true)
104 | translate([ 0, 0, -roof_thickness ]) cylinder(
105 | r = pin_diameter / 2,
106 | h = block_height * height + knob_height +
107 | 2 * roof_thickness,
108 | $fs = cylinder_precision);
109 | }
110 | }
111 | }
112 | // hollow bottom:
113 | if (solid_bottom == false)
114 | translate([ wall_thickness, wall_thickness, -roof_thickness ])
115 | cube([
116 | overall_length - wall_thickness * 2,
117 | overall_width - wall_thickness * 2,
118 | block_height *
119 | height
120 | ]);
121 | // flat_top -> groove around bottom
122 | if (flat_top == true) {
123 | translate([
124 | -wall_thickness / 2,
125 | -wall_thickness * 2 / 3,
126 | -wall_thickness / 2
127 | ])
128 | cube([
129 | overall_length + wall_thickness,
130 | wall_thickness,
131 | wall_thickness
132 | ]);
133 | translate([
134 | -wall_thickness / 2,
135 | overall_width - wall_thickness / 3,
136 | -wall_thickness / 2
137 | ])
138 | cube([
139 | overall_length + wall_thickness,
140 | wall_thickness,
141 | wall_thickness
142 | ]);
143 |
144 | translate([
145 | -wall_thickness * 2 / 3,
146 | -wall_thickness / 2,
147 | -wall_thickness / 2
148 | ])
149 | cube([
150 | wall_thickness,
151 | overall_width + wall_thickness,
152 | wall_thickness
153 | ]);
154 | translate([
155 | overall_length - wall_thickness / 3,
156 | 0,
157 | -wall_thickness / 2
158 | ])
159 | cube([
160 | wall_thickness,
161 | overall_width + wall_thickness,
162 | wall_thickness
163 | ]);
164 | }
165 | if (axle_hole == true)
166 | if (width > 1 && length > 1)
167 | for (ycount = [1:width - 1])
168 | for (xcount = [1:length - 1])
169 | translate([
170 | xcount * knob_spacing,
171 | ycount * knob_spacing,
172 | roof_thickness
173 | ]) axle(height);
174 | if (circular_hole == true)
175 | if (width > 1 && length > 1)
176 | for (ycount = [1:width - 1])
177 | for (xcount = [1:length - 1])
178 | translate([
179 | xcount * knob_spacing,
180 | ycount * knob_spacing,
181 | roof_thickness
182 | ]) cylinder(r = knob_diameter / 2,
183 | h = height * block_height +
184 | roof_thickness / 4,
185 | $fs = cylinder_precision);
186 | }
187 |
188 | if (reinforcement == true && width > 1 && length > 1)
189 | difference()
190 | {
191 | for (ycount = [1:width - 1])
192 | for (xcount = [1:length - 1])
193 | translate(
194 | [ xcount * knob_spacing, ycount * knob_spacing, 0 ])
195 | reinforcement(height);
196 | for (ycount = [1:width - 1])
197 | for (xcount = [1:length - 1])
198 | translate([
199 | xcount * knob_spacing,
200 | ycount * knob_spacing,
201 | -,roof_thickness / 2
202 | ]) cylinder(r = knob_diameter / 2,
203 | h = height * block_height + roof_thickness,
204 | $fs = cylinder_precision);
205 | }
206 | // posts:
207 | if (solid_bottom == false)
208 | if (width > 1 && length > 1)
209 | for (ycount = [1:width - 1])
210 | for (xcount = [1:length - 1])
211 | translate(
212 | [ xcount * knob_spacing, ycount * knob_spacing, 0 ])
213 | post(height);
214 |
215 | if (reinforcement == true && width == 1 && length != 1)
216 | for (xcount = [1:length - 1])
217 | translate([ xcount * knob_spacing, overall_width / 2, 0 ])
218 | cylinder(r = pin_diameter / 2,
219 | h = block_height * height,
220 | $fs = cylinder_precision);
221 |
222 | if (reinforcement == true && length == 1 && width != 1)
223 | for (ycount = [1:width - 1])
224 | translate([ overall_length / 2, ycount * knob_spacing, 0 ])
225 | cylinder(r = pin_diameter / 2,
226 | h = block_height * height,
227 | $fs = cylinder_precision);
228 | }
229 | }
230 |
231 | module post(height)
232 | {
233 | difference()
234 | {
235 | cylinder(r = post_diameter / 2,
236 | h = height * block_height - roof_thickness / 2,
237 | $fs = cylinder_precision);
238 | translate([ 0, 0, -roof_thickness / 2 ])
239 | cylinder(r = knob_diameter / 2,
240 | h = height * block_height + roof_thickness / 4,
241 | $fs = cylinder_precision);
242 | }
243 | }
244 |
245 | module reinforcement(height)
246 | {
247 | union()
248 | {
249 | translate([ 0, 0, height * block_height / 2 ]) union()
250 | {
251 | cube(
252 | [
253 | reinforcing_width,
254 | knob_spacing + knob_diameter + wall_thickness / 2,
255 | height *
256 | block_height
257 | ],
258 | center = true);
259 | rotate(v = [ 0, 0, 1 ], a = 90) cube(
260 | [
261 | reinforcing_width,
262 | knob_spacing + knob_diameter + wall_thickness / 2,
263 | height *
264 | block_height
265 | ],
266 | center = true);
267 | }
268 | }
269 | }
270 |
271 | module axle(height)
272 | {
273 | translate([ 0, 0, height * block_height / 2 ]) union()
274 | {
275 | cube([ axle_diameter, axle_spline_width, height * block_height ],
276 | center = true);
277 | cube([ axle_spline_width, axle_diameter, height * block_height ],
278 | center = true);
279 | }
280 | }
281 |
282 | /**
283 | * Calculate the number of facets to generate for radius `r`. This is intended
284 | * to mimic OpenSCAD's internal get_fragments_from_r() function.
285 | *
286 | * @param r Radius of circle
287 | */
288 | function get_fragments_from_r(r) =
289 | (($fn > 0) ? $fn
290 | : (r < 0.00000095367431640625)
291 | ? 3
292 | : ceil(max(min(360 / $fa, r * 2 * PI / $fs), 5)));
293 |
294 | /**
295 | * This is a function that generates a series of values ala $t for use as facet
296 | * IDs.
297 | *
298 | * @param r Radius of circle
299 | */
300 | function gen_facet_series(r) = [0:1.0 / get_fragments_from_r(r):1.0001];
301 |
302 | // example
303 | translate([ 0, 0, 10 ]) linear_extrude(1) circle(10, $fn = 10);
304 |
305 | linear_extrude(1) polygon([let(r = 10) for (t = gen_facet_series(r, $fn = 10))
306 | let(angle = t * 360)[cos(angle) * r, sin(angle) * r]]);
307 |
308 | post(5);
309 | reinforcement(10);
310 |
311 | MTH_triangleAreaFromLengths(3, 3, 9);
312 |
313 | /* function gen_facet_series_asdf (r) = [0 : 1.0 / ;get_fragments_from_r (r)
314 | * : 1.0001]; */
315 |
316 | MTH_triangleAreaFromLengths(3, 3, 9);
317 |
--------------------------------------------------------------------------------
/test/configs/google-style:
--------------------------------------------------------------------------------
1 | ---
2 | BasedOnStyle: Google
3 |
--------------------------------------------------------------------------------
/test/configs/llvm-style:
--------------------------------------------------------------------------------
1 | ---
2 | BasedOnStyle: LLVM
3 |
--------------------------------------------------------------------------------
/test/configs/tab-style:
--------------------------------------------------------------------------------
1 | ---
2 | IndentWidth: 4
3 | AccessModifierOffset: -4
4 | ContinuationIndentWidth: 4
5 | TabWidth: 4
6 | UseTab: Always
7 |
--------------------------------------------------------------------------------
/test/dirty/constant.scad:
--------------------------------------------------------------------------------
1 | E = 2.71828182845904523536028747135266249775724709369995; // Natural number.
2 |
3 | // Ratio of a circle's circumference to it's diameter.
4 | PI = 3.14159265358979323846264338327950288419716939937510;
5 |
6 | // Golden ratio.
7 | PHI = 1.61803398874989484820458683436563811772030917980576;
8 |
9 | // A set of common square roots.
10 | SQRT_2 = 1.41421356237309504880168872420969807856967187537694;
11 | SQRT_3 = 1.73205080756887729352744634150587236694280525381038;
12 | SQRT_5 = 2.23606797749978969640917366873127623544061835961152;
13 | SQRT_7 = 2.64575131106459059050161575363926042571025918308245;
14 |
15 | IN = 25.4 * MM;
16 | FT = 304.8 * MM;
17 | YD = 914.4 * MM;
18 | MI = 1609344.0 * MM;
19 | THOU = 0.0254 * MM;
20 | MIL = THOU;
21 |
22 | INCH = IN;
23 | FOOT = FT;
24 | FEET = FT;
25 | YARD = YD;
26 | MILE = MI;
27 |
--------------------------------------------------------------------------------
/test/dirty/function.scad:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | /**
6 | * Computes the exponent of a base and a power.
7 | *
8 | * @param base The number to be multiplied power times.
9 | * @param power The number of times to multiply the base together.
10 | * @return The base risen the the power.
11 | */
12 | function MTH_power(base, power ) = pow(base, power); // exp(ln(base) * power);
13 |
14 | /**
15 | * Measures the distance between two 3D vectors.
16 | *
17 | * @param vector_a The first 3D vector to compare.
18 | * @param vector_b The second 3D vector to compare.
19 | * @return The distance between vector_a and vector_b.
20 | */
21 | function MTH_distance3D (vector_a, vector_b)
22 | =
23 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
24 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
25 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
26 |
27 | /**
28 | * Measures the distance between two 2D vectors.
29 | *
30 | * @param vector_a The first 2D vector to compare.
31 | * @param vector_b The second 2D vector to compare.
32 | * @return The distance between vector_a and vector_b.
33 | */
34 | function MTH_distance2D(vector_a, vector_b) =
35 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
36 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]));
37 |
38 | function MTH_distance1D(vector_a , vector_b) = abs(
39 | vector_a
40 | -
41 | vector_b
42 | )
43 | ;
44 | function MTH_normalize( vector) = norm(vector); // vector / (max(MTH_distance3D(ORIGIN, vector), EPSILON));
45 | function MTH_normalVectorAngle(vector) = [
46 | 0 ,
47 | -1 * atan2(vector[2],MTH_distance1D([vector[0],vector[1]])),
48 | atan2(vector[1], vector[0])
49 | ];
50 |
--------------------------------------------------------------------------------
/test/dirty/include.scad:
--------------------------------------------------------------------------------
1 | include
2 | include
3 | use
4 |
5 | include
6 |
7 | use
8 |
9 |
10 | module
11 | testUnitTest()
12 | {
13 | include
14 | include
15 | echo(TST_equal("Equality", [ 1, 2, 4, 8 ], [ 1, 2, 4, 8 ]));
16 | echo(TST_notEqual("Non-equality", [ 1, 2, 4, 8 ], [ 0, 1, 1, 2 ]));
17 | echo(TST_true("Truthiness", 1 + 1 == 2));
18 | echo(TST_false("Falseness", 1 + 1 == 3));
19 | echo(TST_in("Presence", 4, [ 1, 2, 4, 8 ]));
20 | echo(TST_notIn("Absence", 16, [ 1, 2, 4, 8 ]));
21 | echo(TST_approximately("Approximately Equal", 15 + (EPSILON / 2), 15));
22 | }
23 |
--------------------------------------------------------------------------------
/test/dirty/integration-basic.scad:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Some header comment
4 | *
5 | */
6 |
7 | include
8 | include ;
9 |
10 | module polyhole_demo(){
11 | difference() {
12 | cube(size = [100,27,3]);
13 | union() {
14 | for(i = [1:10]) {
15 | translate([(i * i + i)/2 + 3 * i , 8,-1])
16 | mcad_polyhole(h = 5, d = i);
17 |
18 | assign(d = i + 0.5)
19 | translate([(d * d + d)/2 + 3 * d, 19,-1])
20 | mcad_polyhole(h = 5, d = d);
21 | }
22 | }
23 | }
24 | }
25 |
26 | /**
27 | * Measures the distance between two 3D vectors.
28 | *
29 | * @param vector_a The first 3D vector to compare.
30 | * @param vector_b The second 3D vector to compare.
31 | * @return The distance between vector_a and vector_b.
32 | */
33 | function MTH_distance3D (vector_a, vector_b)
34 | =
35 | sqrt((vector_a[0] - vector_b[0]) * (vector_a[0] - vector_b[0]) +
36 | (vector_a[1] - vector_b[1]) * (vector_a[1] - vector_b[1]) +
37 | (vector_a[2] - vector_b[2]) * (vector_a[2] - vector_b[2]));
38 |
39 |
40 | polyhole_demo();
41 |
42 | // examples of usage
43 | // include this in your code:
44 | // use
45 | // then:
46 | // a simple rack
47 | rack(4,20,10,1);//CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
48 | // a simple pinion and translation / rotation to make it mesh the rack
49 | translate([0,-8.5,0])rotate([0,0,360/10/2]) pinion(MTH_distance3D([1,2,3],[4,5,6]),10,10,5);
50 |
--------------------------------------------------------------------------------
/test/dirty/integration.scad:
--------------------------------------------------------------------------------
1 |
2 | echo(TST_true("Iterable", UTL_iterable([ 1, 2, 3 ])));
3 | echo(TST_false("Not iterable", UTL_iterable(1)));
4 |
5 | echo(TST_true("Empty", UTL_empty([])));
6 | echo(TST_false("Not empty", UTL_empty([ 1, 2, 3 ])));
7 |
8 | echo(TST_equal("Head", UTL_head([ 1, 2, 3 ]), 1));
9 |
10 | echo(TST_equal("Tail some", UTL_tail([ 1, 2, 3 ]), [ 2, 3 ]));
11 | echo(TST_equal("Tail one", UTL_tail([1]), []));
12 | echo(TST_equal("Tail zero", UTL_tail([]), undef));
13 |
14 | echo(TST_equal("Last some",
15 | UTL_last([ 1, 2, 3 ]), 3));
16 | echo(
17 | TST_equal(
18 | "Last one", UTL_last([1]), 1));
19 | echo(TST_equal("Last zero", UTL_last([]), undef));
20 |
21 | echo(TST_equal("Reverse some", UTL_reverse([ 1, 2, 3 ]), [ 3, 2, 1 ]));
22 | echo(TST_equal("Reverse zero", UTL_reverse([]), []));
23 |
24 | echo(TST_true("Equal number", UTL_equal(0, 0), true));
25 | echo(TST_false("Not equal number", UTL_equal(0, 5)));
26 | echo(TST_true("Equal empty list", UTL_equal([], [])));
27 | echo(TST_true("Equal list", UTL_equal([ 1, 2, 4 ], [ 1, 2, 4 ])));
28 | echo(TST_false("Not equal list", UTL_equal([ 1, 2, 3 ], [ 1, 2, 4 ])));
29 | echo(TST_true(
30 | "Equal nested list",
31 | UTL_equal([ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 1, 2, 3 ], [ 4, 5, 6 ] ])));
32 | echo(TST_false(
33 | "Not equal nested list",
34 | UTL_equal([ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 1, 2, 4 ], [ 4, 5, 6 ] ])));
35 | echo(
36 | TST_false("Equal unbalanced list",
37 | UTL_equal([ [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ 7, [ 4, 5, 6 ] ])));
38 |
39 | echo(TST_true("All", UTL_all([ true, true, true ])));
40 | echo(TST_false("Not all", UTL_all([ true, true, false ])));
41 |
42 | echo(TST_true("Any", UTL_any([ false, false, true ])));
43 | echo(TST_false("Not any", UTL_any([ false, false, false ])));
44 |
45 | echo(TST_true("Contains", UTL_contains([ 1, 2, 3 ], 2)));
46 | echo(TST_false("Doesn't contain", UTL_contains([ 1, 2, 3 ], 6)));
47 |
48 | echo(TST_equal("Zip zero", UTL_zip([]), [])); echo(TST_equal("Zip zero 2", UTL_zip([ [], [], [] ]), [])); echo(TST_equal("Zip zero 3", UTL_zip([ [], [1], [2] ]), []));
49 | echo(TST_equal("Zip equal length",
50 | UTL_zip([[1,2,3],[4,5,6],[7,8,9]]),[[1,4,7],[2,5,8],[3,6,9]]));
51 | echo(TST_equal("Zip different length",
52 | UTL_zip([ [ 1, 2, 3 ], [ 4, 5 ], [ 7, 8, 9 ] ]),
53 | [ [ 1, 4, 7 ], [ 2, 5, 8 ] ]));
54 |
55 | echo(TST_equal("Sort zero", UTL_sort([]), []));
56 | echo(TST_equal(
57 | "Sort some", UTL_sort([ 4, 2, 8, 16, 1 ]), [ 1, 2, 4, 8, 16 ]));
58 |
59 | echo(TST_equal("One Pole Filter Zero", UTL_onePoleFilter([], 0), []));
60 | echo(TST_equal("One Pole Filter Some",
61 | UTL_onePoleFilter([ 1, 2, 3 ], 0),
62 | [ 1, 2, 3 ]));
63 | echo(TST_equal("One Pole Filter Positive",
64 | UTL_onePoleFilter([ 4, 2, 5 ], 0.5),
65 | [ 4, 3, 4 ]));
66 | echo(TST_equal("One Pole Filter Negative",
67 | UTL_onePoleFilter([ 4, 2, 5 ], -0.5),
68 | [ 4, 1, 7 ]));
69 |
70 |
71 |
72 | rod(20);
73 | translate([rodsize * 2.5, 0, 0]) rod(20, true);
74 | translate([rodsize * 5, 0, 0]) screw(10, true);
75 | translate([rodsize * 7.5, 0, 0]) bearing();
76 | translate([rodsize * 10, 0, 0]) rodnut();
77 | translate([rodsize * 12.5, 0, 0]) rodwasher();
78 | translate([rodsize * 15, 0, 0]) nut();
79 | translate([rodsize * 17.5, 0, 0]) washer();
80 |
81 |
82 |
83 | //examples
84 | linearBearing(model="LM8UU");
85 | translate([20,0,0]) linearBearing(model="LM10UU");
86 |
87 |
88 | module metric_ruler(millimeters)
89 | {
90 | difference()
91 | {
92 | // Body of ruler
93 | color("Beige")
94 | cube(size = [length_mm(millimeters), length_cm(3), length_mm(1)]);
95 | // Centimeter markings
96 | for (i = [0:length_cm(1):length_mm(millimeters) + epsilon])
97 | {
98 | translate([i,length_cm(2.5),length_mm(0.75)])
99 | color("Red")
100 | cube(size = [length_mm(0.5), length_cm(1) + epsilon, length_mm(0.5) + epsilon], center = true);
101 | }
102 | // Half centimeter markings
103 | for (i = [length_cm(0.5):length_cm(1):length_mm(millimeters) + epsilon])
104 | {
105 | translate([i,length_cm(2.7),length_mm(0.875)])
106 | color("Red")
107 | cube(size = [length_mm(0.5), length_cm(0.6) + epsilon, length_mm(0.25) + epsilon], center = true);
108 | }
109 | // Millimeter markings
110 | for (i = [length_mm(1):length_mm(1):length_mm(millimeters) + epsilon])
111 | {
112 | translate([i,length_cm(2.85),length_mm(0.9375)])
113 | color("Red")
114 | cube(size = [length_mm(0.5), length_cm(0.3) + epsilon, length_mm(0.125) + epsilon], center = true);
115 | }
116 | }
117 | }
118 |
119 | metric_ruler(100);
120 |
121 |
122 |
123 |
124 | include
125 |
126 | module polyhole_demo(){
127 | difference() {
128 | cube(size = [100,27,3]);
129 | union() {
130 | for(i = [1:10]) {
131 | translate([(i * i + i)/2 + 3 * i , 8,-1])
132 | mcad_polyhole(h = 5, d = i);
133 |
134 | assign(d = i + 0.5)
135 | translate([(d * d + d)/2 + 3 * d, 19,-1])
136 | mcad_polyhole(h = 5, d = d);
137 | }
138 | }
139 | }
140 | }
141 |
142 | polyhole_demo();
143 |
144 |
145 |
146 |
147 | include ;
148 |
149 | // examples of usage
150 | // include this in your code:
151 | // use
152 | // then:
153 | // a simple rack
154 | rack(4,20,10,1);//CP (mm/tooth), width (mm), thickness(of base) (mm), # teeth
155 | // a simple pinion and translation / rotation to make it mesh the rack
156 | translate([0,-8.5,0])rotate([0,0,360/10/2]) pinion(4,10,10,5);
157 |
--------------------------------------------------------------------------------
/test/dirty/module.scad:
--------------------------------------------------------------------------------
1 | module gear(number_of_teeth,
2 | circular_pitch=false, diametral_pitch=false,
3 | pressure_angle=20, clearance = 0,
4 | verbose=false)
5 | {
6 | if(verbose) {
7 | echo("gear arguments:");
8 | echo(str(" number_of_teeth: ", number_of_teeth));
9 | echo(str(" circular_pitch: ", circular_pitch));
10 | echo(str(" diametral_pitch: ", diametral_pitch));
11 | echo(str(" pressure_angle: ", pressure_angle));
12 | echo(str(" clearance: ", clearance));
13 | }
14 | if (circular_pitch==false && diametral_pitch==false) echo("MCAD ERROR: gear module needs either a diametral_pitch or circular_pitch");
15 | if(verbose) echo("gear calculations:");
16 |
17 | //Convert diametrial pitch to our native circular pitch
18 | circular_pitch = (circular_pitch!=false?circular_pitch:180/diametral_pitch);
19 |
20 | // Pitch diameter: Diameter of pitch circle.
21 | pitch_diameter = pitch_circular2diameter(number_of_teeth,circular_pitch);
22 | if(verbose) echo (str(" pitch_diameter: ", pitch_diameter));
23 | pitch_radius = pitch_diameter/2;
24 |
25 | // Base Circle
26 | base_diameter = pitch_diameter*cos(pressure_angle);
27 | if(verbose) echo (str(" base_diameter: ", base_diameter));
28 | base_radius = base_diameter/2;
29 |
30 | // Diametrial pitch: Number of teeth per unit length.
31 | pitch_diametrial = number_of_teeth / pitch_diameter;
32 | if(verbose) echo (str(" pitch_diametrial: ", pitch_diametrial));
33 |
34 | // Addendum: Radial distance from pitch circle to outside circle.
35 | addendum = 1/pitch_diametrial;
36 | if(verbose) echo (str(" addendum: ", addendum));
37 |
38 | //Outer Circle
39 | outer_radius = pitch_radius+addendum;
40 | outer_diameter = outer_radius*2;
41 | if(verbose) echo (str(" outer_diameter: ", outer_diameter));
42 |
43 | // Dedendum: Radial distance from pitch circle to root diameter
44 | dedendum = addendum + clearance;
45 | if(verbose) echo (str(" dedendum: ", dedendum));
46 |
47 | // Root diameter: Diameter of bottom of tooth spaces.
48 | root_radius = pitch_radius-dedendum;
49 | root_diameter = root_radius * 2;
50 | if(verbose) echo (str(" root_diameter: ", root_diameter));
51 |
52 | half_thick_angle = 360 / (4 * number_of_teeth);
53 | if(verbose) echo (str(" half_thick_angle: ", half_thick_angle));
54 |
55 | union()
56 | {
57 | rotate(half_thick_angle) circle($fn=number_of_teeth*2, r=root_radius*1.001);
58 |
59 | for (i= [1:number_of_teeth])
60 | //for (i = [0])
61 | {
62 | rotate([0,0,i*360/number_of_teeth])
63 | {
64 | involute_gear_tooth(
65 | pitch_radius = pitch_radius,
66 | root_radius = root_radius,
67 | base_radius = base_radius,
68 | outer_radius = outer_radius,
69 | half_thick_angle = half_thick_angle);
70 | }
71 | }
72 | }
73 | }
74 |
75 |
76 | module involute_gear_tooth(
77 | pitch_radius,
78 | root_radius,
79 | base_radius,
80 | outer_radius,
81 | half_thick_angle
82 | )
83 | {
84 | pitch_to_base_angle = involute_intersect_angle( base_radius, pitch_radius );
85 |
86 | outer_to_base_angle = involute_intersect_angle( base_radius, outer_radius );
87 |
88 | base1 = 0 - pitch_to_base_angle - half_thick_angle;
89 | pitch1 = 0 - half_thick_angle;
90 | outer1 = outer_to_base_angle - pitch_to_base_angle - half_thick_angle;
91 |
92 | b1 = polar_to_cartesian([ base1, base_radius ]);
93 | p1 = polar_to_cartesian([ pitch1, pitch_radius ]);
94 | o1 = polar_to_cartesian([ outer1, outer_radius ]);
95 |
96 | b2 = polar_to_cartesian([ -base1, base_radius ]);
97 | p2 = polar_to_cartesian([ -pitch1, pitch_radius ]);
98 | o2 = polar_to_cartesian([ -outer1, outer_radius ]);
99 |
100 | // ( root_radius > base_radius variables )
101 | pitch_to_root_angle = pitch_to_base_angle - involute_intersect_angle(base_radius, root_radius );
102 | root1 = pitch1 - pitch_to_root_angle;
103 | root2 = -pitch1 + pitch_to_root_angle;
104 | r1_t = polar_to_cartesian([ root1, root_radius ]);
105 | r2_t = polar_to_cartesian([ -root1, root_radius ]);
106 |
107 | // ( else )
108 | r1_f = polar_to_cartesian([ base1, root_radius ]);
109 | r2_f = polar_to_cartesian([ -base1, root_radius ]);
110 |
111 | if (root_radius > base_radius)
112 | {
113 | //echo("true");
114 | polygon( points = [
115 | r1_t,p1,o1,o2,p2,r2_t
116 | ], convexity = 3);
117 | }
118 | else
119 | {
120 | polygon( points = [
121 | r1_f, b1,p1,o1,o2,p2,b2,r2_f
122 | ], convexity = 3);
123 | }
124 |
125 | }
126 |
127 |
128 | module test_gears()
129 | {
130 | gear(number_of_teeth=51,circular_pitch=200);
131 | translate([0, 50])gear(number_of_teeth=17,circular_pitch=200);
132 | translate([-50,0]) gear(number_of_teeth=17,diametral_pitch=1);
133 | }
134 |
135 | module demo_3d_gears()
136 | {
137 | //double helical gear
138 | // (helics don't line up perfectly - for display purposes only ;)
139 | translate([50,0])
140 | {
141 | linear_extrude(height = 10, center = true, convexity = 10, twist = -45)
142 | gear(number_of_teeth=17,diametral_pitch=1);
143 | translate([0,0,10]) linear_extrude(height = 10, center = true, convexity = 10, twist = 45)
144 | gear(number_of_teeth=17,diametral_pitch=1);
145 | }
146 |
147 | //spur gear
148 | translate([0,-50]) linear_extrude(height = 10, center = true, convexity = 10, twist = 0)
149 | gear(number_of_teeth=17,diametral_pitch=1);
150 |
151 | }
152 |
153 | module test_involute_curve()
154 | {
155 | for (i=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
156 | {
157 | translate(polar_to_cartesian([involute_intersect_angle( 0.1,i) , i ])) circle($fn=15, r=0.5);
158 | }
159 | }
160 |
161 |
162 | module mcad_test_nuts_and_bolts_1 ()
163 | {
164 | $fn = 360;
165 |
166 | translate ([0, 15])
167 | mcad_nut_hole (3, proj = -1);
168 |
169 | mcad_bolt_hole (3, length = 30,tolerance =10, proj = -1);
170 |
171 | }
172 | //mcad_test_nuts_and_bolts_1 ();
173 |
174 | module mcad_test_nuts_and_bolts_2 ()
175 | {
176 | $fn = 360;
177 |
178 | difference(){
179 | cube(size = [10, 20, 10], center = true);
180 | union(){
181 | translate ([0, 15])
182 | mcad_nut_hole (3, proj = 2);
183 |
184 | linear_extrude (height = 20, center = true, convexity = 10,
185 | twist = 0)
186 | mcad_bolt_hole (3, length = 30, proj = 2);
187 | }
188 | }
189 | }
190 | //mcad_test_nuts_and_bolts_2 ();
191 |
192 | module mcad_test_nuts_and_bolts_3 ()
193 | {
194 | $fn = 360;
195 |
196 | mcad_bolt_hole_with_nut (
197 | size = 3,
198 | length = 10
199 | );
200 | }
201 |
--------------------------------------------------------------------------------
/test/dirty/source.scad:
--------------------------------------------------------------------------------
1 | include
2 | include
3 | use
4 |
5 | include
6 |
7 | use
8 |
9 |
10 | // This file is placed under the public domain
11 |
12 | // from: http://www.thingiverse.com/thing:9512
13 | // Author: nefercheprure
14 |
15 | // Examples:
16 | // standard LEGO 2x1 tile has no pin
17 | // block(1,2,1/3,reinforcement=false,flat_top=true);
18 | // standard LEGO 2x1 flat has pin
19 | // block(1,2,1/3,reinforcement=true);
20 | // standard LEGO 2x1 brick has pin
21 | // block(1,2,1,reinforcement=true);
22 | // standard LEGO 2x1 brick without pin
23 | // block(1,2,1,reinforcement=false);
24 | // standard LEGO 2x1x5 brick has no pin and has hollow knobs
25 | // block(1,2,5,reinforcement=false,hollow_knob=true);
26 |
27 |
28 | knob_diameter=4.8; //knobs on top of blocks
29 | knob_height=2;
30 | knob_spacing=8.0;
31 | wall_thickness=1.45;
32 | roof_thickness=1.05;
33 | block_height=9.5;
34 | pin_diameter=3; //pin for bottom blocks with width or length of 1
35 | post_diameter=6.5;
36 | reinforcing_width=1.5;
37 | axle_spline_width=2.0;
38 | axle_diameter=5;
39 | cylinder_precision=0.5;
40 |
41 | /* EXAMPLES:
42 | block(2,1,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true);
43 | translate([50,-10,0])
44 | block(1,2,1/3,axle_hole=false,circular_hole=true,reinforcement=false,hollow_knob=true,flat_top=true);
45 | translate([10,0,0])
46 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true);
47 | translate([30,0,0])
48 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=false,flat_top=false);
49 | translate([50,0,0])
50 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false);
51 | translate([0,20,0])
52 | block(3,2,2/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false);
53 | translate([20,20,0])
54 | block(3,2,1,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false);
55 | translate([40,20,0])
56 | block(3,2,1/3,axle_hole=false,circular_hole=false,reinforcement=false,hollow_knob=false,flat_top=false);
57 | translate([0,-10,0])
58 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false);
59 | translate([0,-20,0])
60 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=false);
61 | translate([0,-30,0])
62 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=true);
63 | //*/
64 |
65 | module block(width,length,height,axle_hole=false,reinforcement=false, hollow_knob=false, flat_top=false, circular_hole=false, solid_bottom=true, center=false) {
66 | overall_length=(length-1)*knob_spacing+knob_diameter+wall_thickness*2;
67 | overall_width=(width-1)*knob_spacing+knob_diameter+wall_thickness*2;
68 | center= center==true ? 1 : 0;
69 | translate(center*[-overall_length/2, -overall_width/2, 0])
70 | union() {
71 | difference() {
72 | union() {
73 | // body:
74 | cube([overall_length,overall_width,height*block_height]);
75 | // knobs:
76 | if (flat_top != true)
77 | translate([knob_diameter/2+wall_thickness,knob_diameter/2+wall_thickness,0])
78 | for (ycount=[0:width-1])
79 | for (xcount=[0:length-1]) {
80 | translate([xcount*knob_spacing,ycount*knob_spacing,0])
81 | difference() {
82 | cylinder(r=knob_diameter/2,h=block_height*height+knob_height,$fs=cylinder_precision);
83 | if (hollow_knob==true)
84 | translate([0,0,-roof_thickness])
85 | cylinder(r=pin_diameter/2,h=block_height*height+knob_height+2*roof_thickness,$fs=cylinder_precision);
86 | }
87 | }
88 | }
89 | // hollow bottom:
90 | if (solid_bottom == false)
91 | translate([wall_thickness,wall_thickness,-roof_thickness]) cube([overall_length-wall_thickness*2,overall_width-wall_thickness*2,block_height*height]);
92 | // flat_top -> groove around bottom
93 | if (flat_top == true) {
94 | translate([-wall_thickness/2,-wall_thickness*2/3,-wall_thickness/2])
95 | cube([overall_length+wall_thickness,wall_thickness,wall_thickness]);
96 | translate([-wall_thickness/2,overall_width-wall_thickness/3,-wall_thickness/2])
97 | cube([overall_length+wall_thickness,wall_thickness,wall_thickness]);
98 |
99 | translate([-wall_thickness*2/3,-wall_thickness/2,-wall_thickness/2])
100 | cube([wall_thickness,overall_width+wall_thickness,wall_thickness]);
101 | translate([overall_length-wall_thickness/3,0,-wall_thickness/2])
102 | cube([wall_thickness,overall_width+wall_thickness,wall_thickness]);
103 | }
104 | if (axle_hole==true)
105 | if (width>1 && length>1) for (ycount=[1:width-1])
106 | for (xcount=[1:length-1])
107 | translate([xcount*knob_spacing,ycount*knob_spacing,roof_thickness]) axle(height);
108 | if (circular_hole==true)
109 | if (width>1 && length>1) for (ycount=[1:width-1])
110 | for (xcount=[1:length-1])
111 | translate([xcount*knob_spacing,ycount*knob_spacing,roof_thickness])
112 | cylinder(r=knob_diameter/2, h=height*block_height+roof_thickness/4,$fs=cylinder_precision);
113 | }
114 |
115 | if (reinforcement==true && width>1 && length>1)
116 | difference() {
117 | for (ycount=[1:width-1])
118 | for (xcount=[1:length-1])
119 | translate([xcount*knob_spacing,ycount*knob_spacing,0]) reinforcement(height);
120 | for (ycount=[1:width-1])
121 | for (xcount=[1:length-1])
122 | translate([xcount*knob_spacing,ycount*knob_spacing,-roof_thickness/2]) cylinder(r=knob_diameter/2, h=height*block_height+roof_thickness, $fs=cylinder_precision);
123 | }
124 | // posts:
125 | if (solid_bottom == false)
126 | if (width>1 && length>1) for (ycount=[1:width-1])
127 | for (xcount=[1:length-1])
128 | translate([xcount*knob_spacing,ycount*knob_spacing,0]) post(height);
129 |
130 | if (reinforcement == true && width==1 && length!=1)
131 | for (xcount=[1:length-1])
132 | translate([xcount*knob_spacing,overall_width/2,0]) cylinder(r=pin_diameter/2,h=block_height*height,$fs=cylinder_precision);
133 |
134 | if (reinforcement == true && length==1 && width!=1)
135 | for (ycount=[1:width-1])
136 | translate([overall_length/2,ycount*knob_spacing,0]) cylinder(r=pin_diameter/2,h=block_height*height,$fs=cylinder_precision);
137 | }
138 | }
139 |
140 | module post(height) {
141 | difference() {
142 | cylinder(r=post_diameter/2, h=height*block_height-roof_thickness/2,$fs=cylinder_precision);
143 | translate([0,0,-roof_thickness/2])
144 | cylinder(r=knob_diameter/2, h=height*block_height+roof_thickness/4,$fs=cylinder_precision);
145 | }
146 | }
147 |
148 | module reinforcement(height) {
149 | union() {
150 | translate([0,0,height*block_height/2]) union() {
151 | cube([reinforcing_width,knob_spacing+knob_diameter+wall_thickness/2,height*block_height],center=true);
152 | rotate(v=[0,0,1],a=90) cube([reinforcing_width,knob_spacing+knob_diameter+wall_thickness/2,height*block_height], center=true);
153 | }
154 | }
155 | }
156 |
157 | module axle(height) {
158 | translate([0,0,height*block_height/2]) union() {
159 | cube([axle_diameter,axle_spline_width,height*block_height],center=true);
160 | cube([axle_spline_width,axle_diameter,height*block_height],center=true);
161 | }
162 | }
163 |
164 |
165 | /**
166 | * Calculate the number of facets to generate for radius `r`. This is intended
167 | * to mimic OpenSCAD's internal get_fragments_from_r() function.
168 | *
169 | * @param r Radius of circle
170 | */
171 | function get_fragments_from_r (r) = (
172 | ($fn > 0) ? $fn :
173 | (r < 0.00000095367431640625) ? 3 :
174 | ceil (max (min (360 / $fa, r * 2 * PI / $fs), 5))
175 | );
176 |
177 | /**
178 | * This is a function that generates a series of values ala $t for use as facet
179 | * IDs.
180 | *
181 | * @param r Radius of circle
182 | */
183 | function gen_facet_series (r) = [0 : 1.0 / get_fragments_from_r (r) : 1.0001];
184 |
185 | // example
186 | translate ([0, 0, 10])
187 | linear_extrude (1)
188 | circle (10, $fn = 10);
189 |
190 | linear_extrude (1)
191 | polygon (
192 | [
193 | let (r = 10)
194 | for (t = gen_facet_series (r, $fn = 10))
195 | let (angle = t * 360)
196 | [cos (angle) * r, sin (angle) * r]
197 | ]
198 | );
199 |
200 | post(5);
201 | reinforcement(10);
202 |
203 | MTH_triangleAreaFromLengths(3, 3, 9);
204 |
205 | /* function gen_facet_series_asdf (r) = [0 : 1.0 / ;get_fragments_from_r (r) : 1.0001]; */
206 |
207 | MTH_triangleAreaFromLengths(3, 3, 9);
208 |
--------------------------------------------------------------------------------
/test/dirty/walkytalky.scad:
--------------------------------------------------------------------------------
1 | DXF = true; // set to true to see the DXF projection, for a laser cutter for example
2 |
3 | file = "makercase-50-30-105-inside-3-5mm-thickness.dxf";
4 | thickness = 3.5;
5 |
6 | inner_width = 50;
7 | inner_height = 30;
8 | inner_depth = 105;
9 |
10 | outer_width = inner_width + 2 * thickness;
11 | outer_height = inner_height + 2 * thickness;
12 | outer_depth = inner_depth + 2 * thickness;
13 |
14 | spacing = 6;
15 |
16 | module dxf(layer){
17 | import (file = "makercase-50-30-105-inside-3-5mm-thickness.dxf",layer = layer);
18 | }
19 |
20 | module back(){
21 | linear_extrude(height = thickness, center = true) difference(){
22 | dxf("back_outsideCutPath", 0); // , - outer_height - spacing
23 | plug_radius = 3.5;
24 | translate([outer_width / 2, outer_height + spacing / 2 * 2 + outer_height / 2]) circle(plug_radius, $fn = 20);
25 | }
26 | }
27 |
28 | module top(){
29 | radius = 16;
30 | circle_y_offset = 24;
31 | offset_x = outer_depth + outer_width + 1 * spacing;
32 | offset_y = 3;
33 | linear_extrude(height = thickness, center = true)
34 |
35 | difference(){
36 | dxf("top_outsideCutPath", 0);
37 |
38 | // Speaker
39 | translate([offset_x + (outer_width / 2), offset_y + circle_y_offset])
40 | circle(r = radius, $fn=50);
41 |
42 | // Holes
43 | distance = 29 / 2;
44 | translate([offset_x + (outer_width / 2) - distance, offset_y + circle_y_offset - distance]) circle(r = 1, $fn=20);
45 | translate([offset_x + (outer_width / 2) + distance, offset_y + circle_y_offset - distance]) circle(r = 1, $fn=20);
46 | translate([offset_x + (outer_width / 2) - distance, offset_y + circle_y_offset + distance]) circle(r = 1, $fn=20);
47 | translate([offset_x + (outer_width / 2) + distance, offset_y + circle_y_offset + distance]) circle(r = 1, $fn=20);
48 |
49 | // LED
50 | led_radius = 2.3;
51 | led_offset = 7;
52 | translate([offset_x + (outer_width / 2), offset_y + circle_y_offset + radius + led_offset]) circle(r = led_radius, $fn=20);
53 |
54 | // Mic
55 | mic_offset = led_offset + led_radius + 7;
56 | translate([offset_x + (outer_width / 2), offset_y + circle_y_offset + radius + mic_offset]) circle(r = .5, $fn=20);
57 | }
58 |
59 | }
60 |
61 |
62 | module front(){
63 |
64 | socket_width = 7.5;
65 | chip_height = 12;
66 |
67 | linear_extrude(height = thickness, center = true) difference(){
68 | dxf("front_outsideCutPath", 0);
69 |
70 | // Microusb
71 | chip_width = 17;
72 | chip_offset = 12.5;
73 | translate([outer_width - chip_width/2 - chip_offset , spacing / 2 + chip_height]) square([chip_width, 1], center = true);
74 | translate([outer_width - chip_width/2 - chip_offset , spacing / 2 + chip_height + 1.5]) square([socket_width, 3], center = true);
75 |
76 | // Switch
77 | switch_height = 25;
78 | switch_radius = 3;
79 | translate([outer_width - chip_width/2 - chip_offset , spacing / 2 + switch_height]) circle(switch_radius, $fn=50);
80 |
81 | // Charging indicator
82 | charging_radius = .8;
83 | translate([outer_width - chip_width - chip_offset + 1 , spacing / 2 + chip_height + 4]) circle(charging_radius, $fn=20);
84 | }
85 | }
86 |
87 | module left(){
88 |
89 | linear_extrude(height = thickness, center = true) difference(){
90 | dxf("left_outsideCutPath", 0);
91 | button_radius = 3.3;
92 | button_distance = 14;
93 | button_offset = 35;
94 | translate([outer_width + spacing / 2 + button_offset, spacing/2 + outer_height / 2]) circle(button_radius, $fn = 20);
95 | translate([outer_width + spacing / 2 + button_offset + button_distance, spacing/2 + outer_height / 2]) circle(button_radius, $fn = 20);
96 | }
97 | }
98 |
99 | module right(){
100 | linear_extrude(height = thickness, center = true)
101 | dxf("right_outsideCutPath", 0);
102 | }
103 |
104 | module bottom(){
105 | linear_extrude(height = thickness, center = true)
106 | dxf("bottom_outsideCutPath", 0);
107 | }
108 |
109 | module box(){
110 | front();
111 | back();
112 | right();
113 | left();
114 | bottom();
115 | top();
116 | }
117 |
118 | if (DXF){
119 | projection (cut=true)
120 | box() ;
121 | } else {
122 | box();
123 | }
124 |
--------------------------------------------------------------------------------
/test/main.js:
--------------------------------------------------------------------------------
1 | /* eslint-env mocha */
2 | const { expect } = require('chai');
3 | const fs = require('fs-extra');
4 | const format = require('../index.js');
5 |
6 | describe('Main', () => {
7 | describe('integration', () => {
8 | it('should pass a basic integration test', async () => {
9 | const result = await format({ dry: true, input: './test/dirty/integration-basic.scad' });
10 | let correct = await fs.readFile('./test/clean/integration-basic.scad');
11 | correct = correct.toString();
12 | expect(result).to.be.a('array');
13 | expect(result[0]).to.be.a(typeof {});
14 | expect(result[0].source).to.be.a(typeof '');
15 | expect(result[0].formatted).to.be.a(typeof '');
16 | expect(result[0].source).to.equal('./test/dirty/integration-basic.scad');
17 | expect(result[0].formatted).to.equal(correct);
18 | });
19 | });
20 | describe('cases', () => {
21 | it('should format walkytalky.scad', async () => {
22 | const result = await format({ dry: true, input: './test/dirty/walkytalky.scad' });
23 | let correct = await fs.readFile('./test/clean/walkytalky.scad');
24 | correct = correct.toString();
25 | expect(result).to.be.a('array');
26 | expect(result[0]).to.be.a(typeof {});
27 | expect(result[0].source).to.be.a(typeof '');
28 | expect(result[0].formatted).to.be.a(typeof '');
29 | expect(result[0].source).to.equal('./test/dirty/walkytalky.scad');
30 | expect(result[0].formatted).to.equal(correct);
31 | });
32 | });
33 | describe('custom configurations', () => {
34 | it('should follow the Google style', async () => {
35 | const result = await format({ dry: true, input: './test/dirty/integration-basic.scad', config: './test/configs/google-style' });
36 | let correct = await fs.readFile('./test/clean/style-google-integration-basic.scad');
37 | correct = correct.toString();
38 | expect(result[0].formatted).to.equal(correct);
39 | });
40 |
41 | it('should follow the LLVM style', async () => {
42 | const result = await format({ dry: true, input: './test/dirty/integration-basic.scad', config: './test/configs/llvm-style' });
43 | let correct = await fs.readFile('./test/clean/style-llvm-integration-basic.scad');
44 | correct = correct.toString();
45 | expect(result[0].formatted).to.equal(correct);
46 | });
47 |
48 | it('should follow the tabs style', async () => {
49 | const result = await format({ dry: true, input: './test/dirty/integration-basic.scad', config: './test/configs/tab-style' });
50 | let correct = await fs.readFile('./test/clean/style-tab-integration-basic.scad');
51 | correct = correct.toString();
52 | expect(result[0].formatted).to.equal(correct);
53 | });
54 | });
55 | describe.skip('stdin & stdout', () => {
56 | it('should read from stdin and write to stdout', (done) => {
57 | expect(true).to.equal(true);
58 | done();
59 | });
60 | });
61 | describe.skip('glob input', () => {
62 | it('should select multiple files from a glob string', async () => {
63 | const result = await format({ input: './test/dirty/source.scad', output: './test/comparing/source.scad' });
64 | expect(result[0].source).to.equal('./test/dirty/source.scad');
65 | expect(result[0].formatted).to.equal('include');
66 | });
67 | });
68 | });
69 |
--------------------------------------------------------------------------------