UNPKG

roughjs-es5

Version:

Create graphics using HTML Canvas or SVG with a hand-drawn, sketchy, appearance.

91 lines (82 loc) 3.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RoughHachureIterator = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _segment = require("./segment"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var RoughHachureIterator = exports.RoughHachureIterator = function () { function RoughHachureIterator(top, bottom, left, right, gap, sinAngle, cosAngle, tanAngle) { _classCallCheck(this, RoughHachureIterator); this.top = top; this.bottom = bottom; this.left = left; this.right = right; this.gap = gap; this.sinAngle = sinAngle; this.tanAngle = tanAngle; if (Math.abs(sinAngle) < 0.0001) { this.pos = left + gap; } else if (Math.abs(sinAngle) > 0.9999) { this.pos = top + gap; } else { this.deltaX = (bottom - top) * Math.abs(tanAngle); this.pos = left - Math.abs(this.deltaX); this.hGap = Math.abs(gap / cosAngle); this.sLeft = new _segment.RoughSegment(left, bottom, left, top); this.sRight = new _segment.RoughSegment(right, bottom, right, top); } } _createClass(RoughHachureIterator, [{ key: "getNextLine", value: function getNextLine() { if (Math.abs(this.sinAngle) < 0.0001) { if (this.pos < this.right) { var line = [this.pos, this.top, this.pos, this.bottom]; this.pos += this.gap; return line; } } else if (Math.abs(this.sinAngle) > 0.9999) { if (this.pos < this.bottom) { var _line = [this.left, this.pos, this.right, this.pos]; this.pos += this.gap; return _line; } } else { var xLower = this.pos - this.deltaX / 2; var xUpper = this.pos + this.deltaX / 2; var yLower = this.bottom; var yUpper = this.top; if (this.pos < this.right + this.deltaX) { while (xLower < this.left && xUpper < this.left || xLower > this.right && xUpper > this.right) { this.pos += this.hGap; xLower = this.pos - this.deltaX / 2; xUpper = this.pos + this.deltaX / 2; if (this.pos > this.right + this.deltaX) { return null; } } var s = new _segment.RoughSegment(xLower, yLower, xUpper, yUpper); if (s.compare(this.sLeft) == (0, _segment.RoughSegmentRelation)().INTERSECTS) { xLower = s.xi; yLower = s.yi; } if (s.compare(this.sRight) == (0, _segment.RoughSegmentRelation)().INTERSECTS) { xUpper = s.xi; yUpper = s.yi; } if (this.tanAngle > 0) { xLower = this.right - (xLower - this.left); xUpper = this.right - (xUpper - this.left); } var _line2 = [xLower, yLower, xUpper, yUpper]; this.pos += this.hGap; return _line2; } } return null; } }]); return RoughHachureIterator; }();