Permalink
Browse files

renderer: choose cfrontier wisely (closest)

  • Loading branch information...
1 parent 50e757b commit e9109f664199939d946dba740985f4d5a6d1a49e @indutny committed Jan 14, 2013
Showing with 19 additions and 2 deletions.
  1. +19 −2 lib/spoon/renderer.js
View
@@ -31,8 +31,25 @@ Renderer.prototype.addSlots = function addSlot(slots) {
};
Renderer.prototype.getSlot = function getSlot() {
- var slots = this.current.cfrontier[0] &&
- this.slots[this.current.cfrontier[0].id];
+ var cfrontier;
+
+ // Choose closest cfrontier
+ if (this.current.cfrontier.length > 1) {
+ var distances = this.current.cfrontier.map(function(block) {
+ return {
+ distance: this.current.distance(block),
+ block: block
+ };
+ }, this).sort(function(a, b) {
+ return a.distance - b.distance;
+ });
+ cfrontier = distances[0].block;
+ } else {
+ cfrontier = this.current.cfrontier[0];
+ }
+
+ var slots = cfrontier &&
+ this.slots[cfrontier.id];
if (!slots) return this.defaultSlots[0];
// One branch - one slot

0 comments on commit e9109f6

Please sign in to comment.