aboutsummaryrefslogtreecommitdiffstats
path: root/src/types/PointArray.js
diff options
context:
space:
mode:
authorSaivan <savian@me.com>2018-11-26 00:17:41 +1300
committerSaivan <savian@me.com>2018-11-26 00:17:41 +1300
commit617aa12304541cf1d80b2bf5567ac633958c38de (patch)
treec1082b4573625f93d18e82e6d5a0c4a40782993f /src/types/PointArray.js
parent599fda2f11c88b2c18d0cd0b57d4adeca20db2eb (diff)
downloadsvg.js-617aa12304541cf1d80b2bf5567ac633958c38de.tar.gz
svg.js-617aa12304541cf1d80b2bf5567ac633958c38de.zip
Reverted some of the lint rules after chatting with fuzzy
This commit reverts some of the rules we added on the linter, it changed a lot of code again... but these won't happen too often. Changes ======= - Modified the linter again
Diffstat (limited to 'src/types/PointArray.js')
-rw-r--r--src/types/PointArray.js102
1 files changed, 34 insertions, 68 deletions
diff --git a/src/types/PointArray.js b/src/types/PointArray.js
index 581b7dc..9e7406d 100644
--- a/src/types/PointArray.js
+++ b/src/types/PointArray.js
@@ -3,97 +3,76 @@ import { extend } from '../utils/adopter.js'
import { subClassArray } from './ArrayPolyfill.js'
import SVGArray from './SVGArray.js'
-const PointArray = subClassArray( 'PointArray', SVGArray )
+const PointArray = subClassArray('PointArray', SVGArray)
export default PointArray
-extend( PointArray, {
+extend(PointArray, {
// Convert array to string
toString () {
-
// convert to a poly point string
- for ( var i = 0, il = this.length, array = []; i < il; i++ ) {
-
- array.push( this[i].join( ',' ) )
-
+ for (var i = 0, il = this.length, array = []; i < il; i++) {
+ array.push(this[i].join(','))
}
- return array.join( ' ' )
-
+ return array.join(' ')
},
// Convert array to line object
toLine () {
-
return {
x1: this[0][0],
y1: this[0][1],
x2: this[1][0],
y2: this[1][1]
}
-
},
// Get morphed array at given position
- at ( pos ) {
-
+ at (pos) {
// make sure a destination is defined
- if ( !this.destination ) return this
+ if (!this.destination) return this
// generate morphed point string
- for ( var i = 0, il = this.length, array = []; i < il; i++ ) {
-
- array.push( [
- this[i][0] + ( this.destination[i][0] - this[i][0] ) * pos,
- this[i][1] + ( this.destination[i][1] - this[i][1] ) * pos
- ] )
-
+ for (var i = 0, il = this.length, array = []; i < il; i++) {
+ array.push([
+ this[i][0] + (this.destination[i][0] - this[i][0]) * pos,
+ this[i][1] + (this.destination[i][1] - this[i][1]) * pos
+ ])
}
- return new PointArray( array )
-
+ return new PointArray(array)
},
// Parse point string and flat array
- parse ( array = [ [ 0, 0 ] ] ) {
-
+ parse (array = [ [ 0, 0 ] ]) {
var points = []
// if it is an array
- if ( array instanceof Array ) {
-
+ if (array instanceof Array) {
// and it is not flat, there is no need to parse it
- if ( array[0] instanceof Array ) {
-
+ if (array[0] instanceof Array) {
return array
-
}
-
} else { // Else, it is considered as a string
-
// parse points
- array = array.trim().split( delimiter ).map( parseFloat )
-
+ array = array.trim().split(delimiter).map(parseFloat)
}
// validate points - https://svgwg.org/svg2-draft/shapes.html#DataTypePoints
// Odd number of coordinates is an error. In such cases, drop the last odd coordinate.
- if ( array.length % 2 !== 0 ) array.pop()
+ if (array.length % 2 !== 0) array.pop()
// wrap points in two-tuples and parse points as floats
- for ( var i = 0, len = array.length; i < len; i = i + 2 ) {
-
- points.push( [ array[i], array[i + 1] ] )
-
+ for (var i = 0, len = array.length; i < len; i = i + 2) {
+ points.push([ array[i], array[i + 1] ])
}
return points
-
},
// Move point string
- move ( x, y ) {
-
+ move (x, y) {
var box = this.bbox()
// get relative offset
@@ -101,54 +80,41 @@ extend( PointArray, {
y -= box.y
// move every point
- if ( !isNaN( x ) && !isNaN( y ) ) {
-
- for ( var i = this.length - 1; i >= 0; i-- ) {
-
+ if (!isNaN(x) && !isNaN(y)) {
+ for (var i = this.length - 1; i >= 0; i--) {
this[i] = [ this[i][0] + x, this[i][1] + y ]
-
}
-
}
return this
-
},
// Resize poly string
- size ( width, height ) {
-
+ size (width, height) {
var i
var box = this.bbox()
// recalculate position of all points according to new size
- for ( i = this.length - 1; i >= 0; i-- ) {
-
- if ( box.width ) this[i][0] = ( ( this[i][0] - box.x ) * width ) / box.width + box.x
- if ( box.height ) this[i][1] = ( ( this[i][1] - box.y ) * height ) / box.height + box.y
-
+ for (i = this.length - 1; i >= 0; i--) {
+ if (box.width) this[i][0] = ((this[i][0] - box.x) * width) / box.width + box.x
+ if (box.height) this[i][1] = ((this[i][1] - box.y) * height) / box.height + box.y
}
return this
-
},
// Get bounding box of points
bbox () {
-
var maxX = -Infinity
var maxY = -Infinity
var minX = Infinity
var minY = Infinity
- this.forEach( function ( el ) {
-
- maxX = Math.max( el[0], maxX )
- maxY = Math.max( el[1], maxY )
- minX = Math.min( el[0], minX )
- minY = Math.min( el[1], minY )
-
- } )
+ this.forEach(function (el) {
+ maxX = Math.max(el[0], maxX)
+ maxY = Math.max(el[1], maxY)
+ minX = Math.min(el[0], minX)
+ minY = Math.min(el[1], minY)
+ })
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }
-
}
-} )
+})