├── .gitmodules
├── README.md
├── addon.cc
├── binding.gyp
├── binding.gyp mac
├── binding.windowsgyp
├── icon.icns
├── icon.ico
├── icons
├── 16x16.png
├── 32x32.png
├── 512x512.png
└── 64x64.png
├── main.js
├── main
├── LICENSE.txt
├── background single.js
├── background.html
├── background.js
├── deepnest.js
├── font
│ ├── fonts
│ │ ├── LatoLatin-Bold.eot
│ │ ├── LatoLatin-Bold.ttf
│ │ ├── LatoLatin-Bold.woff
│ │ ├── LatoLatin-Bold.woff2
│ │ ├── LatoLatin-BoldItalic.eot
│ │ ├── LatoLatin-BoldItalic.ttf
│ │ ├── LatoLatin-BoldItalic.woff
│ │ ├── LatoLatin-BoldItalic.woff2
│ │ ├── LatoLatin-Light.eot
│ │ ├── LatoLatin-Light.ttf
│ │ ├── LatoLatin-Light.woff
│ │ ├── LatoLatin-Light.woff2
│ │ ├── LatoLatin-Regular.eot
│ │ ├── LatoLatin-Regular.ttf
│ │ ├── LatoLatin-Regular.woff
│ │ └── LatoLatin-Regular.woff2
│ ├── generator_config.txt
│ ├── lato-hai-demo.html
│ ├── lato-hai-webfont.eot
│ ├── lato-hai-webfont.svg
│ ├── lato-hai-webfont.ttf
│ ├── lato-hai-webfont.woff
│ ├── lato-lig-demo.html
│ ├── lato-lig-webfont.eot
│ ├── lato-lig-webfont.svg
│ ├── lato-lig-webfont.ttf
│ ├── lato-lig-webfont.woff
│ ├── latolatinfonts.css
│ ├── specimen_files
│ │ ├── easytabs.js
│ │ ├── grid_12-825-55-15.css
│ │ └── specimen_stylesheet.css
│ └── stylesheet.css
├── img
│ ├── account.svg
│ ├── account_dark.svg
│ ├── arrow_down.svg
│ ├── arrow_right.svg
│ ├── arrow_up.svg
│ ├── auth0logo.svg
│ ├── background.png
│ ├── close.svg
│ ├── close_dark.svg
│ ├── code.svg
│ ├── credits.svg
│ ├── credits_light.svg
│ ├── delete.svg
│ ├── download.svg
│ ├── import.svg
│ ├── info.svg
│ ├── logo.svg
│ ├── logosmall.svg
│ ├── minus.svg
│ ├── plus.svg
│ ├── progress.svg
│ ├── reset.svg
│ ├── settings.svg
│ ├── shop.svg
│ ├── shop_dark.svg
│ ├── spin.svg
│ ├── spin_dark.svg
│ ├── start.svg
│ ├── stop.svg
│ ├── unlimited.svg
│ ├── unlimited_light.svg
│ ├── zoomin.svg
│ └── zoomout.svg
├── index.html
├── login.html
├── readme.md
├── style.css
├── svgnest.js
├── svgparser.js
└── util
│ ├── clipper.js
│ ├── clippernode.js
│ ├── d3-polygon.js
│ ├── domparser.js
│ ├── eval.js
│ ├── filesaver.js
│ ├── geometryutil.js
│ ├── hull.js
│ ├── interact.js
│ ├── json.js
│ ├── matrix.js
│ ├── parallel.js
│ ├── pathsegpolyfill.js
│ ├── placementworker.js
│ ├── ractive.js
│ ├── simplify.js
│ └── svgpanzoom.js
├── minkowski thread.cc
├── minkowski.cc
├── minkowski.h
├── minkowski
├── Makefile
├── Release
│ ├── .deps
│ │ └── Release
│ │ │ ├── addon.node.d
│ │ │ └── obj.target
│ │ │ └── addon
│ │ │ ├── addon.o.d
│ │ │ └── minkowski.o.d
│ ├── addon.node
│ └── obj.target
│ │ └── addon
│ │ ├── addon.o
│ │ └── minkowski.o
├── addon.target.mk
├── binding.Makefile
├── config.gypi
└── gyp-mac-tool
├── package.json
├── renderer.js
└── test.json
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "polygon"]
2 | path = polygon
3 | url = https://github.com/boostorg/polygon.git
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | **Deepnest**: A fast, robust nesting tool for laser cutters and other CNC tools
4 |
5 | **Download:** https://deepnest.io
6 |
7 | Deepnest is a desktop application based on [SVGNest](https://github.com/Jack000/SVGnest)
8 |
9 | - new nesting engine with speed critical code written in C
10 | - merges common lines for laser cuts
11 | - support for DXF files (via conversion)
12 | - new path approximation feature for highly complex parts
13 |
14 | To rebuild the native nesting engine
15 | - npm install --save-dev electron-rebuild
16 | - npm install
17 | - .\node_modules\.bin\electron-rebuild.cmd
18 | - copy contents of build/Release to minkowski/Release
19 | - To package app run electron-packager . deepnest --platform=win32 --arch=x64
--------------------------------------------------------------------------------
/addon.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "minkowski.h"
3 |
4 | using v8::FunctionTemplate;
5 | using v8::Handle;
6 | using v8::Object;
7 | using v8::String;
8 | using Nan::GetFunction;
9 | using Nan::New;
10 | using Nan::Set;
11 |
12 | // Expose synchronous and asynchronous access to our
13 | // Estimate() function
14 | NAN_MODULE_INIT(InitAll) {
15 | Set(target, New("calculateNFP").ToLocalChecked(),
16 | GetFunction(New(calculateNFP)).ToLocalChecked());
17 | }
18 |
19 | NODE_MODULE(addon, InitAll)
20 |
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | "targets": [
3 | {
4 | "target_name": "addon",
5 | "sources": [ "addon.cc", "minkowski.cc" ],
6 | 'cflags!': [ '-fno-exceptions', "-m64" ],
7 | "ldflags": [ "-m elf_i386" ],
8 | 'cflags_cc!': [ '-fno-exceptions', '-fPIC -m64' ],
9 | 'conditions': [
10 | ['OS=="mac"', {
11 | 'xcode_settings': {
12 | 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
13 | }
14 | }]
15 | ],
16 | "include_dirs" : [
17 | " {
64 | // Someone tried to run a second instance, we should focus our window.
65 | if (mainWindow) {
66 | if (mainWindow.isMinimized()) mainWindow.restore()
67 | mainWindow.focus()
68 | }
69 | })
70 |
71 | if (shouldQuit) {
72 | app.quit()
73 | }
74 |
75 | function createMainWindow() {
76 |
77 | // Create the browser window.
78 | const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize;
79 |
80 | var frameless = process.platform == 'darwin';
81 | //var frameless = true;
82 |
83 | mainWindow = new BrowserWindow({width: Math.ceil(width*0.9), height: Math.ceil(height*0.9), frame: !frameless, show: false})
84 |
85 | // and load the index.html of the app.
86 | mainWindow.loadURL(url.format({
87 | pathname: path.join(__dirname, './main/index.html'),
88 | protocol: 'file:',
89 | slashes: true
90 | }));
91 |
92 | mainWindow.setMenu(null);
93 |
94 | // Open the DevTools.
95 | //mainWindow.webContents.openDevTools()
96 |
97 | // Emitted when the window is closed.
98 | mainWindow.on('closed', function () {
99 | // Dereference the window object, usually you would store windows
100 | // in an array if your app supports multi windows, this is the time
101 | // when you should delete the corresponding element.
102 | mainWindow = null
103 | })
104 | }
105 |
106 | let winCount = 0;
107 |
108 | function createBackgroundWindows() {
109 | //busyWindows = [];
110 | // used to have 8, now just 1 background window
111 | if(winCount < 1){
112 | var back = new BrowserWindow({
113 | show: false
114 | });
115 |
116 | //back.webContents.openDevTools();
117 |
118 | back.loadURL(url.format({
119 | pathname: path.join(__dirname, './main/background.html'),
120 | protocol: 'file:',
121 | slashes: true
122 | }));
123 |
124 | backgroundWindows[winCount] = back;
125 |
126 | back.once('ready-to-show', () => {
127 | //back.show();
128 | winCount++;
129 | createBackgroundWindows();
130 | });
131 | }
132 | }
133 |
134 | // This method will be called when Electron has finished
135 | // initialization and is ready to create browser windows.
136 | // Some APIs can only be used after this event occurs.
137 | app.on('ready', () => {
138 | createMainWindow();
139 | mainWindow.once('ready-to-show', () => {
140 | mainWindow.show();
141 | createBackgroundWindows();
142 | })
143 | mainWindow.on('closed', () => {
144 | app.quit();
145 | });
146 | })
147 |
148 | // Quit when all windows are closed.
149 | app.on('window-all-closed', function () {
150 | app.quit()
151 | })
152 |
153 | app.on('activate', function () {
154 | // On OS X it's common to re-create a window in the app when the
155 | // dock icon is clicked and there are no other windows open.
156 | if (mainWindow === null) {
157 | createWindow()
158 | }
159 | })
160 |
161 | app.on('before-quit', function(){
162 | var p = path.join(__dirname, './nfpcache')
163 | if( fs.existsSync(p) ) {
164 | fs.readdirSync(p).forEach(function(file,index){
165 | var curPath = p + "/" + file;
166 | fs.unlinkSync(curPath);
167 | });
168 | }
169 | });
170 |
171 | //ipcMain.on('background-response', (event, payload) => mainWindow.webContents.send('background-response', payload));
172 | //ipcMain.on('background-start', (event, payload) => backgroundWindows[0].webContents.send('background-start', payload));
173 |
174 | ipcMain.on('background-start', function(event, payload){
175 | console.log('starting background!');
176 | for(var i=0; i
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Bold.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Bold.eot
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Bold.ttf
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Bold.woff
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Bold.woff2
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-BoldItalic.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-BoldItalic.eot
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-BoldItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-BoldItalic.ttf
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-BoldItalic.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-BoldItalic.woff
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-BoldItalic.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-BoldItalic.woff2
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Light.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Light.eot
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Light.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Light.ttf
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Light.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Light.woff
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Light.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Light.woff2
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Regular.eot
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Regular.ttf
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Regular.woff
--------------------------------------------------------------------------------
/main/font/fonts/LatoLatin-Regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/fonts/LatoLatin-Regular.woff2
--------------------------------------------------------------------------------
/main/font/generator_config.txt:
--------------------------------------------------------------------------------
1 | # Font Squirrel Font-face Generator Configuration File
2 | # Upload this file to the generator to recreate the settings
3 | # you used to create these fonts.
4 |
5 | {"mode":"optimal","formats":["ttf","woff","eotz"],"tt_instructor":"default","fix_vertical_metrics":"Y","fix_gasp":"xy","add_spaces":"Y","add_hyphens":"Y","fallback":"none","fallback_custom":"100","options_subset":"basic","subset_custom":"","subset_custom_range":"","subset_ot_features_list":"","css_stylesheet":"stylesheet.css","filename_suffix":"-webfont","emsquare":"2048","spacing_adjustment":"0"}
--------------------------------------------------------------------------------
/main/font/lato-hai-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/lato-hai-webfont.eot
--------------------------------------------------------------------------------
/main/font/lato-hai-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/lato-hai-webfont.ttf
--------------------------------------------------------------------------------
/main/font/lato-hai-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/lato-hai-webfont.woff
--------------------------------------------------------------------------------
/main/font/lato-lig-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/lato-lig-webfont.eot
--------------------------------------------------------------------------------
/main/font/lato-lig-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/lato-lig-webfont.ttf
--------------------------------------------------------------------------------
/main/font/lato-lig-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/font/lato-lig-webfont.woff
--------------------------------------------------------------------------------
/main/font/latolatinfonts.css:
--------------------------------------------------------------------------------
1 | /* Webfont: LatoLatin-Bold */@font-face {
2 | font-family: 'LatoLatinWeb';
3 | src: url('fonts/LatoLatin-Bold.eot'); /* IE9 Compat Modes */
4 | src: url('fonts/LatoLatin-Bold.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
5 | url('fonts/LatoLatin-Bold.woff2') format('woff2'), /* Modern Browsers */
6 | url('fonts/LatoLatin-Bold.woff') format('woff'), /* Modern Browsers */
7 | url('fonts/LatoLatin-Bold.ttf') format('truetype');
8 | font-style: normal;
9 | font-weight: bold;
10 | text-rendering: optimizeLegibility;
11 | }
12 |
13 | /* Webfont: LatoLatin-Regular */@font-face {
14 | font-family: 'LatoLatinWeb';
15 | src: url('fonts/LatoLatin-Regular.eot'); /* IE9 Compat Modes */
16 | src: url('fonts/LatoLatin-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
17 | url('fonts/LatoLatin-Regular.woff2') format('woff2'), /* Modern Browsers */
18 | url('fonts/LatoLatin-Regular.woff') format('woff'), /* Modern Browsers */
19 | url('fonts/LatoLatin-Regular.ttf') format('truetype');
20 | font-style: normal;
21 | font-weight: normal;
22 | text-rendering: optimizeLegibility;
23 | }
24 |
25 | /* Webfont: LatoLatin-Light */@font-face {
26 | font-family: 'LatoLatinWebLight';
27 | src: url('fonts/LatoLatin-Light.eot'); /* IE9 Compat Modes */
28 | src: url('fonts/LatoLatin-Light.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
29 | url('fonts/LatoLatin-Light.woff2') format('woff2'), /* Modern Browsers */
30 | url('fonts/LatoLatin-Light.woff') format('woff'), /* Modern Browsers */
31 | url('fonts/LatoLatin-Light.ttf') format('truetype');
32 | font-style: normal;
33 | font-weight: normal;
34 | text-rendering: optimizeLegibility;
35 | }
--------------------------------------------------------------------------------
/main/font/specimen_files/easytabs.js:
--------------------------------------------------------------------------------
1 | (function($){$.fn.easyTabs=function(option){var param=jQuery.extend({fadeSpeed:"fast",defaultContent:1,activeClass:'active'},option);$(this).each(function(){var thisId="#"+this.id;if(param.defaultContent==''){param.defaultContent=1;}
2 | if(typeof param.defaultContent=="number")
3 | {var defaultTab=$(thisId+" .tabs li:eq("+(param.defaultContent-1)+") a").attr('href').substr(1);}else{var defaultTab=param.defaultContent;}
4 | $(thisId+" .tabs li a").each(function(){var tabToHide=$(this).attr('href').substr(1);$("#"+tabToHide).addClass('easytabs-tab-content');});hideAll();changeContent(defaultTab);function hideAll(){$(thisId+" .easytabs-tab-content").hide();}
5 | function changeContent(tabId){hideAll();$(thisId+" .tabs li").removeClass(param.activeClass);$(thisId+" .tabs li a[href=#"+tabId+"]").closest('li').addClass(param.activeClass);if(param.fadeSpeed!="none")
6 | {$(thisId+" #"+tabId).fadeIn(param.fadeSpeed);}else{$(thisId+" #"+tabId).show();}}
7 | $(thisId+" .tabs li").click(function(){var tabId=$(this).find('a').attr('href').substr(1);changeContent(tabId);return false;});});}})(jQuery);
--------------------------------------------------------------------------------
/main/font/specimen_files/grid_12-825-55-15.css:
--------------------------------------------------------------------------------
1 | /*Notes about grid:
2 | Columns: 12
3 | Grid Width: 825px
4 | Column Width: 55px
5 | Gutter Width: 15px
6 | -------------------------------*/
7 |
8 |
9 |
10 | .section {margin-bottom: 18px;
11 | }
12 | .section:after {content: ".";display: block;height: 0;clear: both;visibility: hidden;}
13 | .section {*zoom: 1;}
14 |
15 | .section .firstcolumn,
16 | .section .firstcol {margin-left: 0;}
17 |
18 |
19 | /* Border on left hand side of a column. */
20 | .border {
21 | padding-left: 7px;
22 | margin-left: 7px;
23 | border-left: 1px solid #eee;
24 | }
25 |
26 | /* Border with more whitespace, spans one column. */
27 | .colborder {
28 | padding-left: 42px;
29 | margin-left: 42px;
30 | border-left: 1px solid #eee;
31 | }
32 |
33 |
34 |
35 | /* The Grid Classes */
36 | .grid1, .grid1_2cols, .grid1_3cols, .grid1_4cols, .grid2, .grid2_3cols, .grid2_4cols, .grid3, .grid3_2cols, .grid3_4cols, .grid4, .grid4_3cols, .grid5, .grid5_2cols, .grid5_3cols, .grid5_4cols, .grid6, .grid6_4cols, .grid7, .grid7_2cols, .grid7_3cols, .grid7_4cols, .grid8, .grid8_3cols, .grid9, .grid9_2cols, .grid9_4cols, .grid10, .grid10_3cols, .grid10_4cols, .grid11, .grid11_2cols, .grid11_3cols, .grid11_4cols, .grid12
37 | {margin-left: 15px;float: left;display: inline; overflow: hidden;}
38 |
39 |
40 | .width1, .grid1, .span-1 {width: 55px;}
41 | .width1_2cols,.grid1_2cols {width: 20px;}
42 | .width1_3cols,.grid1_3cols {width: 8px;}
43 | .width1_4cols,.grid1_4cols {width: 2px;}
44 | .input_width1 {width: 49px;}
45 |
46 | .width2, .grid2, .span-2 {width: 125px;}
47 | .width2_3cols,.grid2_3cols {width: 31px;}
48 | .width2_4cols,.grid2_4cols {width: 20px;}
49 | .input_width2 {width: 119px;}
50 |
51 | .width3, .grid3, .span-3 {width: 195px;}
52 | .width3_2cols,.grid3_2cols {width: 90px;}
53 | .width3_4cols,.grid3_4cols {width: 37px;}
54 | .input_width3 {width: 189px;}
55 |
56 | .width4, .grid4, .span-4 {width: 265px;}
57 | .width4_3cols,.grid4_3cols {width: 78px;}
58 | .input_width4 {width: 259px;}
59 |
60 | .width5, .grid5, .span-5 {width: 335px;}
61 | .width5_2cols,.grid5_2cols {width: 160px;}
62 | .width5_3cols,.grid5_3cols {width: 101px;}
63 | .width5_4cols,.grid5_4cols {width: 72px;}
64 | .input_width5 {width: 329px;}
65 |
66 | .width6, .grid6, .span-6 {width: 405px;}
67 | .width6_4cols,.grid6_4cols {width: 90px;}
68 | .input_width6 {width: 399px;}
69 |
70 | .width7, .grid7, .span-7 {width: 475px;}
71 | .width7_2cols,.grid7_2cols {width: 230px;}
72 | .width7_3cols,.grid7_3cols {width: 148px;}
73 | .width7_4cols,.grid7_4cols {width: 107px;}
74 | .input_width7 {width: 469px;}
75 |
76 | .width8, .grid8, .span-8 {width: 545px;}
77 | .width8_3cols,.grid8_3cols {width: 171px;}
78 | .input_width8 {width: 539px;}
79 |
80 | .width9, .grid9, .span-9 {width: 615px;}
81 | .width9_2cols,.grid9_2cols {width: 300px;}
82 | .width9_4cols,.grid9_4cols {width: 142px;}
83 | .input_width9 {width: 609px;}
84 |
85 | .width10, .grid10, .span-10 {width: 685px;}
86 | .width10_3cols,.grid10_3cols {width: 218px;}
87 | .width10_4cols,.grid10_4cols {width: 160px;}
88 | .input_width10 {width: 679px;}
89 |
90 | .width11, .grid11, .span-11 {width: 755px;}
91 | .width11_2cols,.grid11_2cols {width: 370px;}
92 | .width11_3cols,.grid11_3cols {width: 241px;}
93 | .width11_4cols,.grid11_4cols {width: 177px;}
94 | .input_width11 {width: 749px;}
95 |
96 | .width12, .grid12, .span-12 {width: 825px;}
97 | .input_width12 {width: 819px;}
98 |
99 | /* Subdivided grid spaces */
100 | .emptycols_left1, .prepend-1 {padding-left: 70px;}
101 | .emptycols_right1, .append-1 {padding-right: 70px;}
102 | .emptycols_left2, .prepend-2 {padding-left: 140px;}
103 | .emptycols_right2, .append-2 {padding-right: 140px;}
104 | .emptycols_left3, .prepend-3 {padding-left: 210px;}
105 | .emptycols_right3, .append-3 {padding-right: 210px;}
106 | .emptycols_left4, .prepend-4 {padding-left: 280px;}
107 | .emptycols_right4, .append-4 {padding-right: 280px;}
108 | .emptycols_left5, .prepend-5 {padding-left: 350px;}
109 | .emptycols_right5, .append-5 {padding-right: 350px;}
110 | .emptycols_left6, .prepend-6 {padding-left: 420px;}
111 | .emptycols_right6, .append-6 {padding-right: 420px;}
112 | .emptycols_left7, .prepend-7 {padding-left: 490px;}
113 | .emptycols_right7, .append-7 {padding-right: 490px;}
114 | .emptycols_left8, .prepend-8 {padding-left: 560px;}
115 | .emptycols_right8, .append-8 {padding-right: 560px;}
116 | .emptycols_left9, .prepend-9 {padding-left: 630px;}
117 | .emptycols_right9, .append-9 {padding-right: 630px;}
118 | .emptycols_left10, .prepend-10 {padding-left: 700px;}
119 | .emptycols_right10, .append-10 {padding-right: 700px;}
120 | .emptycols_left11, .prepend-11 {padding-left: 770px;}
121 | .emptycols_right11, .append-11 {padding-right: 770px;}
122 | .pull-1 {margin-left: -70px;}
123 | .push-1 {margin-right: -70px;margin-left: 18px;float: right;}
124 | .pull-2 {margin-left: -140px;}
125 | .push-2 {margin-right: -140px;margin-left: 18px;float: right;}
126 | .pull-3 {margin-left: -210px;}
127 | .push-3 {margin-right: -210px;margin-left: 18px;float: right;}
128 | .pull-4 {margin-left: -280px;}
129 | .push-4 {margin-right: -280px;margin-left: 18px;float: right;}
--------------------------------------------------------------------------------
/main/font/specimen_files/specimen_stylesheet.css:
--------------------------------------------------------------------------------
1 | @import url('grid_12-825-55-15.css');
2 |
3 | /*
4 | CSS Reset by Eric Meyer - Released under Public Domain
5 | http://meyerweb.com/eric/tools/css/reset/
6 | */
7 | html, body, div, span, applet, object, iframe,
8 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
9 | a, abbr, acronym, address, big, cite, code,
10 | del, dfn, em, font, img, ins, kbd, q, s, samp,
11 | small, strike, strong, sub, sup, tt, var,
12 | b, u, i, center, dl, dt, dd, ol, ul, li,
13 | fieldset, form, label, legend, table,
14 | caption, tbody, tfoot, thead, tr, th, td
15 | {margin: 0;padding: 0;border: 0;outline: 0;
16 | font-size: 100%;vertical-align: baseline;
17 | background: transparent;}
18 | body {line-height: 1;}
19 | ol, ul {list-style: none;}
20 | blockquote, q {quotes: none;}
21 | blockquote:before, blockquote:after,
22 | q:before, q:after {content: ''; content: none;}
23 | :focus {outline: 0;}
24 | ins {text-decoration: none;}
25 | del {text-decoration: line-through;}
26 | table {border-collapse: collapse;border-spacing: 0;}
27 |
28 |
29 |
30 |
31 | body {
32 | color: #000;
33 | background-color: #dcdcdc;
34 | }
35 |
36 | a {
37 | text-decoration: none;
38 | color: #1883ba;
39 | }
40 |
41 | h1{
42 | font-size: 32px;
43 | font-weight: normal;
44 | font-style: normal;
45 | margin-bottom: 18px;
46 | }
47 |
48 | h2{
49 | font-size: 18px;
50 | }
51 |
52 | #container {
53 | width: 865px;
54 | margin: 0px auto;
55 | }
56 |
57 |
58 | #header {
59 | padding: 20px;
60 | font-size: 36px;
61 | background-color: #000;
62 | color: #fff;
63 | }
64 |
65 | #header span {
66 | color: #666;
67 | }
68 | #main_content {
69 | background-color: #fff;
70 | padding: 60px 20px 20px;
71 | }
72 |
73 |
74 | #footer p {
75 | margin: 0;
76 | padding-top: 10px;
77 | padding-bottom: 50px;
78 | color: #333;
79 | font: 10px Arial, sans-serif;
80 | }
81 |
82 | .tabs {
83 | width: 100%;
84 | height: 31px;
85 | background-color: #444;
86 | }
87 | .tabs li {
88 | float: left;
89 | margin: 0;
90 | overflow: hidden;
91 | background-color: #444;
92 | }
93 | .tabs li a {
94 | display: block;
95 | color: #fff;
96 | text-decoration: none;
97 | font: bold 11px/11px 'Arial';
98 | text-transform: uppercase;
99 | padding: 10px 15px;
100 | border-right: 1px solid #fff;
101 | }
102 |
103 | .tabs li a:hover {
104 | background-color: #00b3ff;
105 |
106 | }
107 |
108 | .tabs li.active a {
109 | color: #000;
110 | background-color: #fff;
111 | }
112 |
113 |
114 |
115 | div.huge {
116 |
117 | font-size: 300px;
118 | line-height: 1em;
119 | padding: 0;
120 | letter-spacing: -.02em;
121 | overflow: hidden;
122 | }
123 | div.glyph_range {
124 | font-size: 72px;
125 | line-height: 1.1em;
126 | }
127 |
128 | .size10{ font-size: 10px; }
129 | .size11{ font-size: 11px; }
130 | .size12{ font-size: 12px; }
131 | .size13{ font-size: 13px; }
132 | .size14{ font-size: 14px; }
133 | .size16{ font-size: 16px; }
134 | .size18{ font-size: 18px; }
135 | .size20{ font-size: 20px; }
136 | .size24{ font-size: 24px; }
137 | .size30{ font-size: 30px; }
138 | .size36{ font-size: 36px; }
139 | .size48{ font-size: 48px; }
140 | .size60{ font-size: 60px; }
141 | .size72{ font-size: 72px; }
142 | .size90{ font-size: 90px; }
143 |
144 |
145 | .psample_row1 { height: 120px;}
146 | .psample_row1 { height: 120px;}
147 | .psample_row2 { height: 160px;}
148 | .psample_row3 { height: 160px;}
149 | .psample_row4 { height: 160px;}
150 |
151 | .psample {
152 | overflow: hidden;
153 | position: relative;
154 | }
155 | .psample p {
156 | line-height: 1.3em;
157 | display: block;
158 | overflow: hidden;
159 | margin: 0;
160 | }
161 |
162 | .psample span {
163 | margin-right: .5em;
164 | }
165 |
166 | .white_blend {
167 | width: 100%;
168 | height: 61px;
169 | background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVkAAAA9CAYAAAAH4BojAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNrs3TsKgFAMRUE/eer+NxztxMYuEWQG3ECKwwUF58ycAKixOAGAyAKILAAiCyCyACILgMgCiCyAyAIgsgAiCyCyAIgsgMgCiCwAIgsgsgAiC4DIAogsACIL0CWuZ3UGgLrIhjMA1EV2OAOAJQtgyQLwjOzmDAAiCyCyAIgsQFtkd2cAEFkAkQVAZAHaIns4A4AlC2DJAiCyACILILIAiCzAV5H1dQGAJQsgsgCILIDIAvwisl58AViyAJYsACILILIAIgvAe2T9EhxAZAFEFgCRBeiL7HAGgLrIhjMAWLIAliwAt1OAAQDwygTBulLIlQAAAABJRU5ErkJggg==);
170 | position: absolute;
171 | bottom: 0;
172 | }
173 | .black_blend {
174 | width: 100%;
175 | height: 61px;
176 | background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVkAAAA9CAYAAAAH4BojAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAPJJREFUeNrs3TEKhTAQRVGjibr/9QoxhY2N3Ywo50A28IrLwP9g6b1PAMSYTQAgsgAiC4DIAogsgMgCILIAIgsgsgCILIDIAogsACILILIAIguAyAKILIDIAiCyACILgMgCZCnjLWYAiFGvB0BQZJsZAFyyAC5ZAO6RXc0AILIAIguAyAKkRXYzA4DIAogsACILkBbZ3QwALlkAlywAIgsgsgAiC4DIArwVWf8uAHDJAogsACILILIAv4isH74AXLIALlkARBZAZAFEFoDnyPokOIDIAogsACILkBfZZgaAuMhWMwC4ZAE+p4x3mAEgxinAAJ+XBbPWGkwAAAAAAElFTkSuQmCC);
177 | position: absolute;
178 | bottom: 0;
179 | }
180 | .fullreverse {
181 | background: #000 !important;
182 | color: #fff !important;
183 | margin-left: -20px;
184 | padding-left: 20px;
185 | margin-right: -20px;
186 | padding-right: 20px;
187 | padding: 20px;
188 | margin-bottom:0;
189 | }
190 |
191 |
192 | .sample_table td {
193 | padding-top: 3px;
194 | padding-bottom:5px;
195 | padding-left: 5px;
196 | vertical-align: middle;
197 | line-height: 1.2em;
198 | }
199 |
200 | .sample_table td:first-child {
201 | background-color: #eee;
202 | text-align: right;
203 | padding-right: 5px;
204 | padding-left: 0;
205 | padding: 5px;
206 | font: 11px/12px "Courier New", Courier, mono;
207 | }
208 |
209 | code {
210 | white-space: pre;
211 | background-color: #eee;
212 | display: block;
213 | padding: 10px;
214 | margin-bottom: 18px;
215 | overflow: auto;
216 | }
217 |
218 |
219 | .bottom,.last {margin-bottom:0 !important; padding-bottom:0 !important;}
220 |
221 | .box {
222 | padding: 18px;
223 | margin-bottom: 18px;
224 | background: #eee;
225 | }
226 |
227 | .reverse,.reversed { background: #000 !important;color: #fff !important; border: none !important;}
228 |
229 | #bodycomparison {
230 | position: relative;
231 | overflow: hidden;
232 | font-size: 72px;
233 | height: 90px;
234 | white-space: nowrap;
235 | }
236 |
237 | #bodycomparison div{
238 | font-size: 72px;
239 | line-height: 90px;
240 | display: inline;
241 | margin: 0 15px 0 0;
242 | padding: 0;
243 | }
244 |
245 | #bodycomparison div span{
246 | font: 10px Arial;
247 | position: absolute;
248 | left: 0;
249 | }
250 | #xheight {
251 | float: none;
252 | position: absolute;
253 | color: #d9f3ff;
254 | font-size: 72px;
255 | line-height: 90px;
256 | }
257 |
258 | .fontbody {
259 | position: relative;
260 | }
261 | .arialbody{
262 | font-family: Arial;
263 | position: relative;
264 | }
265 | .verdanabody{
266 | font-family: Verdana;
267 | position: relative;
268 | }
269 | .georgiabody{
270 | font-family: Georgia;
271 | position: relative;
272 | }
273 |
274 | /* @group Layout page
275 | */
276 |
277 | #layout h1 {
278 | font-size: 36px;
279 | line-height: 42px;
280 | font-weight: normal;
281 | font-style: normal;
282 | }
283 |
284 | #layout h2 {
285 | font-size: 24px;
286 | line-height: 23px;
287 | font-weight: normal;
288 | font-style: normal;
289 | }
290 |
291 | #layout h3 {
292 | font-size: 22px;
293 | line-height: 1.4em;
294 | margin-top: 1em;
295 | font-weight: normal;
296 | font-style: normal;
297 | }
298 |
299 |
300 | #layout p.byline {
301 | font-size: 12px;
302 | margin-top: 18px;
303 | line-height: 12px;
304 | margin-bottom: 0;
305 | }
306 | #layout p {
307 | font-size: 14px;
308 | line-height: 21px;
309 | margin-bottom: .5em;
310 | }
311 |
312 | #layout p.large{
313 | font-size: 18px;
314 | line-height: 26px;
315 | }
316 |
317 | #layout .sidebar p{
318 | font-size: 12px;
319 | line-height: 1.4em;
320 | }
321 |
322 | #layout p.caption {
323 | font-size: 10px;
324 | margin-top: -16px;
325 | margin-bottom: 18px;
326 | }
327 |
328 | /* @end */
329 |
330 | /* @group Glyphs */
331 |
332 | #glyph_chart div{
333 | background-color: #d9f3ff;
334 | color: black;
335 | float: left;
336 | font-size: 36px;
337 | height: 1.2em;
338 | line-height: 1.2em;
339 | margin-bottom: 1px;
340 | margin-right: 1px;
341 | text-align: center;
342 | width: 1.2em;
343 | position: relative;
344 | padding: .6em .2em .2em;
345 | }
346 |
347 | #glyph_chart div p {
348 | position: absolute;
349 | left: 0;
350 | top: 0;
351 | display: block;
352 | text-align: center;
353 | font: bold 9px Arial, sans-serif;
354 | background-color: #3a768f;
355 | width: 100%;
356 | color: #fff;
357 | padding: 2px 0;
358 | }
359 |
360 |
361 | #glyphs h1 {
362 | font-family: Arial, sans-serif;
363 | }
364 | /* @end */
365 |
366 | /* @group Installing */
367 |
368 | #installing {
369 | font: 13px Arial, sans-serif;
370 | }
371 |
372 | #installing p,
373 | #glyphs p{
374 | line-height: 1.2em;
375 | margin-bottom: 18px;
376 | font: 13px Arial, sans-serif;
377 | }
378 |
379 |
380 |
381 | #installing h3{
382 | font-size: 15px;
383 | margin-top: 18px;
384 | }
385 |
386 | /* @end */
387 |
388 | #rendering h1 {
389 | font-family: Arial, sans-serif;
390 | }
391 | .render_table td {
392 | font: 11px "Courier New", Courier, mono;
393 | vertical-align: middle;
394 | }
395 |
396 |
397 |
--------------------------------------------------------------------------------
/main/font/stylesheet.css:
--------------------------------------------------------------------------------
1 | /* Generated by Font Squirrel (http://www.fontsquirrel.com) on July 12, 2014 */
2 |
3 |
4 |
5 | @font-face {
6 | font-family: 'latohairline';
7 | src: url('lato-hai-webfont.eot');
8 | src: url('lato-hai-webfont.eot?#iefix') format('embedded-opentype'),
9 | url('lato-hai-webfont.woff') format('woff'),
10 | url('lato-hai-webfont.ttf') format('truetype'),
11 | url('lato-hai-webfont.svg#latohairline') format('svg');
12 | font-weight: normal;
13 | font-style: normal;
14 |
15 | }
16 |
17 |
18 |
19 |
20 | @font-face {
21 | font-family: 'latolight';
22 | src: url('lato-lig-webfont.eot');
23 | src: url('lato-lig-webfont.eot?#iefix') format('embedded-opentype'),
24 | url('lato-lig-webfont.woff') format('woff'),
25 | url('lato-lig-webfont.ttf') format('truetype'),
26 | url('lato-lig-webfont.svg#latolight') format('svg');
27 | font-weight: normal;
28 | font-style: normal;
29 |
30 | }
--------------------------------------------------------------------------------
/main/img/account.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
--------------------------------------------------------------------------------
/main/img/account_dark.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
--------------------------------------------------------------------------------
/main/img/arrow_down.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/main/img/arrow_right.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/main/img/arrow_up.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/main/img/auth0logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
21 |
--------------------------------------------------------------------------------
/main/img/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfernoEmbedded/Deepnest/9e50524bcbe8084e9677a57d9e48364c6ddd3634/main/img/background.png
--------------------------------------------------------------------------------
/main/img/close.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
--------------------------------------------------------------------------------
/main/img/close_dark.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/main/img/code.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
22 |
--------------------------------------------------------------------------------
/main/img/credits.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
--------------------------------------------------------------------------------
/main/img/credits_light.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
--------------------------------------------------------------------------------
/main/img/delete.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/img/download.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/img/import.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
--------------------------------------------------------------------------------
/main/img/info.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
--------------------------------------------------------------------------------
/main/img/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
98 |
--------------------------------------------------------------------------------
/main/img/logosmall.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
67 |
--------------------------------------------------------------------------------
/main/img/minus.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/main/img/plus.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/main/img/progress.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/main/img/reset.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/main/img/settings.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
29 |
--------------------------------------------------------------------------------
/main/img/shop.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
--------------------------------------------------------------------------------
/main/img/shop_dark.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
--------------------------------------------------------------------------------
/main/img/spin.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/img/spin_dark.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/img/start.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/img/stop.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
--------------------------------------------------------------------------------
/main/img/unlimited.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
--------------------------------------------------------------------------------
/main/img/unlimited_light.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
--------------------------------------------------------------------------------
/main/img/zoomin.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/img/zoomout.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/main/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Deepnest login
4 |
5 |
6 |
7 |
64 |
65 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/main/readme.md:
--------------------------------------------------------------------------------
1 | # 
2 |
3 | **SVGNest**: A browser-based vector nesting tool.
4 |
5 | **Demo:** http://svgnest.com
6 |
7 | (requires SVG and webworker support). Mobile warning: running the demo is CPU intensive.
8 |
9 | references (PDF):
10 | - [López-Camacho *et al.* 2013](http://www.cs.stir.ac.uk/~goc/papers/EffectiveHueristic2DAOR2013.pdf)
11 | - [Kendall 2000](http://www.graham-kendall.com/papers/k2001.pdf)
12 | - [E.K. Burke *et al.* 2006](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.440.379&rep=rep1&type=pdf)
13 |
14 | ## What is "nesting"?
15 |
16 | Given a square piece of material and some letters to be laser-cut:
17 |
18 | 
19 |
20 | We want to pack all the letters into the square, using as little material as possible. If a single square is not enough, we also want to minimize the number of squares used.
21 |
22 | In the CNC world this is called "nesting", and [software](http://www.mynesting.com/) that [does this](http://www.autodesk.com/products/trunest/overview) is typically targeted at [industrial customers](http://www.hypertherm.com/en/Products/Automated_cutting/Nesting_software/) and [very expensive](http://www.nestfab.com/pricing/).
23 |
24 | SVGnest is a free and open-source alternative that solves this problem with the orbital approach outlined in [E.K. Burke *et al.* 2006], using a genetic algorithm for global optimization. It works for arbitrary containers and concave edge cases, and performs on-par with existing commercial software.
25 |
26 | 
27 |
28 | It also features part-in-part support, for placing parts in the holes of other parts.
29 |
30 | 
31 |
32 | ## Usage
33 |
34 | Make sure all parts have been converted to outlines, and that no outlines overlap. Upload the SVG file and select one of the outlines to be used as the bin.
35 |
36 | All other outlines are automatically processed as parts for nesting.
37 |
38 | ## Outline of algorithm
39 |
40 | While [good heuristics](http://cgi.csc.liv.ac.uk/~epa/surveyhtml.html) exist for the rectangular bin packing problem, in the real world we are concerned with irregular shapes.
41 |
42 | The strategy is made of two parts:
43 |
44 | - the placement strategy (ie. how do I insert each part into a bin?)
45 | - and the optimization strategy (ie. what's the best order of insertions?)
46 |
47 | ### Placing the part
48 |
49 | The key concept here is the "No Fit Polygon".
50 |
51 | Given polygons A and B, we want to "orbit" B around A such that they always touch but do not intersect.
52 |
53 | 
54 |
55 | The resulting orbit is the NFP. The NFP contains all possible placements of B that touches the previously placed parts. We can then choose a point on the NFP as the placement position using some heuristics.
56 |
57 | Similarly we can construct an "Inner Fit Polygon" for the part and the bin. This is the same as the NFP, except the orbiting polygon is inside the stationary one.
58 |
59 | When two or more parts have already been placed, we can take the union of the NFPs of the previously placed parts.
60 |
61 | 
62 |
63 | This means that we need to compute O(nlogn) NFPs to complete the first packing. While there are ways to mitigate this, we take the brute-force approach which has good properties for the optimization algo.
64 |
65 | ### Optimization
66 |
67 | Now that we can place the parts, we need to optimize the insertion order. Here's an example of a bad insertion order:
68 |
69 | 
70 |
71 | If the large "C" is placed last, the concave space inside it won't be utilized because all the parts that could have filled it have already been placed.
72 |
73 | To solve this, we use the "first-fit-decreasing" heuristic. Larger parts are placed first, and smaller parts last. This is quite intuitive, as the smaller parts tend to act as "sand" to fill the gaps left by the larger parts.
74 |
75 | 
76 |
77 | While this strategy gives us a good start, we want to explore more of the solution space. We could simply randomize the insertion order, but we can probably do better with a genetic algorithm. (If you don't know what a GA is, [this article](http://www.ai-junkie.com/ga/intro/gat1.html) is a very approachable read)
78 |
79 | ## Evaluating fitness
80 |
81 | In our GA the insertion order and the rotation of the parts form the gene. The fitness function follows these rules:
82 |
83 | 1. Minimize the number of unplaceable parts (parts that cannot fit any bin due to its rotation)
84 | 2. Minimize the number of bins used
85 | 3. Minimize the *width* of all placed parts
86 |
87 | The third one is rather arbitrary, as we can also optimize for rectangular bounds or a minimal concave hull. In real-world use the material to be cut tends to be rectangular, and those options tend to result in long slivers of un-used material.
88 |
89 | Because small mutations in the gene cause potentially large changes in overall fitness, the individuals of the population can be very similar. By caching NFPs new individuals can be evaluated very quickly.
90 |
91 | ## Performance
92 |
93 | 
94 |
95 | Performs similarly to commercial software, after both have run for about 5 minutes.
96 |
97 | ## Configuration parameters
98 |
99 | - **Space between parts:** Minimum space between parts (eg. for laser kerf, CNC offset etc.)
100 | - **Curve tolerance:** The maximum error allowed for linear approximations of Bezier paths and arcs, in SVG units or "pixels". Decrease this value if curved parts appear to slightly overlap.
101 | - **Part rotations:** The *possible* number of rotations to evaluate for each part. eg. 4 for only the cardinal directions. Larger values may improve results, but will be slower to converge.
102 | - **GA population:** The population size for the Genetic Algorithm
103 | - **GA mutation rate:** The probability of mutation for each gene or part placement. Values from 1-50
104 | - **Part in part:** When enabled, places parts in the holes of other parts. This is off by default as it can be resource intensive
105 | - **Explore concave areas:** When enabled, solves the concave edge case at a cost of some performance and placement robustness:
106 |
107 | 
108 |
109 | ## To-do
110 |
111 | - ~~Recursive placement (putting parts in holes of other parts)~~
112 | - Customize fitness function (gravity direction, etc)
113 | - kill worker threads when stop button is clicked
114 | - fix certain edge cases in NFP generation
--------------------------------------------------------------------------------
/main/util/d3-polygon.js:
--------------------------------------------------------------------------------
1 | // https://d3js.org/d3-polygon/ Version 1.0.2. Copyright 2016 Mike Bostock.
2 | (function (global, factory) {
3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
5 | (factory((global.d3 = global.d3 || {})));
6 | }(this, (function (exports) { 'use strict';
7 |
8 | var area = function(polygon) {
9 | var i = -1,
10 | n = polygon.length,
11 | a,
12 | b = polygon[n - 1],
13 | area = 0;
14 |
15 | while (++i < n) {
16 | a = b;
17 | b = polygon[i];
18 | area += a[1] * b[0] - a[0] * b[1];
19 | }
20 |
21 | return area / 2;
22 | };
23 |
24 | var centroid = function(polygon) {
25 | var i = -1,
26 | n = polygon.length,
27 | x = 0,
28 | y = 0,
29 | a,
30 | b = polygon[n - 1],
31 | c,
32 | k = 0;
33 |
34 | while (++i < n) {
35 | a = b;
36 | b = polygon[i];
37 | k += c = a[0] * b[1] - b[0] * a[1];
38 | x += (a[0] + b[0]) * c;
39 | y += (a[1] + b[1]) * c;
40 | }
41 |
42 | return k *= 3, [x / k, y / k];
43 | };
44 |
45 | // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
46 | // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
47 | // right, +y is up). Returns a positive value if ABC is counter-clockwise,
48 | // negative if clockwise, and zero if the points are collinear.
49 | var cross = function(a, b, c) {
50 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
51 | };
52 |
53 | function lexicographicOrder(a, b) {
54 | return a[0] - b[0] || a[1] - b[1];
55 | }
56 |
57 | // Computes the upper convex hull per the monotone chain algorithm.
58 | // Assumes points.length >= 3, is sorted by x, unique in y.
59 | // Returns an array of indices into points in left-to-right order.
60 | function computeUpperHullIndexes(points) {
61 | var n = points.length,
62 | indexes = [0, 1],
63 | size = 2;
64 |
65 | for (var i = 2; i < n; ++i) {
66 | while (size > 1 && cross(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
67 | indexes[size++] = i;
68 | }
69 |
70 | return indexes.slice(0, size); // remove popped points
71 | }
72 |
73 | var hull = function(points) {
74 | if ((n = points.length) < 3) return null;
75 |
76 | var i,
77 | n,
78 | sortedPoints = new Array(n),
79 | flippedPoints = new Array(n);
80 |
81 | for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
82 | sortedPoints.sort(lexicographicOrder);
83 | for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
84 |
85 | var upperIndexes = computeUpperHullIndexes(sortedPoints),
86 | lowerIndexes = computeUpperHullIndexes(flippedPoints);
87 |
88 | // Construct the hull polygon, removing possible duplicate endpoints.
89 | var skipLeft = lowerIndexes[0] === upperIndexes[0],
90 | skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
91 | hull = [];
92 |
93 | // Add upper hull in right-to-l order.
94 | // Then add lower hull in left-to-right order.
95 | for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
96 | for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
97 |
98 | return hull;
99 | };
100 |
101 | var contains = function(polygon, point) {
102 | var n = polygon.length,
103 | p = polygon[n - 1],
104 | x = point[0], y = point[1],
105 | x0 = p[0], y0 = p[1],
106 | x1, y1,
107 | inside = false;
108 |
109 | for (var i = 0; i < n; ++i) {
110 | p = polygon[i], x1 = p[0], y1 = p[1];
111 | if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
112 | x0 = x1, y0 = y1;
113 | }
114 |
115 | return inside;
116 | };
117 |
118 | var length = function(polygon) {
119 | var i = -1,
120 | n = polygon.length,
121 | b = polygon[n - 1],
122 | xa,
123 | ya,
124 | xb = b[0],
125 | yb = b[1],
126 | perimeter = 0;
127 |
128 | while (++i < n) {
129 | xa = xb;
130 | ya = yb;
131 | b = polygon[i];
132 | xb = b[0];
133 | yb = b[1];
134 | xa -= xb;
135 | ya -= yb;
136 | perimeter += Math.sqrt(xa * xa + ya * ya);
137 | }
138 |
139 | return perimeter;
140 | };
141 |
142 | exports.polygonArea = area;
143 | exports.polygonCentroid = centroid;
144 | exports.polygonHull = hull;
145 | exports.polygonContains = contains;
146 | exports.polygonLength = length;
147 |
148 | Object.defineProperty(exports, '__esModule', { value: true });
149 |
150 | })));
151 |
--------------------------------------------------------------------------------
/main/util/domparser.js:
--------------------------------------------------------------------------------
1 | /* inspired by https://gist.github.com/1129031 */
2 | /*global document, DOMParser*/
3 |
4 | (function(DOMParser) {
5 | "use strict";
6 |
7 | var
8 | proto = DOMParser.prototype
9 | , nativeParse = proto.parseFromString
10 | ;
11 |
12 | // Firefox/Opera/IE throw errors on unsupported types
13 | try {
14 | // WebKit returns null on unsupported types
15 | if ((new DOMParser()).parseFromString("", "text/html")) {
16 | // text/html parsing is natively supported
17 | return;
18 | }
19 | } catch (ex) {}
20 |
21 | proto.parseFromString = function(markup, type) {
22 | if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
23 | var
24 | doc = document.implementation.createHTMLDocument("")
25 | ;
26 | if (markup.toLowerCase().indexOf(' -1) {
27 | doc.documentElement.innerHTML = markup;
28 | }
29 | else {
30 | doc.body.innerHTML = markup;
31 | }
32 | return doc;
33 | } else {
34 | return nativeParse.apply(this, arguments);
35 | }
36 | };
37 | }(DOMParser));
--------------------------------------------------------------------------------
/main/util/eval.js:
--------------------------------------------------------------------------------
1 | var isNode = typeof module !== 'undefined' && module.exports;
2 |
3 | if (isNode) {
4 | process.once('message', function (code) {
5 | eval(JSON.parse(code).data);
6 | });
7 | } else {
8 | self.onmessage = function (code) {
9 | eval(code.data);
10 | };
11 | }
--------------------------------------------------------------------------------
/main/util/filesaver.js:
--------------------------------------------------------------------------------
1 | /* FileSaver.js
2 | * A saveAs() FileSaver implementation.
3 | * 1.1.20151003
4 | *
5 | * By Eli Grey, http://eligrey.com
6 | * License: MIT
7 | * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
8 | */
9 |
10 | /*global self */
11 | /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
12 |
13 | /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
14 |
15 | var saveAs = saveAs || (function(view) {
16 | "use strict";
17 | // IE <10 is explicitly unsupported
18 | if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
19 | return;
20 | }
21 | var
22 | doc = view.document
23 | // only get URL when necessary in case Blob.js hasn't overridden it yet
24 | , get_URL = function() {
25 | return view.URL || view.webkitURL || view;
26 | }
27 | , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
28 | , can_use_save_link = "download" in save_link
29 | , click = function(node) {
30 | var event = new MouseEvent("click");
31 | node.dispatchEvent(event);
32 | }
33 | , is_safari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent)
34 | , webkit_req_fs = view.webkitRequestFileSystem
35 | , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
36 | , throw_outside = function(ex) {
37 | (view.setImmediate || view.setTimeout)(function() {
38 | throw ex;
39 | }, 0);
40 | }
41 | , force_saveable_type = "application/octet-stream"
42 | , fs_min_size = 0
43 | // See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
44 | // https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
45 | // for the reasoning behind the timeout and revocation flow
46 | , arbitrary_revoke_timeout = 500 // in ms
47 | , revoke = function(file) {
48 | var revoker = function() {
49 | if (typeof file === "string") { // file is an object URL
50 | get_URL().revokeObjectURL(file);
51 | } else { // file is a File
52 | file.remove();
53 | }
54 | };
55 | if (view.chrome) {
56 | revoker();
57 | } else {
58 | setTimeout(revoker, arbitrary_revoke_timeout);
59 | }
60 | }
61 | , dispatch = function(filesaver, event_types, event) {
62 | event_types = [].concat(event_types);
63 | var i = event_types.length;
64 | while (i--) {
65 | var listener = filesaver["on" + event_types[i]];
66 | if (typeof listener === "function") {
67 | try {
68 | listener.call(filesaver, event || filesaver);
69 | } catch (ex) {
70 | throw_outside(ex);
71 | }
72 | }
73 | }
74 | }
75 | , auto_bom = function(blob) {
76 | // prepend BOM for UTF-8 XML and text/* types (including HTML)
77 | if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
78 | return new Blob(["\ufeff", blob], {type: blob.type});
79 | }
80 | return blob;
81 | }
82 | , FileSaver = function(blob, name, no_auto_bom) {
83 | if (!no_auto_bom) {
84 | blob = auto_bom(blob);
85 | }
86 | // First try a.download, then web filesystem, then object URLs
87 | var
88 | filesaver = this
89 | , type = blob.type
90 | , blob_changed = false
91 | , object_url
92 | , target_view
93 | , dispatch_all = function() {
94 | dispatch(filesaver, "writestart progress write writeend".split(" "));
95 | }
96 | // on any filesys errors revert to saving with object URLs
97 | , fs_error = function() {
98 | if (target_view && is_safari && typeof FileReader !== "undefined") {
99 | // Safari doesn't allow downloading of blob urls
100 | var reader = new FileReader();
101 | reader.onloadend = function() {
102 | var base64Data = reader.result;
103 | target_view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/));
104 | filesaver.readyState = filesaver.DONE;
105 | dispatch_all();
106 | };
107 | reader.readAsDataURL(blob);
108 | filesaver.readyState = filesaver.INIT;
109 | return;
110 | }
111 | // don't create more object URLs than needed
112 | if (blob_changed || !object_url) {
113 | object_url = get_URL().createObjectURL(blob);
114 | }
115 | if (target_view) {
116 | target_view.location.href = object_url;
117 | } else {
118 | var new_tab = view.open(object_url, "_blank");
119 | if (new_tab == undefined && is_safari) {
120 | //Apple do not allow window.open, see http://bit.ly/1kZffRI
121 | view.location.href = object_url
122 | }
123 | }
124 | filesaver.readyState = filesaver.DONE;
125 | dispatch_all();
126 | revoke(object_url);
127 | }
128 | , abortable = function(func) {
129 | return function() {
130 | if (filesaver.readyState !== filesaver.DONE) {
131 | return func.apply(this, arguments);
132 | }
133 | };
134 | }
135 | , create_if_not_found = {create: true, exclusive: false}
136 | , slice
137 | ;
138 | filesaver.readyState = filesaver.INIT;
139 | if (!name) {
140 | name = "download";
141 | }
142 | if (can_use_save_link) {
143 | object_url = get_URL().createObjectURL(blob);
144 | setTimeout(function() {
145 | save_link.href = object_url;
146 | save_link.download = name;
147 | click(save_link);
148 | dispatch_all();
149 | revoke(object_url);
150 | filesaver.readyState = filesaver.DONE;
151 | });
152 | return;
153 | }
154 | // Object and web filesystem URLs have a problem saving in Google Chrome when
155 | // viewed in a tab, so I force save with application/octet-stream
156 | // http://code.google.com/p/chromium/issues/detail?id=91158
157 | // Update: Google errantly closed 91158, I submitted it again:
158 | // https://code.google.com/p/chromium/issues/detail?id=389642
159 | if (view.chrome && type && type !== force_saveable_type) {
160 | slice = blob.slice || blob.webkitSlice;
161 | blob = slice.call(blob, 0, blob.size, force_saveable_type);
162 | blob_changed = true;
163 | }
164 | // Since I can't be sure that the guessed media type will trigger a download
165 | // in WebKit, I append .download to the filename.
166 | // https://bugs.webkit.org/show_bug.cgi?id=65440
167 | if (webkit_req_fs && name !== "download") {
168 | name += ".download";
169 | }
170 | if (type === force_saveable_type || webkit_req_fs) {
171 | target_view = view;
172 | }
173 | if (!req_fs) {
174 | fs_error();
175 | return;
176 | }
177 | fs_min_size += blob.size;
178 | req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
179 | fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
180 | var save = function() {
181 | dir.getFile(name, create_if_not_found, abortable(function(file) {
182 | file.createWriter(abortable(function(writer) {
183 | writer.onwriteend = function(event) {
184 | target_view.location.href = file.toURL();
185 | filesaver.readyState = filesaver.DONE;
186 | dispatch(filesaver, "writeend", event);
187 | revoke(file);
188 | };
189 | writer.onerror = function() {
190 | var error = writer.error;
191 | if (error.code !== error.ABORT_ERR) {
192 | fs_error();
193 | }
194 | };
195 | "writestart progress write abort".split(" ").forEach(function(event) {
196 | writer["on" + event] = filesaver["on" + event];
197 | });
198 | writer.write(blob);
199 | filesaver.abort = function() {
200 | writer.abort();
201 | filesaver.readyState = filesaver.DONE;
202 | };
203 | filesaver.readyState = filesaver.WRITING;
204 | }), fs_error);
205 | }), fs_error);
206 | };
207 | dir.getFile(name, {create: false}, abortable(function(file) {
208 | // delete file if it already exists
209 | file.remove();
210 | save();
211 | }), abortable(function(ex) {
212 | if (ex.code === ex.NOT_FOUND_ERR) {
213 | save();
214 | } else {
215 | fs_error();
216 | }
217 | }));
218 | }), fs_error);
219 | }), fs_error);
220 | }
221 | , FS_proto = FileSaver.prototype
222 | , saveAs = function(blob, name, no_auto_bom) {
223 | return new FileSaver(blob, name, no_auto_bom);
224 | }
225 | ;
226 | // IE 10+ (native saveAs)
227 | if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
228 | return function(blob, name, no_auto_bom) {
229 | if (!no_auto_bom) {
230 | blob = auto_bom(blob);
231 | }
232 | return navigator.msSaveOrOpenBlob(blob, name || "download");
233 | };
234 | }
235 |
236 | FS_proto.abort = function() {
237 | var filesaver = this;
238 | filesaver.readyState = filesaver.DONE;
239 | dispatch(filesaver, "abort");
240 | };
241 | FS_proto.readyState = FS_proto.INIT = 0;
242 | FS_proto.WRITING = 1;
243 | FS_proto.DONE = 2;
244 |
245 | FS_proto.error =
246 | FS_proto.onwritestart =
247 | FS_proto.onprogress =
248 | FS_proto.onwrite =
249 | FS_proto.onabort =
250 | FS_proto.onerror =
251 | FS_proto.onwriteend =
252 | null;
253 |
254 | return saveAs;
255 | }(
256 | typeof self !== "undefined" && self
257 | || typeof window !== "undefined" && window
258 | || this.content
259 | ));
260 | // `self` is undefined in Firefox for Android content script context
261 | // while `this` is nsIContentFrameMessageManager
262 | // with an attribute `content` that corresponds to the window
263 |
264 | if (typeof module !== "undefined" && module.exports) {
265 | module.exports.saveAs = saveAs;
266 | } else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
267 | define([], function() {
268 | return saveAs;
269 | });
270 | }
--------------------------------------------------------------------------------
/main/util/hull.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Graham's Scan Convex Hull Algorithm
3 | * @desc An implementation of the Graham's Scan Convex Hull algorithm in JavaScript.
4 | * @author Brian Barnett, brian@3kb.co.uk, http://brianbar.net/ || http://3kb.co.uk/
5 | * @version 1.0.4
6 | */
7 | function ConvexHullGrahamScan(){this.anchorPoint=void 0,this.reverse=!1,this.points=[]}ConvexHullGrahamScan.prototype={constructor:ConvexHullGrahamScan,Point:function(n,t){this.x=n,this.y=t},_findPolarAngle:function(n,t){var i,o,h=57.295779513082;if(!n||!t)return 0;if(i=t.x-n.x,o=t.y-n.y,0==i&&0==o)return 0;var r=Math.atan2(o,i)*h;return this.reverse?0>=r&&(r+=360):r>=0&&(r+=360),r},addPoint:function(n,t){return void 0===this.anchorPoint?void(this.anchorPoint=new this.Point(n,t)):this.anchorPoint.y>t&&this.anchorPoint.x>n||this.anchorPoint.y===t&&this.anchorPoint.x>n||this.anchorPoint.y>t&&this.anchorPoint.x===n?(this.points.push(new this.Point(this.anchorPoint.x,this.anchorPoint.y)),void(this.anchorPoint=new this.Point(n,t))):void this.points.push(new this.Point(n,t))},_sortPoints:function(){var n=this;return this.points.sort(function(t,i){var o=n._findPolarAngle(n.anchorPoint,t),h=n._findPolarAngle(n.anchorPoint,i);return h>o?-1:o>h?1:0})},_checkPoints:function(n,t,i){var o,h=this._findPolarAngle(n,t),r=this._findPolarAngle(n,i);return h>r?(o=h-r,!(o>180)):r>h?(o=r-h,o>180):!0},getHull:function(){var n,t,i=[];if(this.reverse=this.points.every(function(n){return n.x<0&&n.y<0}),n=this._sortPoints(),t=n.length,3>t)return n.unshift(this.anchorPoint),n;for(i.push(n.shift(),n.shift());;){var o,h,r;if(i.push(n.shift()),o=i[i.length-3],h=i[i.length-2],r=i[i.length-1],this._checkPoints(o,h,r)&&i.splice(i.length-2,1),0==n.length){if(t==i.length){var e=this.anchorPoint;return i=i.filter(function(n){return!!n}),i.some(function(n){return n.x==e.x&&n.y==e.y})||i.unshift(this.anchorPoint),i}n=i,t=n.length,i=[],i.push(n.shift(),n.shift())}}}},"function"==typeof define&&define.amd&&define(function(){return ConvexHullGrahamScan}),"undefined"!=typeof module&&(module.exports=ConvexHullGrahamScan);
--------------------------------------------------------------------------------
/main/util/json.js:
--------------------------------------------------------------------------------
1 | var JSON;if(!JSON){JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i 1) {
318 | ++runningWorkers;
319 | that._spawnReduceWorker([that.data[0], that.data[1]], cb, done, env, wrk);
320 | that.data.splice(0, 2);
321 | } else {
322 | if (wrk) wrk.terminate();
323 | }
324 | }
325 |
326 | var newOp = new Operation();
327 | this.operation.then(function () {
328 | if (that.data.length === 1) {
329 | newOp.resolve(null, that.data[0]);
330 | } else {
331 | for (var i = 0; i < that.options.maxWorkers && i < Math.floor(that.data.length / 2) ; ++i) {
332 | ++runningWorkers;
333 | that._spawnReduceWorker([that.data[i * 2], that.data[i * 2 + 1]], cb, done, env);
334 | }
335 |
336 | that.data.splice(0, i * 2);
337 | }
338 | });
339 | this.operation = newOp;
340 | return this;
341 | };
342 |
343 | Parallel.prototype.then = function (cb, errCb) {
344 | var that = this;
345 | var newOp = new Operation();
346 | errCb = typeof errCb === 'function' ? errCb : function(){};
347 |
348 | this.operation.then(function () {
349 | var retData;
350 |
351 | try {
352 | if (cb) {
353 | retData = cb(that.data);
354 | if (retData !== undefined) {
355 | that.data = retData;
356 | }
357 | }
358 | newOp.resolve(null, that.data);
359 | } catch (e) {
360 | if (errCb) {
361 | retData = errCb(e);
362 | if (retData !== undefined) {
363 | that.data = retData;
364 | }
365 |
366 | newOp.resolve(null, that.data);
367 | } else {
368 | newOp.resolve(null, e);
369 | }
370 | }
371 | }, function (err) {
372 | if (errCb) {
373 | var retData = errCb(err);
374 | if (retData !== undefined) {
375 | that.data = retData;
376 | }
377 |
378 | newOp.resolve(null, that.data);
379 | } else {
380 | newOp.resolve(null, err);
381 | }
382 | });
383 | this.operation = newOp;
384 | return this;
385 | };
386 |
387 | if (isCommonJS) {
388 | module.exports = Parallel;
389 | } else {
390 | self.Parallel = Parallel;
391 | }
392 | })();
--------------------------------------------------------------------------------
/main/util/placementworker.js:
--------------------------------------------------------------------------------
1 |
2 | // jsClipper uses X/Y instead of x/y...
3 | function toClipperCoordinates(polygon){
4 | var clone = [];
5 | for(var i=0; i 0){
40 | rotated.children = [];
41 | for(var j=0; j 0){
87 |
88 | var placed = [];
89 | var placements = [];
90 | fitness += 1; // add 1 for each new bin opened (lower fitness is better)
91 |
92 | for(i=0; i 2 && area > 0.1*self.config.clipperScale*self.config.clipperScale){
173 | clipper.AddPath(clone, ClipperLib.PolyType.ptSubject, true);
174 | }
175 | }
176 | }
177 |
178 | if(!clipper.Execute(ClipperLib.ClipType.ctUnion, combinedNfp, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero)){
179 | continue;
180 | }
181 |
182 | // difference with bin polygon
183 | var finalNfp = new ClipperLib.Paths();
184 | clipper = new ClipperLib.Clipper();
185 |
186 | clipper.AddPaths(combinedNfp, ClipperLib.PolyType.ptClip, true);
187 | clipper.AddPaths(clipperBinNfp, ClipperLib.PolyType.ptSubject, true);
188 | if(!clipper.Execute(ClipperLib.ClipType.ctDifference, finalNfp, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero)){
189 | continue;
190 | }
191 |
192 | finalNfp = ClipperLib.Clipper.CleanPolygons(finalNfp, 0.0001*self.config.clipperScale);
193 |
194 | for(j=0; j= 0){
273 | paths.splice(index,1);
274 | }
275 | }
276 |
277 | if(placements && placements.length > 0){
278 | allplacements.push(placements);
279 | }
280 | else{
281 | break; // something went wrong
282 | }
283 | }
284 |
285 | // there were parts that couldn't be placed
286 | fitness += 2*paths.length;
287 |
288 | return {placements: allplacements, fitness: fitness, paths: paths, area: binarea };
289 | };
290 |
291 | }
292 |
293 | // clipperjs uses alerts for warnings
294 | function alert(message) {
295 | console.log('alert: ', message);
296 | }
--------------------------------------------------------------------------------
/main/util/simplify.js:
--------------------------------------------------------------------------------
1 | /*
2 | (c) 2013, Vladimir Agafonkin
3 | Simplify.js, a high-performance JS polyline simplification library
4 | mourner.github.io/simplify-js
5 | modified by Jack Qiao
6 | */
7 |
8 | (function () { 'use strict';
9 |
10 | // to suit your point format, run search/replace for '.x' and '.y';
11 | // for 3D version, see 3d branch (configurability would draw significant performance overhead)
12 |
13 | // square distance between 2 points
14 | function getSqDist(p1, p2) {
15 |
16 | var dx = p1.x - p2.x,
17 | dy = p1.y - p2.y;
18 |
19 | return dx * dx + dy * dy;
20 | }
21 |
22 | // square distance from a point to a segment
23 | function getSqSegDist(p, p1, p2) {
24 |
25 | var x = p1.x,
26 | y = p1.y,
27 | dx = p2.x - x,
28 | dy = p2.y - y;
29 |
30 | if (dx !== 0 || dy !== 0) {
31 |
32 | var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
33 |
34 | if (t > 1) {
35 | x = p2.x;
36 | y = p2.y;
37 |
38 | } else if (t > 0) {
39 | x += dx * t;
40 | y += dy * t;
41 | }
42 | }
43 |
44 | dx = p.x - x;
45 | dy = p.y - y;
46 |
47 | return dx * dx + dy * dy;
48 | }
49 | // rest of the code doesn't care about point format
50 |
51 | // basic distance-based simplification
52 | function simplifyRadialDist(points, sqTolerance) {
53 |
54 | var prevPoint = points[0],
55 | newPoints = [prevPoint],
56 | point;
57 |
58 | for (var i = 1, len = points.length; i < len; i++) {
59 | point = points[i];
60 |
61 | if (point.marked || getSqDist(point, prevPoint) > sqTolerance) {
62 | newPoints.push(point);
63 | prevPoint = point;
64 | }
65 | }
66 |
67 | if (prevPoint !== point) newPoints.push(point);
68 |
69 | return newPoints;
70 | }
71 |
72 | function simplifyDPStep(points, first, last, sqTolerance, simplified) {
73 | var maxSqDist = sqTolerance;
74 | var index = -1;
75 | var marked = false;
76 | for (var i = first + 1; i < last; i++) {
77 | var sqDist = getSqSegDist(points[i], points[first], points[last]);
78 |
79 | if (sqDist > maxSqDist) {
80 | index = i;
81 | maxSqDist = sqDist;
82 | }
83 | /*if(points[i].marked && maxSqDist <= sqTolerance){
84 | index = i;
85 | marked = true;
86 | }*/
87 | }
88 |
89 | /*if(!points[index] && maxSqDist > sqTolerance){
90 | console.log('shit shit shit');
91 | }*/
92 |
93 | if (maxSqDist > sqTolerance || marked) {
94 | if (index - first > 1) simplifyDPStep(points, first, index, sqTolerance, simplified);
95 | simplified.push(points[index]);
96 | if (last - index > 1) simplifyDPStep(points, index, last, sqTolerance, simplified);
97 | }
98 | }
99 |
100 | // simplification using Ramer-Douglas-Peucker algorithm
101 | function simplifyDouglasPeucker(points, sqTolerance) {
102 | var last = points.length - 1;
103 |
104 | var simplified = [points[0]];
105 | simplifyDPStep(points, 0, last, sqTolerance, simplified);
106 | simplified.push(points[last]);
107 |
108 | return simplified;
109 | }
110 |
111 | // both algorithms combined for awesome performance
112 | function simplify(points, tolerance, highestQuality) {
113 |
114 | if (points.length <= 2) return points;
115 |
116 | var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
117 |
118 | points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
119 | points = simplifyDouglasPeucker(points, sqTolerance);
120 |
121 | return points;
122 | }
123 |
124 | window.simplify = simplify;
125 |
126 | })();
--------------------------------------------------------------------------------
/minkowski thread.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include "minkowski.h"
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #undef min
14 | #undef max
15 |
16 | typedef boost::polygon::point_data point;
17 | typedef boost::polygon::polygon_set_data polygon_set;
18 | typedef boost::polygon::polygon_with_holes_data polygon;
19 | typedef std::pair edge;
20 | using namespace boost::polygon::operators;
21 |
22 | void convolve_two_segments(std::vector& figure, const edge& a, const edge& b) {
23 | using namespace boost::polygon;
24 | figure.clear();
25 | figure.push_back(point(a.first));
26 | figure.push_back(point(a.first));
27 | figure.push_back(point(a.second));
28 | figure.push_back(point(a.second));
29 | convolve(figure[0], b.second);
30 | convolve(figure[1], b.first);
31 | convolve(figure[2], b.first);
32 | convolve(figure[3], b.second);
33 | }
34 |
35 | template
36 | void convolve_two_point_sequences(polygon_set& result, itrT1 ab, itrT1 ae, itrT2 bb, itrT2 be) {
37 | using namespace boost::polygon;
38 | if(ab == ae || bb == be)
39 | return;
40 | point first_a = *ab;
41 | point prev_a = *ab;
42 | std::vector vec;
43 | polygon poly;
44 | ++ab;
45 | for( ; ab != ae; ++ab) {
46 | point first_b = *bb;
47 | point prev_b = *bb;
48 | itrT2 tmpb = bb;
49 | ++tmpb;
50 | for( ; tmpb != be; ++tmpb) {
51 | convolve_two_segments(vec, std::make_pair(prev_b, *tmpb), std::make_pair(prev_a, *ab));
52 | set_points(poly, vec.begin(), vec.end());
53 | result.insert(poly);
54 | prev_b = *tmpb;
55 | }
56 | prev_a = *ab;
57 | }
58 | }
59 |
60 | template
61 | void convolve_point_sequence_with_polygons(polygon_set& result, itrT b, itrT e, const std::vector& polygons) {
62 | using namespace boost::polygon;
63 | for(std::size_t i = 0; i < polygons.size(); ++i) {
64 | convolve_two_point_sequences(result, b, e, begin_points(polygons[i]), end_points(polygons[i]));
65 | for(polygon_with_holes_traits::iterator_holes_type itrh = begin_holes(polygons[i]);
66 | itrh != end_holes(polygons[i]); ++itrh) {
67 | convolve_two_point_sequences(result, b, e, begin_points(*itrh), end_points(*itrh));
68 | }
69 | }
70 | }
71 |
72 | void convolve_two_polygon_sets(polygon_set& result, const polygon_set& a, const polygon_set& b) {
73 | using namespace boost::polygon;
74 | result.clear();
75 | std::vector a_polygons;
76 | std::vector b_polygons;
77 | a.get(a_polygons);
78 | b.get(b_polygons);
79 | for(std::size_t ai = 0; ai < a_polygons.size(); ++ai) {
80 | convolve_point_sequence_with_polygons(result, begin_points(a_polygons[ai]),
81 | end_points(a_polygons[ai]), b_polygons);
82 | for(polygon_with_holes_traits::iterator_holes_type itrh = begin_holes(a_polygons[ai]);
83 | itrh != end_holes(a_polygons[ai]); ++itrh) {
84 | convolve_point_sequence_with_polygons(result, begin_points(*itrh),
85 | end_points(*itrh), b_polygons);
86 | }
87 | for(std::size_t bi = 0; bi < b_polygons.size(); ++bi) {
88 | polygon tmp_poly = a_polygons[ai];
89 | result.insert(convolve(tmp_poly, *(begin_points(b_polygons[bi]))));
90 | tmp_poly = b_polygons[bi];
91 | result.insert(convolve(tmp_poly, *(begin_points(a_polygons[ai]))));
92 | }
93 | }
94 | }
95 |
96 | class thread_pool
97 | {
98 | private:
99 | boost::asio::io_service io_service_;
100 | boost::asio::io_service::work work_;
101 | boost::thread_group threads_;
102 | std::size_t available_;
103 | boost::mutex mutex_;
104 | public:
105 |
106 | /// @brief Constructor.
107 | thread_pool( std::size_t pool_size )
108 | : work_( io_service_ ),
109 | available_( pool_size )
110 | {
111 | for ( std::size_t i = 0; i < pool_size; ++i )
112 | {
113 | threads_.create_thread( boost::bind( &boost::asio::io_service::run,
114 | &io_service_ ) );
115 | }
116 | }
117 |
118 | void join(){
119 | try
120 | {
121 | threads_.join_all();
122 | }
123 | catch ( const std::exception& ) {}
124 | }
125 |
126 | /// @brief Destructor.
127 | ~thread_pool()
128 | {
129 | // Force all threads to return from io_service::run().
130 | io_service_.stop();
131 |
132 | // Suppress all exceptions.
133 | try
134 | {
135 | threads_.join_all();
136 | }
137 | catch ( const std::exception& ) {}
138 | }
139 |
140 | /// @brief Adds a task to the thread pool if a thread is currently available.
141 | template < typename Task >
142 | void run_task( Task task )
143 | {
144 | boost::unique_lock< boost::mutex > lock( mutex_ );
145 |
146 | // If no threads are available, then return.
147 | if ( 0 == available_ ) return;
148 |
149 | // Decrement count, indicating thread is no longer available.
150 | --available_;
151 |
152 | // Post a wrapped task into the queue.
153 | io_service_.post( boost::bind( &thread_pool::wrap_task, this,
154 | boost::function< void() >( task ) ) );
155 | }
156 |
157 | private:
158 | /// @brief Wrap a task so that the available count can be increased once
159 | /// the user provided task has completed.
160 | void wrap_task( boost::function< void() > task )
161 | {
162 | // Run the user supplied task.
163 | try
164 | {
165 | task();
166 | }
167 | // Suppress all exceptions.
168 | catch ( const std::exception& ) {}
169 |
170 | // Task has finished, so increment count of available threads.
171 | boost::unique_lock< boost::mutex > lock( mutex_ );
172 | ++available_;
173 | }
174 | };
175 |
176 | double inputscale;
177 |
178 | using v8::Local;
179 | using v8::Array;
180 | using v8::Isolate;
181 | using v8::String;
182 | using v8::Handle;
183 | using v8::Object;
184 | using v8::Value;
185 |
186 | using namespace boost::polygon;
187 |
188 | class Worker{
189 | public:
190 | Handle Alist;
191 | Handle B;
192 | Local all_results;
193 | Isolate* isolate;
194 |
195 | void Do(int index){
196 |
197 | Handle A = Handle::Cast(Alist->Get(index));
198 |
199 | polygon_set a, b, c;
200 | std::vector polys;
201 | std::vector pts;
202 |
203 | // get maximum bounds for scaling factor
204 | unsigned int len = A->Length();
205 | double Amaxx = 0;
206 | double Aminx = 0;
207 | double Amaxy = 0;
208 | double Aminy = 0;
209 | for (unsigned int i = 0; i < len; i++) {
210 | Local