-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.js
More file actions
44 lines (39 loc) · 1.24 KB
/
utility.js
File metadata and controls
44 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Converts Paths to SVG path string
// and scales down the coordinates
function paths2string (paths, scale) {
var svgpath = "", i, j;
if (!scale) scale = 1;
for(i = 0; i < paths.length; i++) {
for(j = 0; j < paths[i].length; j++){
if (!j) svgpath += "M";
else svgpath += "L";
svgpath += (paths[i][j].X / scale) + ", " + (paths[i][j].Y / scale);
}
svgpath += "Z";
}
if (svgpath=="") svgpath = "M0,0";
return svgpath;
}
function get2DArray(size) {
size = size > 0 ? size : 0;
var arr = [];
while(size--) { arr.push([]); }
return arr;
}
function get_circle_path(row_1, col_1, row_2, col_2, cellsize) {
var radius_x = cellsize*(Math.abs( saved_row - curr_row )/2+0.5);
var radius_y = cellsize*(Math.abs( saved_col - curr_col )/2+0.5);
var center_x = cellsize*((saved_row + curr_row)/2+0.5);
var center_y = cellsize*((saved_col + curr_col)/2+0.5);
var count = 4*Math.min(radius_x, radius_y);
var slice = 2 * Math.PI / count;
var circle_path = new ClipperLib.Path();
for( var ii=0; ii<count; ii++)
{
var angle = ii*slice;
var x_coord = radius_x * Math.cos(angle)+center_x;
var y_coord = radius_y * Math.sin(angle)+center_y;
circle_path.push({X:x_coord,Y:y_coord});
}
return circle_path;
}