~ubuntu-branches/ubuntu/precise/whoopsie-daisy/precise-proposed

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/src/geom/delaunay.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-10 14:28:58 UTC
  • Revision ID: package-import@ubuntu.com-20120410142858-nk453o1z7t7py3bs
Tags: 0.1.26
* Take ownership of the NetworkManager state variant on setup and
  unref it, plugging a memory leak.
* Log the reason the server rejected the submitted crash report.
* Send the Whoopsie version with each crash submission.
* Delete both .upload and .uploaded files after 14 days. Thanks
  Marc Deslauriers (LP: #973687).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* @param vertices [[x1, y1], [x2, y2], …]
 
3
* @returns triangles [[[x1, y1], [x2, y2], [x3, y3]], …]
 
4
 */
 
5
d3.geom.delaunay = function(vertices) {
 
6
  var edges = vertices.map(function() { return []; }),
 
7
      triangles = [];
 
8
 
 
9
  // Use the Voronoi tessellation to determine Delaunay edges.
 
10
  d3_voronoi_tessellate(vertices, function(e) {
 
11
    edges[e.region.l.index].push(vertices[e.region.r.index]);
 
12
  });
 
13
 
 
14
  // Reconnect the edges into counterclockwise triangles.
 
15
  edges.forEach(function(edge, i) {
 
16
    var v = vertices[i],
 
17
        cx = v[0],
 
18
        cy = v[1];
 
19
    edge.forEach(function(v) {
 
20
      v.angle = Math.atan2(v[0] - cx, v[1] - cy);
 
21
    });
 
22
    edge.sort(function(a, b) {
 
23
      return a.angle - b.angle;
 
24
    });
 
25
    for (var j = 0, m = edge.length - 1; j < m; j++) {
 
26
      triangles.push([v, edge[j], edge[j + 1]]);
 
27
    }
 
28
  });
 
29
 
 
30
  return triangles;
 
31
};