aboutsummaryrefslogtreecommitdiffstats
path: root/src/types/PathArray.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-05-19 20:06:29 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-05-19 20:06:29 +1000
commit4ea53725a9021a136f6d81122dd78dc97a3e7da0 (patch)
tree7cd4b2aaa2c1e834aa61a669066f87d9746e7ef6 /src/types/PathArray.js
parent47cffd9d5d9628c1729be291ee3a2f9b5651bd2c (diff)
downloadsvg.js-4ea53725a9021a136f6d81122dd78dc97a3e7da0.tar.gz
svg.js-4ea53725a9021a136f6d81122dd78dc97a3e7da0.zip
sorted method names
Diffstat (limited to 'src/types/PathArray.js')
-rw-r--r--src/types/PathArray.js107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/types/PathArray.js b/src/types/PathArray.js
index d9c1eb2..b7c3c33 100644
--- a/src/types/PathArray.js
+++ b/src/types/PathArray.js
@@ -125,9 +125,10 @@ for (var i = 0, il = mlhvqtcsaz.length; i < il; ++i) {
}
export default class PathArray extends SVGArray {
- // Convert array to string
- toString () {
- return arrayToString(this)
+ // Get bounding box of path
+ bbox () {
+ parser().path.setAttribute('d', this.toString())
+ return new Box(parser.nodes.path.getBBox())
}
// Move path string
@@ -171,52 +172,6 @@ export default class PathArray extends SVGArray {
return this
}
- // Resize path string
- size (width, height) {
- // get bounding box of current situation
- var box = this.bbox()
- var i, l
-
- // If the box width or height is 0 then we ignore
- // transformations on the respective axis
- box.width = box.width === 0 ? 1 : box.width
- box.height = box.height === 0 ? 1 : box.height
-
- // recalculate position of all points according to new size
- for (i = this.length - 1; i >= 0; i--) {
- l = this[i][0]
-
- if (l === 'M' || l === 'L' || l === 'T') {
- this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x
- this[i][2] = ((this[i][2] - box.y) * height) / box.height + box.y
- } else if (l === 'H') {
- this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x
- } else if (l === 'V') {
- this[i][1] = ((this[i][1] - box.y) * height) / box.height + box.y
- } else if (l === 'C' || l === 'S' || l === 'Q') {
- this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x
- this[i][2] = ((this[i][2] - box.y) * height) / box.height + box.y
- this[i][3] = ((this[i][3] - box.x) * width) / box.width + box.x
- this[i][4] = ((this[i][4] - box.y) * height) / box.height + box.y
-
- if (l === 'C') {
- this[i][5] = ((this[i][5] - box.x) * width) / box.width + box.x
- this[i][6] = ((this[i][6] - box.y) * height) / box.height + box.y
- }
- } else if (l === 'A') {
- // resize radii
- this[i][1] = (this[i][1] * width) / box.width
- this[i][2] = (this[i][2] * height) / box.height
-
- // move position values
- this[i][6] = ((this[i][6] - box.x) * width) / box.width + box.x
- this[i][7] = ((this[i][7] - box.y) * height) / box.height + box.y
- }
- }
-
- return this
- }
-
// Absolutize and parse path to array
parse (array = [ 'M', 0, 0 ]) {
// prepare for parsing
@@ -264,9 +219,55 @@ export default class PathArray extends SVGArray {
return result
}
- // Get bounding box of path
- bbox () {
- parser().path.setAttribute('d', this.toString())
- return new Box(parser.nodes.path.getBBox())
+ // Resize path string
+ size (width, height) {
+ // get bounding box of current situation
+ var box = this.bbox()
+ var i, l
+
+ // If the box width or height is 0 then we ignore
+ // transformations on the respective axis
+ box.width = box.width === 0 ? 1 : box.width
+ box.height = box.height === 0 ? 1 : box.height
+
+ // recalculate position of all points according to new size
+ for (i = this.length - 1; i >= 0; i--) {
+ l = this[i][0]
+
+ if (l === 'M' || l === 'L' || l === 'T') {
+ this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x
+ this[i][2] = ((this[i][2] - box.y) * height) / box.height + box.y
+ } else if (l === 'H') {
+ this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x
+ } else if (l === 'V') {
+ this[i][1] = ((this[i][1] - box.y) * height) / box.height + box.y
+ } else if (l === 'C' || l === 'S' || l === 'Q') {
+ this[i][1] = ((this[i][1] - box.x) * width) / box.width + box.x
+ this[i][2] = ((this[i][2] - box.y) * height) / box.height + box.y
+ this[i][3] = ((this[i][3] - box.x) * width) / box.width + box.x
+ this[i][4] = ((this[i][4] - box.y) * height) / box.height + box.y
+
+ if (l === 'C') {
+ this[i][5] = ((this[i][5] - box.x) * width) / box.width + box.x
+ this[i][6] = ((this[i][6] - box.y) * height) / box.height + box.y
+ }
+ } else if (l === 'A') {
+ // resize radii
+ this[i][1] = (this[i][1] * width) / box.width
+ this[i][2] = (this[i][2] * height) / box.height
+
+ // move position values
+ this[i][6] = ((this[i][6] - box.x) * width) / box.width + box.x
+ this[i][7] = ((this[i][7] - box.y) * height) / box.height + box.y
+ }
+ }
+
+ return this
}
+
+ // Convert array to string
+ toString () {
+ return arrayToString(this)
+ }
+
}