Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion rhill-voronoi-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,23 @@ Voronoi.prototype.closeCells = function(bbox) {
}
};

// http://www.wikihow.com/Calculate-the-Area-of-a-Polygon
Voronoi.prototype.computeAreas = function() {
for (var i = 0 ; i < this.cells.length ; i++){
var Stotal=0
var Ttotal=0
var cell=this.cells[i];
for ( var j = 0 ; j < cell.halfedges.length ; j++ ) {
var vertexa = cell.halfedges[j].getStartpoint();
var vertexb = cell.halfedges[j].getEndpoint();
Stotal+=vertexa.x*vertexb.y
Ttotal+=vertexa.y*vertexb.x
}
cell.area=(Ttotal-Stotal)/2
}

}

// ---------------------------------------------------------------------------
// Top-level Fortune loop

Expand Down Expand Up @@ -1453,7 +1470,7 @@ Voronoi.prototype.compute = function(sites, bbox) {

// add missing edges in order to close opened cells
this.closeCells(bbox);

this.computeAreas();
// to measure execution time
var stopTime = new Date();

Expand Down