| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.attachCircle = attachCircle;
|
|---|
| 7 | exports.detachCircle = detachCircle;
|
|---|
| 8 | exports.firstCircle = void 0;
|
|---|
| 9 | var _RedBlackTree = require("./RedBlackTree");
|
|---|
| 10 | var _Diagram = require("./Diagram");
|
|---|
| 11 | var circlePool = [];
|
|---|
| 12 | var firstCircle;
|
|---|
| 13 | function Circle() {
|
|---|
| 14 | (0, _RedBlackTree.RedBlackNode)(this);
|
|---|
| 15 | this.x = this.y = this.arc = this.site = this.cy = null;
|
|---|
| 16 | }
|
|---|
| 17 | function attachCircle(arc) {
|
|---|
| 18 | var lArc = arc.P,
|
|---|
| 19 | rArc = arc.N;
|
|---|
| 20 | if (!lArc || !rArc) return;
|
|---|
| 21 | var lSite = lArc.site,
|
|---|
| 22 | cSite = arc.site,
|
|---|
| 23 | rSite = rArc.site;
|
|---|
| 24 | if (lSite === rSite) return;
|
|---|
| 25 | var bx = cSite[0],
|
|---|
| 26 | by = cSite[1],
|
|---|
| 27 | ax = lSite[0] - bx,
|
|---|
| 28 | ay = lSite[1] - by,
|
|---|
| 29 | cx = rSite[0] - bx,
|
|---|
| 30 | cy = rSite[1] - by;
|
|---|
| 31 | var d = 2 * (ax * cy - ay * cx);
|
|---|
| 32 | if (d >= -_Diagram.epsilon2) return;
|
|---|
| 33 | var ha = ax * ax + ay * ay,
|
|---|
| 34 | hc = cx * cx + cy * cy,
|
|---|
| 35 | x = (cy * ha - ay * hc) / d,
|
|---|
| 36 | y = (ax * hc - cx * ha) / d;
|
|---|
| 37 | var circle = circlePool.pop() || new Circle();
|
|---|
| 38 | circle.arc = arc;
|
|---|
| 39 | circle.site = cSite;
|
|---|
| 40 | circle.x = x + bx;
|
|---|
| 41 | circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
|
|---|
| 42 |
|
|---|
| 43 | arc.circle = circle;
|
|---|
| 44 | var before = null,
|
|---|
| 45 | node = _Diagram.circles._;
|
|---|
| 46 | while (node) {
|
|---|
| 47 | if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
|
|---|
| 48 | if (node.L) node = node.L;else {
|
|---|
| 49 | before = node.P;
|
|---|
| 50 | break;
|
|---|
| 51 | }
|
|---|
| 52 | } else {
|
|---|
| 53 | if (node.R) node = node.R;else {
|
|---|
| 54 | before = node;
|
|---|
| 55 | break;
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | _Diagram.circles.insert(before, circle);
|
|---|
| 60 | if (!before) exports.firstCircle = firstCircle = circle;
|
|---|
| 61 | }
|
|---|
| 62 | function detachCircle(arc) {
|
|---|
| 63 | var circle = arc.circle;
|
|---|
| 64 | if (circle) {
|
|---|
| 65 | if (!circle.P) exports.firstCircle = firstCircle = circle.N;
|
|---|
| 66 | _Diagram.circles.remove(circle);
|
|---|
| 67 | circlePool.push(circle);
|
|---|
| 68 | (0, _RedBlackTree.RedBlackNode)(circle);
|
|---|
| 69 | arc.circle = null;
|
|---|
| 70 | }
|
|---|
| 71 | } |
|---|