 
     p.angle()
 
+  # Internal: Calculates the proportions of each step of the rectangle path.
+  #
+  # Returns an {Array}.
   pathSteps: (pathBasedOnLength=true) ->
     if pathBasedOnLength
       l = @length()

      .add(@topEdge().scale random.get())
      .add(@leftEdge().scale random.get())

  length: -> @width * 2 + @height * 2

  pathPointAt: (n, pathBasedOnLength=true) ->
    [p1,p2,p3] = @pathSteps pathBasedOnLength



  @alias 'scale', 'scaleAroundCenter'

  # Inflates the rectangle around its center by the amount of the arguments.
  #
  # <script>drawTransform('rectangle', {type: 'inflateAroundCenter', args: [10, 10]})</script>
  #
  # x - A {Number} for the width or a point-like {Object}.
  # y - A {Number} for the height if the first argument
  #     was also a number.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateAroundCenter: (x, y) ->
    center = @center()
    @inflate x, y
    @setCenter center
    this

  # Inflates the rectangle from its origin by the amount of the arguments.
  #
  # <script>drawTransform('rectangle', {type: 'inflate', args: [10, 10]})</script>
  #
  # x - A {Number} for the width or a point-like {Object}.
  # y - A {Number} for the height if the first argument
  #     was also a number.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflate: (x, y) ->
    pt = Point.pointFrom x, y
    @width += pt.x
    @height += pt.y
    this

  # Inflates the rectangle width to the left by the passed-in value.
  #
  # <script>drawTransform('rectangle', {type: 'inflateLeft', args: [10]})</script>
  #
  # inflate - a {Number} for the width inflation.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateLeft: (inflate) ->
    @width += inflate
    offset = @topEdge().normalize(-inflate)
    {@x,@y} = @topLeft().add(offset)
    this

  # Inflates the rectangle width to the right by the passed-in value.
  #
  # <script>drawTransform('rectangle', {type: 'inflateRight', args: [10]})</script>
  #
  # inflate - A {Number} for width inflation.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateRight: (inflate) ->
    @width += inflate
    this

  # Inflates the rectangle height to the top by the passed-in value.
  #
  # <script>drawTransform('rectangle', {type: 'inflateTop', args: [10]})</script>
  #
  # x - A {Number} for the height inflation.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateTop: (inflate) ->
    @height += inflate
    offset = @leftEdge().normalize(-inflate)
    {@x,@y} = @topLeft().add(offset)
    this

  # Inflates the rectangle height to the bottom by the passed-in value.
  #
  # <script>drawTransform('rectangle', {type: 'inflateBottom', args: [10]})</script>
  #
  # x - A {Number} for the height inflation.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateBottom: (inflate) ->
    @height += inflate
    this

  # Inflates the rectangle to the top left by the amount of the arguments.
  #
  # <script>drawTransform('rectangle', {type: 'inflateTopLeft', args: [10, 10]})</script>
  #
  # x - A {Number} for the width or a point-like {Object}.
  # y - A {Number} for the height if the first argument
  #     was also a number.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateTopLeft: (x, y) ->
    pt = Point.pointFrom x, y
    @inflateLeft pt.x
    @inflateTop pt.y
    this

  # Inflates the rectangle to the top right by the amount of the arguments.
  #
  # <script>drawTransform('rectangle', {type: 'inflateTopRight', args: [10, 10]})</script>
  #
  # x - A {Number} for the width or a point-like {Object}.
  # y - A {Number} for the height if the first argument
  #     was also a number.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateTopRight: (x, y) ->
    pt = Point.pointFrom x, y
    @inflateRight pt.x
    @inflateTop pt.y
    this

  # Inflates the rectangle to the bottom left by the amount of the arguments.
  #
  # <script>drawTransform('rectangle', {type: 'inflateBottomLeft', args: [10, 10]})</script>
  #
  # x - A {Number} for the width or a point-like {Object}.
  # y - A {Number} for the height if the first argument
  #     was also a number.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateBottomLeft: (x, y) ->
    pt = Point.pointFrom x, y
    @inflateLeft pt.x
    @inflateBottom pt.y
    this

  # Inflates the rectangle to the bottom right by the amount of the arguments.
  #
  # <script>drawTransform('rectangle', {type: 'inflateBottomRight', args: [10, 10]})</script>
  #
  # x - A {Number} for the width or a point-like {Object}.
  # y - A {Number} for the height if the first argument
  #     was also a number.
  #
  # Returns this [Rectangle]{agt.geom.Rectangle}.
  inflateBottomRight: (x, y) -> @inflate x, y

  # Always returns `true`.
  #
  # Returns a {Boolean}.
  closedGeometry: -> true

  # Returns the rectangle points.
  #
  # <script>drawGeometryPoints('rectangle', 'points')</script>
  #
  # Returns an {Array}.
  points: ->
    [@topLeft(), @topRight(), @bottomRight(), @bottomLeft(), @topLeft()]

  # Returns the [Point]{agt.geom.Point} on the perimeter of the rectangle
  # at the given `angle`.
  #
  # angle - The angle {Number}.
  #
  # <script>drawGeometry('rectangle', {angle: true})</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  pointAtAngle: (angle) ->
    center = @center()
    vec = center.add Math.cos(angle)*10000,
                     Math.sin(angle)*10000
    @intersections(points: -> [center, vec])?[0]

  # Returns the surface {Number} of this rectangle.
  #
  # Returns a {Number}.
  acreage: -> @width * @height

  # Returns `true` when the given point is contained in the rectangle.
  #
  # In the example below all the green points on the screen represents
  # coordinates that are contained in the rectangle.
  #
  # <script>drawGeometry('rectangle', {contains: true})</script>
  #
  # x - A {Number} for the x coordinate or a point-like {Object}.
  # y - A {Number} for the y coordinate if the first argument
  #     was also a number.
  #
  # Returns a {Boolean}.
  contains: (x, y) ->
    {x,y} = new Point(x, y).rotateAround(@topLeft(), -@rotation)
    (@x <= x <= @x + @width) and (@y <= y <= @y + @height)

  # Returns a randomly generated point within the rectangle perimeter.
  #
  # <script>drawGeometry('rectangle', {surface: true})</script>
  #
  # random - An optional [Random]{agt.random.Random} instance to use instead
  #          of the default `Math` random method.
  #
  # Returns a [Point]{agt.geom.Point}.
  randomPointInSurface: (random) ->
    unless random?
      random = new chancejs.Random new chancejs.MathRandom
