Add ellipse shape

This commit is contained in:
Cauli Tomaz
2019-07-29 18:44:31 +02:00
parent 7d153fb3f1
commit 2eafa354bb
4 changed files with 19 additions and 1 deletions

View File

@@ -70,6 +70,10 @@ function Library (ronin) {
return { cx, cy, r }
}
this.ellipse = (cx, cy, rx, ry) => { // Returns a ellipse shape.
return { cx, cy, rx, ry }
}
this.line = (ax, ay, bx, by) => { // Returns a line shape.
return { a: this.pos(ax, ay), b: this.pos(bx, by) }
}

View File

@@ -90,6 +90,8 @@ function Surface (ronin) {
}
if (isCircle(shape)) {
this.traceCircle(shape, context)
} else if (isEllipse(shape)) {
this.traceEllipse(shape, context)
} else if (isText(shape)) {
this.traceText(shape, context)
} else if (isSvg(shape)) {
@@ -122,6 +124,10 @@ function Surface (ronin) {
context.arc(circle.cx, circle.cy, circle.r, 0, 2 * Math.PI)
}
this.traceEllipse = function (ellipse, context) {
context.ellipse(ellipse.cx, ellipse.cy, ellipse.rx, ellipse.ry, 0, 2 * Math.PI, false)
}
this.traceText = function (text, context) {
}
@@ -287,6 +293,9 @@ function Surface (ronin) {
function isCircle (shape) {
return !isNaN(shape.cx) && !isNaN(shape.cy) && !isNaN(shape.r)
}
function isEllipse (shape) {
return !isNaN(shape.cx) && !isNaN(shape.cy) && !isNaN(shape.rx) && !isNaN(shape.ry)
}
function isPos (shape) {
return !isNaN(shape.x) && !isNaN(shape.y)
}