code: function(drad) {
      var cos = Math.cos(drad);
      cos = -1e-10 < cos && cos < 1e-10 ? 0 : cos;
      return cos;
  }
docs: These versions of cos and sin ensure that rotations very close to 0 return 0. This avoids some problems where entities are not quite aligned with the grid.