Skip to content

Commit

Permalink
Fixed issue with Illustrator import
Browse files Browse the repository at this point in the history
  • Loading branch information
neauoire committed Nov 22, 2018
1 parent 36cc25e commit ba05da9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
32 changes: 24 additions & 8 deletions desktop/sources/scripts/generator.js
Expand Up @@ -47,24 +47,22 @@ function Generator (layer, style) {
}

if (type == 'line') {
html += `L${vertex.x},${vertex.y} `
html += this._line(vertex)
} else if (type == 'arc_c') {
let clock = mirror > 0 ? '0,0' : '0,1'
html += next ? `A${Math.abs(next.x - vertex.x)},${Math.abs(next.y - vertex.y)} 0 ${clock} ${next.x},${next.y} ` : ''
html += this._arc(vertex, next, clock)
} else if (type == 'arc_r') {
let clock = mirror > 0 ? '0,1' : '0,0'
html += next ? `A${Math.abs(next.x - vertex.x)},${Math.abs(next.y - vertex.y)} 0 ${clock} ${next.x},${next.y} ` : ''
html += this._arc(vertex, next, clock)
} else if (type == 'arc_c_full') {
let clock = mirror > 0 ? '1,0' : '1,1'
html += next ? `A${Math.abs(next.x - vertex.x)},${Math.abs(next.y - vertex.y)} 0 ${clock} ${next.x},${next.y} ` : ''
html += this._arc(vertex, next, clock)
} else if (type == 'arc_r_full') {
let clock = mirror > 0 ? '1,1' : '1,0'
html += next ? `A${Math.abs(next.x - vertex.x)},${Math.abs(next.y - vertex.y)} 0 ${clock} ${next.x},${next.y} ` : ''
html += this._arc(vertex, next, clock)
} else if (type == 'bezier') {
html += next && after_next ? `Q${next.x},${next.y} ${after_next.x},${after_next.y} ` : ''
html += this._bezier(next, after_next)
skip = 1
} else {
console.warn(`unknown type:${type}`)
}
}

Expand All @@ -75,6 +73,24 @@ function Generator (layer, style) {
return html
}

this._line = function (a) {
return `L${a.x},${a.y} `
}

this._arc = function (a, b, c) {
if (!a || !b || !c) { return '' }

const offset = { x: b.x - a.x, y: b.y - a.y }

if (offset.x === 0 || offset.y === 0) { return this._line(b) }
return `A${Math.abs(b.x - a.x)},${Math.abs(b.y - a.y)} 0 ${c} ${b.x},${b.y} `
}

this._bezier = function (a, b) {
if (!a || !b) { return '' }
return `Q${a.x},${a.y} ${b.x},${b.y} `
}

this.convert = function (layer, mirror, angle) {
let s = ''
let prev = null
Expand Down
17 changes: 10 additions & 7 deletions desktop/sources/scripts/tool.js
Expand Up @@ -142,17 +142,20 @@ DOTGRID.Tool = function () {
return null
}

this.add_segment = function (type, vertices) {
let append_target = this.can_append({ type: type, vertices: vertices })
if (append_target) {
this.layer()[append_target].vertices = this.layer()[append_target].vertices.concat(vertices)
} else {
this.layer().push({ type: type, vertices: vertices })
}
}

this.cast = function (type) {
if (!this.layer()) { this.layers[this.index] = [] }
if (!this.can_cast(type)) { console.warn('Cannot cast'); return }

let append_target = this.can_append({ type: type, vertices: this.vertices.slice() })

if (append_target) {
this.layers[this.index][append_target].vertices = this.layers[this.index][append_target].vertices.concat(this.vertices.slice())
} else {
this.layer().push({ type: type, vertices: this.vertices.slice() })
}
this.add_segment(type, this.vertices.slice())

DOTGRID.history.push(this.layers)

Expand Down

0 comments on commit ba05da9

Please sign in to comment.