code: function(p, angle) {
  
              p = new Point(p);
              var center = new Point(this.x + this.width / 2, this.y + this.height / 2);
              var result;
  
              if (angle) p.rotate(center, angle);
  
              // (clockwise, starting from the top side)
              var sides = [
                  this.topLine(),
                  this.rightLine(),
                  this.bottomLine(),
                  this.leftLine()
              ];
              var connector = new Line(center, p);
  
              for (var i = sides.length - 1; i >= 0; --i) {
                  var intersection = sides[i].intersection(connector);
                  if (intersection !== null) {
                      result = intersection;
                      break;
                  }
              }
              if (result && angle) result.rotate(center, -angle);
              return result;
          }
docs: Find point on my boundary where line starting from my center ending in point p intersects me. @param {number} angle If angle is specified, intersection with rotated rectangle is computed.