Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

renderer: choose cfrontier wisely (closest)

  • Loading branch information...
commit e9109f664199939d946dba740985f4d5a6d1a49e 1 parent 50e757b
Fedor Indutny authored January 14, 2013

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. 21  lib/spoon/renderer.js
21  lib/spoon/renderer.js
@@ -31,8 +31,25 @@ Renderer.prototype.addSlots = function addSlot(slots) {
31 31
 };
32 32
 
33 33
 Renderer.prototype.getSlot = function getSlot() {
34  
-  var slots = this.current.cfrontier[0] &&
35  
-              this.slots[this.current.cfrontier[0].id];
  34
+  var cfrontier;
  35
+
  36
+  // Choose closest cfrontier
  37
+  if (this.current.cfrontier.length > 1) {
  38
+    var distances = this.current.cfrontier.map(function(block) {
  39
+      return {
  40
+        distance: this.current.distance(block),
  41
+        block: block
  42
+      };
  43
+    }, this).sort(function(a, b) {
  44
+      return a.distance - b.distance;
  45
+    });
  46
+    cfrontier = distances[0].block;
  47
+  } else {
  48
+    cfrontier = this.current.cfrontier[0];
  49
+  }
  50
+
  51
+  var slots = cfrontier &&
  52
+              this.slots[cfrontier.id];
36 53
   if (!slots) return this.defaultSlots[0];
37 54
 
38 55
   // One branch - one slot

0 notes on commit e9109f6

Please sign in to comment.
Something went wrong with that request. Please try again.