Skip to content

Commit f367976

Browse files
committed
Use parse-rect module for viewports
1 parent 0f5fcfc commit f367976

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

index.js

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const flatten = require('flatten-vertex-data')
1313
const ie = require('is-iexplorer')
1414
const {float32, fract32} = require('to-float32')
1515
const arrayRange = require('array-range')
16+
const parseRect = require('parse-rect')
1617

1718
module.exports = Scatter
1819

@@ -639,37 +640,10 @@ function Scatter (regl, options) {
639640
},
640641

641642
viewport: vp => {
642-
let viewport
643-
644-
if (Array.isArray(vp)) {
645-
viewport = {
646-
x: vp[0],
647-
y: vp[1],
648-
width: vp[2] - vp[0],
649-
height: vp[3] - vp[1]
650-
}
651-
}
652-
else if (vp) {
653-
viewport = {
654-
x: vp.x || vp.left || 0,
655-
y: vp.y || vp.top || 0
656-
}
657-
658-
if (vp.right) viewport.width = vp.right - viewport.x
659-
else viewport.width = vp.w || vp.width || 0
660-
661-
if (vp.bottom) viewport.height = vp.bottom - viewport.y
662-
else viewport.height = vp.h || vp.height || 0
663-
}
664-
else {
665-
viewport = {
666-
x: 0, y: 0,
667-
width: gl.drawingBufferWidth,
668-
height: gl.drawingBufferHeight
669-
}
670-
}
671-
672-
return viewport
643+
return parseRect(vp || [
644+
gl.drawingBufferWidth,
645+
gl.drawingBufferHeight
646+
])
673647
}
674648
}])
675649

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"glslify": "^6.1.0",
3939
"is-iexplorer": "^1.0.0",
4040
"object-assign": "^4.1.1",
41+
"parse-rect": "^1.1.0",
4142
"pick-by-alias": "^1.0.0",
4243
"snap-points-2d": "^3.2.0",
4344
"to-float32": "^1.0.0",

0 commit comments

Comments
 (0)