summit/frontend/node_modules/martinez-polygon-clipping/dist/martinez.min.js

9 lines
19 KiB
JavaScript
Raw Normal View History

2025-12-08 16:31:30 +00:00
/**
* martinez v0.7.4
* Martinez polygon clipping algorithm, does boolean operation on polygons (multipolygons, polygons with holes etc): intersection, union, difference, xor
*
* @author Alex Milevski <info@w8r.name>
* @license MIT
* @preserve
*/
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports):typeof define==="function"&&define.amd?define(["exports"],e):(t=t||self,e(t.martinez={}))})(this,function(t){"use strict";function N(t,e){return t>e?1:t<e?-1:0}var d=function t(e,r){if(e===void 0)e=N;if(r===void 0)r=false;this._compare=e;this._root=null;this._size=0;this._noDuplicates=!!r};var e={size:{configurable:true}};d.prototype.rotateLeft=function t(e){var r=e.right;if(r){e.right=r.left;if(r.left){r.left.parent=e}r.parent=e.parent}if(!e.parent){this._root=r}else if(e===e.parent.left){e.parent.left=r}else{e.parent.right=r}if(r){r.left=e}e.parent=r};d.prototype.rotateRight=function t(e){var r=e.left;if(r){e.left=r.right;if(r.right){r.right.parent=e}r.parent=e.parent}if(!e.parent){this._root=r}else if(e===e.parent.left){e.parent.left=r}else{e.parent.right=r}if(r){r.right=e}e.parent=r};d.prototype._splay=function t(e){while(e.parent){var r=e.parent;if(!r.parent){if(r.left===e){this.rotateRight(r)}else{this.rotateLeft(r)}}else if(r.left===e&&r.parent.left===r){this.rotateRight(r.parent);this.rotateRight(r)}else if(r.right===e&&r.parent.right===r){this.rotateLeft(r.parent);this.rotateLeft(r)}else if(r.left===e&&r.parent.right===r){this.rotateRight(r);this.rotateLeft(r)}else{this.rotateLeft(r);this.rotateRight(r)}}};d.prototype.splay=function t(e){var r,i,n,o,f;while(e.parent){r=e.parent;i=r.parent;if(i&&i.parent){n=i.parent;if(n.left===i){n.left=e}else{n.right=e}e.parent=n}else{e.parent=null;this._root=e}o=e.left;f=e.right;if(e===r.left){if(i){if(i.left===r){if(r.right){i.left=r.right;i.left.parent=i}else{i.left=null}r.right=i;i.parent=r}else{if(o){i.right=o;o.parent=i}else{i.right=null}e.left=i;i.parent=e}}if(f){r.left=f;f.parent=r}else{r.left=null}e.right=r;r.parent=e}else{if(i){if(i.right===r){if(r.left){i.right=r.left;i.right.parent=i}else{i.right=null}r.left=i;i.parent=r}else{if(f){i.left=f;f.parent=i}else{i.left=null}e.right=i;i.parent=e}}if(o){r.right=o;o.parent=r}else{r.right=null}e.left=r;r.parent=e}}};d.prototype.replace=function t(e,r){if(!e.parent){this._root=r}else if(e===e.parent.left){e.parent.left=r}else{e.parent.right=r}if(r){r.parent=e.parent}};d.prototype.minNode=function t(e){if(e===void 0)e=this._root;if(e){while(e.left){e=e.left}}return e};d.prototype.maxNode=function t(e){if(e===void 0)e=this._root;if(e){while(e.right){e=e.right}}return e};d.prototype.insert=function t(e,r){var i=this._root;var n=null;var o=this._compare;var f;if(this._noDuplicates){while(i){n=i;f=o(i.key,e);if(f===0){return}else if(o(i.key,e)<0){i=i.right}else{i=i.left}}}else{while(i){n=i;if(o(i.key,e)<0){i=i.right}else{i=i.left}}}i={key:e,data:r,left:null,right:null,parent:n};if(!n){this._root=i}else if(o(n.key,i.key)<0){n.right=i}else{n.left=i}this.splay(i);this._size++;return i};d.prototype.find=function t(e){var r=this._root;var i=this._compare;while(r){var n=i(r.key,e);if(n<0){r=r.right}else if(n>0){r=r.left}else{return r}}return null};d.prototype.contains=function t(e){var r=this._root;var i=this._compare;while(r){var n=i(e,r.key);if(n===0){return true}else if(n<0){r=r.left}else{r=r.right}}return false};d.prototype.remove=function t(e){var r=this.find(e);if(!r){return false}this.splay(r);if(!r.left){this.replace(r,r.right)}else if(!r.right){this.replace(r,r.left)}else{var i=this.minNode(r.right);if(i.parent!==r){this.replace(i,i.right);i.right=r.right;i.right.parent=i}this.replace(r,i);i.left=r.left;i.left.parent=i}this._size--;return true};d.prototype.removeNode=function t(e){if(!e){return false}this.splay(e);if(!e.left){this.replace(e,e.right)}else if(!e.right){this.replace(e,e.left)}else{var r=this.minNode(e.right);if(r.parent!==e){this.replace(r,r.right);r.right=e.right;r.right.parent=r}this.replace(e,r);r.left=e.left;r.left.parent=r}this._size--;return true};d.prototype.erase=function t(e){var r=this.find(e);if(!r){return}this.splay(r);var i=r.left;var n=r.right;var o=null;if(i){i.parent=null;o=this.maxNode(i);this.splay(o);this._root=o}if(n){if(i){o.right=n}else{this._root=n}n.parent=o}this._size--};d.prototype.pop=function t(){var e=this