Re-added rotation guides

This commit is contained in:
Devine Lu Linvega 2018-05-28 19:24:19 +12:00
parent c41566a75e
commit de0d67d646
4 changed files with 33 additions and 10 deletions

View File

@ -1,8 +1,9 @@
function Generator(layer)
function Generator(layer,style)
{
this.layer = layer;
this.style = style;
function operate(layer,offset,scale,mirror = 0)
function operate(layer,offset,scale,mirror = 0,angle = 0)
{
var l = copy(layer)
@ -11,9 +12,17 @@ function Generator(layer)
for(k2 in seg.vertices){
if(mirror == 1){ seg.vertices[k2].x = (dotgrid.tool.settings.size.width) - seg.vertices[k2].x }
if(mirror == 2){ seg.vertices[k2].y = (dotgrid.tool.settings.size.height) - seg.vertices[k2].y }
// Offset
seg.vertices[k2].x += offset.x
seg.vertices[k2].x *= scale
seg.vertices[k2].y += offset.y
// Rotate
var center = {x:(dotgrid.tool.settings.size.width/2)+offset.x,y:(dotgrid.tool.settings.size.height/2)+offset.y}
seg.vertices[k2] = rotate_point(seg.vertices[k2],center,angle)
// Scale
seg.vertices[k2].x *= scale
seg.vertices[k2].y *= scale
}
}
@ -65,7 +74,7 @@ function Generator(layer)
return html
}
this.convert = function(layer,mirror)
this.convert = function(layer,mirror,angle)
{
var s = ""
var prev = null
@ -78,16 +87,28 @@ function Generator(layer)
return s;
}
this.toString = function(offset = {x:0,y:0}, scale = 1, mirror = dotgrid.tool.style().mirror_style)
this.toString = function(offset = {x:0,y:0}, scale = 1, mirror = this.style.mirror_style ? this.style.mirror_style : 0)
{
var s = this.convert(operate(this.layer,offset,scale))
if(mirror == 1 || mirror == 2){
s += this.convert(operate(this.layer,offset,scale,mirror),mirror)
}
if(mirror == 3){
s += this.convert(operate(this.layer,offset,scale,mirror,120),mirror)
s += this.convert(operate(this.layer,offset,scale,mirror,240),mirror)
}
if(mirror == 4){
s += this.convert(operate(this.layer,offset,scale,mirror,72),mirror)
s += this.convert(operate(this.layer,offset,scale,mirror,144),mirror)
s += this.convert(operate(this.layer,offset,scale,mirror,216),mirror)
s += this.convert(operate(this.layer,offset,scale,mirror,288),mirror)
}
return s
}
function copy(data){ return data ? JSON.parse(JSON.stringify(data)) : []; }
function rotate_point(pointX, pointY, originX, originY, angle){ angle = angle * Math.PI / 180.0; return { x: (Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX).toFixed(1), y: (Math.sin(angle) * (pointX-originX) + Math.cos(angle) * (pointY-originY) + originY).toFixed(1) }; }
function rotate_point(point, origin, angle){ angle = angle * Math.PI / 180.0; return { x: (Math.cos(angle) * (point.x-origin.x) - Math.sin(angle) * (point.y-origin.y) + origin.x).toFixed(1), y: (Math.sin(angle) * (point.x-origin.x) + Math.cos(angle) * (point.y-origin.y) + origin.y).toFixed(1) }; }
}

View File

@ -21,11 +21,11 @@ function Guide()
this.clear();
if(dotgrid.tool.index == 2){ this.draw_markers() ; this.draw_vertices() }
this.draw_path(new Generator(dotgrid.tool.layers[2]).toString({x:15,y:15},scale),dotgrid.tool.styles[2])
this.draw_path(new Generator(dotgrid.tool.layers[2],dotgrid.tool.styles[2]).toString({x:15,y:15},scale),dotgrid.tool.styles[2])
if(dotgrid.tool.index == 1){ this.draw_markers() ; this.draw_vertices() }
this.draw_path(new Generator(dotgrid.tool.layers[1]).toString({x:15,y:15},scale),dotgrid.tool.styles[1])
this.draw_path(new Generator(dotgrid.tool.layers[1],dotgrid.tool.styles[1]).toString({x:15,y:15},scale),dotgrid.tool.styles[1])
if(dotgrid.tool.index == 0){ this.draw_markers(); this.draw_vertices() }
this.draw_path(new Generator(dotgrid.tool.layers[0]).toString({x:15,y:15},scale),dotgrid.tool.styles[0])
this.draw_path(new Generator(dotgrid.tool.layers[0],dotgrid.tool.styles[0]).toString({x:15,y:15},scale),dotgrid.tool.styles[0])
this.draw_handles()
this.draw_translation();

View File

@ -65,6 +65,8 @@ function Interface()
if(dotgrid.tool.style().mirror_style == 0){ document.getElementById("mirror_path").setAttribute("d","M60,60 L60,60 L120,120 M180,180 L180,180 L240,240 M210,90 L210,90 L180,120 M120,180 L120,180 L90,210") }
else if(dotgrid.tool.style().mirror_style == 1){ document.getElementById("mirror_path").setAttribute("d","M60,60 L240,240 M180,120 L210,90 M120,180 L90,210") }
else if(dotgrid.tool.style().mirror_style == 2){ document.getElementById("mirror_path").setAttribute("d","M210,90 L210,90 L90,210 M60,60 L60,60 L120,120 M180,180 L180,180 L240,240") }
else if(dotgrid.tool.style().mirror_style == 3){ document.getElementById("mirror_path").setAttribute("d","M60,60 L60,60 L120,120 L120,120 L180,120 M120,150 L120,150 L180,150 M120,180 L120,180 L180,180 L180,180 L240,240 ") }
else if(dotgrid.tool.style().mirror_style == 4){ document.getElementById("mirror_path").setAttribute("d","M120,120 L120,120 L120,120 L180,120 M120,150 L120,150 L180,150 M120,180 L120,180 L180,180 L180,180 L180,180 L240,240 M120,210 L120,210 L180,210 M120,90 L120,90 L180,90 M60,60 L60,60 L120,120 ") }
this.prev_operation = dotgrid.cursor.operation;
}

View File

@ -241,7 +241,7 @@ function Tool()
this.toggle_mirror = function()
{
this.style().mirror_style = this.style().mirror_style > 1 ? 0 : this.style().mirror_style+1;
this.style().mirror_style = this.style().mirror_style > 3 ? 0 : this.style().mirror_style+1;
dotgrid.guide.refresh();
dotgrid.interface.refresh(true);