public void DetachBeachSection(TreeNode beachSectionNode) { //this.detachCircleEvent(beachsection); // detach potentially attached circle event //this.beachline.rbRemoveNode(beachsection); // remove from RB-tree //this.beachsectionJunkyard.push(beachsection); // mark for reuse DetachCircleEvent(beachSectionNode); BeachLine.RemoveNode(beachSectionNode); //BeachLine.Dump("BeachLine removing node", beachLineCounter++); BeachLine.Dump("detachBeachSection, remove", beachLineCounter++); //dumpTree(this.beachline, "detachBeachSection, remove", beachLineCounter); beachLineCounter++; }
public void AddBeachSection(Site site) { //var x = site.x, // directrix = site.y; var x = site.X; var dir = site.Y; //var lArc, rArc, // dxl, dxr, // node = this.beachline.root; TreeNode lArc = null, rArc = null; double dxl, dxr; TreeNode node = BeachLine.root; while (node != null) { // dxl = this.leftBreakPoint(node, directrix) - x; dxl = GetLeftBreakPoint(node.BeachSection, node, dir) - x; // // x lessThanWithEpsilon xl => falls somewhere before the left edge of the beachsection // if (dxl > 1e-9) // { // node = node.rbLeft; // } // else // { if (dxl > epsilon) { node = node.Left; } else { // dxr = x - this.rightBreakPoint(node, directrix); dxr = x - GetRightBreakPoint(node.BeachSection, node, dir); // // x greaterThanWithEpsilon xr => falls somewhere after the right edge of the beachsection // if (dxr > 1e-9) // { // if (!node.rbRight) // { // lArc = node; // break; // } // node = node.rbRight; // } if (dxr > epsilon) { if (node.Right == null) { lArc = node; break; } node = node.Right; } else { if (dxl > -epsilon) { lArc = node.Previous; rArc = node; } else if (dxr > -epsilon) { lArc = node; rArc = node.Next; } else { lArc = node; rArc = node; } break; } // else // { // // x equalWithEpsilon xl => falls exactly on the left edge of the beachsection // if (dxl > -1e-9) // { // lArc = node.rbPrevious; // rArc = node; // } // // x equalWithEpsilon xr => falls exactly on the right edge of the beachsection // else if (dxr > -1e-9) // { // lArc = node; // rArc = node.rbNext; // } // // falls exactly somewhere in the middle of the beachsection // else // { // lArc = rArc = node; // } // break; // } // } } } //var newArc = this.createBeachsection(site); //this.beachline.rbInsertSuccessor(lArc, newArc); var newArc = CreateBeachSection(site); var newArcNode = new TreeNode { BeachSection = newArc, X = site.X, Y = site.Y, Site = site }; BeachLine.InsertSuccessor(lArc, newArcNode); //dumpTree(this.beachline, "BeachLine, addBeachSection first insert", beachLineCounter); BeachLine.Dump("BeachLine, addBeachSection first insert", beachLineCounter++); //if (!lArc && !rArc) //{ // return; //} if (lArc == null && rArc == null) { return; } //if (lArc === rArc) //{ // this.detachCircleEvent(lArc); // rArc = this.createBeachsection(lArc.site); // this.beachline.rbInsertSuccessor(newArc, rArc); // newArc.edge = rArc.edge = this.createEdge(lArc.site, newArc.site); // this.a--ttachCircleEvent(lArc); // this.a--ttachCircleEvent(rArc); // return; //} if (lArc == rArc) { DetachCircleEvent(lArc); var s = lArc.BeachSection.Site; rArc = new TreeNode { BeachSection = CreateBeachSection(s), X = s.X, Y = s.Y, Site = s }; BeachLine.InsertSuccessor(newArcNode, rArc); BeachLine.Dump("BeachLine, addBeachSection second insert", beachLineCounter++); newArc.Edge = CreateEdge(lArc.BeachSection.Site, newArc.Site, null, null); rArc.BeachSection.Edge = newArc.Edge; AttachCircleEvent(lArc); AttachCircleEvent(rArc); return; } //if (lArc && !rArc) //{ // newArc.edge = this.createEdge(lArc.site, newArc.site); // return; //} if (lArc != null && rArc == null) { newArc.Edge = CreateEdge(lArc.BeachSection.Site, newArc.Site, null, null); return; } ////if (!lArc && rArc) { //// throw "Voronoi.addBeachsection(): What is this I don't even"; //// } /// if (lArc == null && rArc != null) { Console.WriteLine("SHOULD NOT HAPPEN"); } //if (lArc !== rArc) //{ // this.detachCircleEvent(lArc); // this.detachCircleEvent(rArc); // var lSite = lArc.site, // ax = lSite.x, // ay = lSite.y, // bx = site.x - ax, // by = site.y - ay, // rSite = rArc.site, // cx = rSite.x - ax, // cy = rSite.y - ay, // d = 2 * (bx * cy - by * cx), // hb = bx * bx + by * by, // hc = cx * cx + cy * cy, // vertex = this.createVertex((cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay); // this.setEdgeStartpoint(rArc.edge, lSite, rSite, vertex); // newArc.edge = this.createEdge(lSite, site, undefined, vertex); // rArc.edge = this.createEdge(site, rSite, undefined, vertex); // this.a--ttachCircleEvent(lArc); // this.a--ttachCircleEvent(rArc); // return; //} if (lArc != rArc) { DetachCircleEvent(lArc); DetachCircleEvent(rArc); var lSite = lArc.BeachSection.Site; var ax = lSite.X; var ay = lSite.Y; var bx = site.X - ax; var by = site.Y - ay; var rSite = rArc.BeachSection.Site; var cx = rSite.X - ax; var cy = rSite.Y - ay; var d = 2 * (bx * cy - by * cx); var hb = bx * bx + by * by; var hc = cx * cx + cy * cy; var vertex = CreateVertex((cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay); rArc.BeachSection.Edge = CreateEdge(lSite, site, null, vertex); newArc.Edge = CreateEdge(lSite, site, null, vertex); rArc.BeachSection.Edge = CreateEdge(site, rSite, null, vertex); AttachCircleEvent(lArc); AttachCircleEvent(rArc); return; } }