flatten-js
Version:
Javascript library for 2d geometry
1 lines • 7.35 kB
JSON
{"dependencies":[{"name":"C:\\Users\\alexbol\\WebstormProjects\\flatten-js\\package.json","includedInParent":true,"mtime":1520238055570}],"generated":{"js":"/**\r\n * Created by Alex Bol on 3/7/2017.\r\n */\n\"use strict\";\n\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nmodule.exports = function (Flatten) {\n /**\r\n * Class Box represent bounding box of the shape\r\n * @type {Box}\r\n */\n Flatten.Box = function () {\n /**\r\n *\r\n * @param {number} xmin - minimal x coordinate\r\n * @param {number} ymin - minimal y coordinate\r\n * @param {number} xmax - maximal x coordinate\r\n * @param {number} ymax - maximal y coordinate\r\n */\n function Box() {\n var xmin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;\n var ymin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;\n var xmax = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;\n var ymax = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;\n\n _classCallCheck(this, Box);\n\n /**\r\n * Minimal x coordinate\r\n * @type {number}\r\n */\n this.xmin = xmin;\n /**\r\n * Minimal y coordinate\r\n * @type {number}\r\n */\n this.ymin = ymin;\n /**\r\n * Maximal x coordinate\r\n * @type {number}\r\n */\n this.xmax = xmax;\n /**\r\n * Maximal y coordinate\r\n * @type {number}\r\n */\n this.ymax = ymax;\n }\n\n /**\r\n * Clones and returns new instance of box\r\n * @returns {Box}\r\n */\n\n\n _createClass(Box, [{\n key: \"clone\",\n value: function clone() {\n return new Box(this.xmin, this.ymin, this.xmax, this.ymax);\n }\n\n /**\r\n * Property low need for interval tree interface\r\n * @returns {Point}\r\n */\n\n }, {\n key: \"notIntersect\",\n\n\n /**\r\n * Returns true if not intersected with other box\r\n * @param {Box} other_box - other box to test\r\n * @returns {boolean}\r\n */\n value: function notIntersect(other_box) {\n return this.xmax < other_box.xmin || this.xmin > other_box.xmax || this.ymax < other_box.ymin || this.ymin > other_box.ymax;\n }\n\n /**\r\n * Returns true if intersected with other box\r\n * @param {Box} other_box - Query box\r\n * @returns {boolean}\r\n */\n\n }, {\n key: \"intersect\",\n value: function intersect(other_box) {\n return !this.notIntersect(other_box);\n }\n\n /**\r\n * Returns new box merged with other box\r\n * @param {Box} other_box - Other box to merge with\r\n * @returns {Box}\r\n */\n\n }, {\n key: \"merge\",\n value: function merge(other_box) {\n return new Box(this.xmin === undefined ? other_box.xmin : Math.min(this.xmin, other_box.xmin), this.ymin === undefined ? other_box.ymin : Math.min(this.ymin, other_box.ymin), this.xmax === undefined ? other_box.xmax : Math.max(this.xmax, other_box.xmax), this.ymax === undefined ? other_box.ymax : Math.max(this.ymax, other_box.ymax));\n }\n\n /**\r\n * Defines predicate \"less than\" between two boxes. Need for interval index\r\n * @param {Box} other_box - other box\r\n * @returns {boolean} - true if this box less than other box, false otherwise\r\n */\n\n }, {\n key: \"less_than\",\n value: function less_than(other_box) {\n if (this.low.lessThan(other_box.low)) return true;\n if (this.low.equalTo(other_box.low) && this.high.lessThan(other_box.high)) return true;\n return false;\n }\n\n /**\r\n * Returns true if this box is equal to other box, false otherwise\r\n * @param {Box} other_box - query box\r\n * @returns {boolean}\r\n */\n\n }, {\n key: \"equal_to\",\n value: function equal_to(other_box) {\n return this.low.equalTo(other_box.low) && this.high.equalTo(other_box.high);\n }\n }, {\n key: \"output\",\n value: function output() {\n return this.clone();\n }\n }, {\n key: \"maximal_val\",\n value: function maximal_val(box1, box2) {\n // return pt1.lessThan(pt2) ? pt2.clone() : pt1.clone();\n return box1.merge(box2);\n }\n }, {\n key: \"val_less_than\",\n value: function val_less_than(pt1, pt2) {\n return pt1.lessThan(pt2);\n }\n\n /**\r\n * Set new values to the box object\r\n * @param {number} xmin - miminal x coordinate\r\n * @param {number} ymin - minimal y coordinate\r\n * @param {number} xmax - maximal x coordinate\r\n * @param {number} ymax - maximal y coordinate\r\n */\n\n }, {\n key: \"set\",\n value: function set(xmin, ymin, xmax, ymax) {\n this.xmin = xmin;\n this.ymin = ymin;\n this.xmax = xmax;\n this.ymax = ymax;\n }\n }, {\n key: \"low\",\n get: function get() {\n return new Flatten.Point(this.xmin, this.ymin);\n }\n\n /**\r\n * Property high need for interval tree interface\r\n * @returns {Point}\r\n */\n\n }, {\n key: \"high\",\n get: function get() {\n return new Flatten.Point(this.xmax, this.ymax);\n }\n\n /**\r\n * Property max returns the box itself !\r\n * @returns {Box}\r\n */\n\n }, {\n key: \"max\",\n get: function get() {\n return this.clone();\n }\n }]);\n\n return Box;\n }();\n};"},"hash":"74a93db1ed4f1f0f9e13bdc5f0bb7a47","cacheData":{"env":{}}}