<commit_before>
namespace('agt.geom')

# Public: A `Rectangle` geometry is defined with a position, a size
# and a rotation.
#
# ```coffeescript
# rectangle = new Rectangle 20, 20, 80, 40, Math.PI * 0.1
# rectangle = new Rectangle x: 20, y: 20, width: 80, height: 40, rotation: Math.PI * 0.1
# ```
#
# <script>window.exampleKey = 'rectangle'</script>
# <script>drawGeometry(exampleKey, {highlight: true})</script>
#
# ### Included Mixins
#
# - {agt.geom.Geometry}
# - {agt.geom.Intersections}
# - {agt.geom.Path}
# - {agt.geom.Surface}
# - {agt.mixins.Aliasable}
# - [agt.mixins.Cloneable](../../../files/mixins/cloneable.coffee.html)
# - [agt.mixins.Equatable](../../../files/mixins/equatable.coffee.html)
# - [agt.mixins.Formattable](../../../files/mixins/formattable.coffee.html)
# - [agt.mixins.Memoizable](../../../files/mixins/memoizable.coffee.html)
# - [agt.mixins.Parameterizable](../../../files/mixins/parameterizable.coffee.html)
# - [agt.mixins.Sourcable](../../../files/mixins/sourcable.coffee.html)
class agt.geom.Rectangle
  properties = ['x','y','width','height','rotation']

  @extend agt.mixins.Aliasable

  @include agt.mixins.Cloneable()
  @include agt.mixins.Equatable.apply(null, properties)
  @include agt.mixins.Formattable.apply(null, ['Rectangle'].concat properties)
  @include agt.mixins.Sourcable.apply(null, ['agt.geom.Rectangle'].concat properties)
  @include agt.mixins.Parameterizable('rectangleFrom', {
    x: NaN
    y: NaN
    width: NaN
    height: NaN
    rotation: NaN
  })
  @include agt.geom.Geometry
  @include agt.geom.Surface
  @include agt.geom.Path
  @include agt.geom.Triangulable
  @include agt.geom.Proxyable
  @include agt.geom.Intersections

  ### Public ###

  # A specific intersection algorithm when confronting two rectangles.
  #
  # <script>drawShapeIntersections(exampleKey, exampleKey)</script>
  #
  # geom1 - The first rectangle.
  # geom2 - The second rectangle.
  # block - The callback {Function} to call for each intersection.
  # data - A {Boolean} of whether to include extra data per intersection.
  @eachRectangleRectangleIntersections: (geom1, geom2, block, data=false) ->
    if geom1.equals geom2
      for p in geom1.points()
        return if block.call this, p
    else
      @eachIntersections geom1, geom2, block, data

  # Registers the fast intersections iterators for the Rectangle class
  iterators = agt.geom.Intersections.iterators
  k = 'RectangleRectangle'
  iterators[k] = Rectangle.eachRectangleRectangleIntersections

  # Creates a new `Rectangle` instance.
  #
  # x - The x coordinate {Number} of the rectangle or a rectangle-like {Object}.
  # y - The y coordinate {Number} of the rectangle.
  # width - The width {Number} of the rectangle.
  # height - The height {Number} of the rectangle.
  # rotation - The rotation {Number} of the rectangle.
  constructor: (x, y, width, height, rotation) ->
    args = @defaultToZero @rectangleFrom.apply this, arguments
    {@x,@y,@width,@height,@rotation} = args

  # Returns the coordinates of the rectangle's corners in an {Array}.
  #
  # <script>drawGeometryPoints(exampleKey, 'corners')</script>
  #
  # Returns an {Array}.
  corners: -> [@topLeft(), @topRight(), @bottomRight(), @bottomLeft()]

  # Returns the coordinates of the top left corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'topLeft')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topLeft: -> new agt.geom.Point(@x, @y)

  # Returns the coordinates of the top right corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'topRight')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topRight: -> @topLeft().add(@topEdge())

  # Returns the coordinates of the bottom left corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'bottomLeft')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomLeft: -> @topLeft().add(@leftEdge())

  # Returns the coordinates of the bottom right corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'bottomRight')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomRight: -> @topLeft().add(@topEdge()).add(@leftEdge())

  # Returns the coordinates of the center of the rectangle.
  #
  # <script>drawGeometry(exampleKey, {center: true})</script>
  #
  # Returns a [Point]{agt.geom.Point}
  center: -> @topLeft().add(@diagonal().scale(0.5))

  # Returns the coordinates of the center of the upper edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'topEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topEdgeCenter: -> @topLeft().add(@topEdge().scale(0.5))

  # Returns the coordinates of the center of the bottom edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'bottomEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomEdgeCenter: -> @bottomLeft().add(@topEdge().scale(0.5))

  # Returns the coordinates of the center of the left edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'leftEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  leftEdgeCenter: -> @topLeft().add(@leftEdge().scale(0.5))

  # Returns the coordinates of the center of the right edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'rightEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  rightEdgeCenter: -> @topRight().add(@leftEdge().scale(0.5))

  # Returns an array containing all the rectangle's edges vectors.
  #
  # Returns an {Array}.
  edges: -> [@topEdge(), @topRight(), @bottomRight(), @bottomLeft()]

  # Returns the rectangle's top edge vector.
  #
  # <script>drawGeometryEdge(exampleKey, 'topLeft', 'topEdge')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topEdge: -> new agt.geom.Point @width * Math.cos(@rotation),
                        @width * Math.sin(@rotation)

  # Returns the rectangle's left edge vector.
  #
  # <script>drawGeometryEdge(exampleKey, 'topLeft', 'leftEdge')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  leftEdge: ->
    new agt.geom.Point @height * Math.cos(@rotation + Math.PI / 2),
              @height * Math.sin(@rotation + Math.PI / 2)

  # Returns the rectangle's bottom edge vector.
  #
  # <script>drawGeometryEdge(exampleKey, 'bottomLeft', 'bottomEdge')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomEdge: -> @topEdge()
<commit_msg>:race_horse: Simpler version of edges methods with rotation = 0<commit_after>
namespace('agt.geom')

# Public: A `Rectangle` geometry is defined with a position, a size
# and a rotation.
#
# ```coffeescript
# rectangle = new Rectangle 20, 20, 80, 40, Math.PI * 0.1
# rectangle = new Rectangle x: 20, y: 20, width: 80, height: 40, rotation: Math.PI * 0.1
# ```
#
# <script>window.exampleKey = 'rectangle'</script>
# <script>drawGeometry(exampleKey, {highlight: true})</script>
#
# ### Included Mixins
#
# - {agt.geom.Geometry}
# - {agt.geom.Intersections}
# - {agt.geom.Path}
# - {agt.geom.Surface}
# - {agt.mixins.Aliasable}
# - [agt.mixins.Cloneable](../../../files/mixins/cloneable.coffee.html)
# - [agt.mixins.Equatable](../../../files/mixins/equatable.coffee.html)
# - [agt.mixins.Formattable](../../../files/mixins/formattable.coffee.html)
# - [agt.mixins.Memoizable](../../../files/mixins/memoizable.coffee.html)
# - [agt.mixins.Parameterizable](../../../files/mixins/parameterizable.coffee.html)
# - [agt.mixins.Sourcable](../../../files/mixins/sourcable.coffee.html)
class agt.geom.Rectangle
  properties = ['x','y','width','height','rotation']

  @extend agt.mixins.Aliasable

  @include agt.mixins.Cloneable()
  @include agt.mixins.Equatable.apply(null, properties)
  @include agt.mixins.Formattable.apply(null, ['Rectangle'].concat properties)
  @include agt.mixins.Sourcable.apply(null, ['agt.geom.Rectangle'].concat properties)
  @include agt.mixins.Parameterizable('rectangleFrom', {
    x: NaN
    y: NaN
    width: NaN
    height: NaN
    rotation: NaN
  })
  @include agt.geom.Geometry
  @include agt.geom.Surface
  @include agt.geom.Path
  @include agt.geom.Triangulable
  @include agt.geom.Proxyable
  @include agt.geom.Intersections

  ### Public ###

  # A specific intersection algorithm when confronting two rectangles.
  #
  # <script>drawShapeIntersections(exampleKey, exampleKey)</script>
  #
  # geom1 - The first rectangle.
  # geom2 - The second rectangle.
  # block - The callback {Function} to call for each intersection.
  # data - A {Boolean} of whether to include extra data per intersection.
  @eachRectangleRectangleIntersections: (geom1, geom2, block, data=false) ->
    if geom1.equals geom2
      for p in geom1.points()
        return if block.call this, p
    else
      @eachIntersections geom1, geom2, block, data

  # Registers the fast intersections iterators for the Rectangle class
  iterators = agt.geom.Intersections.iterators
  k = 'RectangleRectangle'
  iterators[k] = Rectangle.eachRectangleRectangleIntersections

  # Creates a new `Rectangle` instance.
  #
  # x - The x coordinate {Number} of the rectangle or a rectangle-like {Object}.
  # y - The y coordinate {Number} of the rectangle.
  # width - The width {Number} of the rectangle.
  # height - The height {Number} of the rectangle.
  # rotation - The rotation {Number} of the rectangle.
  constructor: (x, y, width, height, rotation) ->
    args = @defaultToZero @rectangleFrom.apply this, arguments
    {@x,@y,@width,@height,@rotation} = args

  # Returns the coordinates of the rectangle's corners in an {Array}.
  #
  # <script>drawGeometryPoints(exampleKey, 'corners')</script>
  #
  # Returns an {Array}.
  corners: -> [@topLeft(), @topRight(), @bottomRight(), @bottomLeft()]

  # Returns the coordinates of the top left corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'topLeft')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topLeft: -> new agt.geom.Point(@x, @y)

  # Returns the coordinates of the top right corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'topRight')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topRight: -> @topLeft().add(@topEdge())

  # Returns the coordinates of the bottom left corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'bottomLeft')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomLeft: -> @topLeft().add(@leftEdge())

  # Returns the coordinates of the bottom right corner of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'bottomRight')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomRight: -> @topLeft().add(@topEdge()).add(@leftEdge())

  # Returns the coordinates of the center of the rectangle.
  #
  # <script>drawGeometry(exampleKey, {center: true})</script>
  #
  # Returns a [Point]{agt.geom.Point}
  center: -> @topLeft().add(@diagonal().scale(0.5))

  # Returns the coordinates of the center of the upper edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'topEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topEdgeCenter: -> @topLeft().add(@topEdge().scale(0.5))

  # Returns the coordinates of the center of the bottom edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'bottomEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomEdgeCenter: -> @bottomLeft().add(@topEdge().scale(0.5))

  # Returns the coordinates of the center of the left edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'leftEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  leftEdgeCenter: -> @topLeft().add(@leftEdge().scale(0.5))

  # Returns the coordinates of the center of the right edge of the rectangle.
  #
  # <script>drawGeometryPoints(exampleKey, 'rightEdgeCenter')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  rightEdgeCenter: -> @topRight().add(@leftEdge().scale(0.5))

  # Returns an array containing all the rectangle's edges vectors.
  #
  # Returns an {Array}.
  edges: -> [@topEdge(), @topRight(), @bottomRight(), @bottomLeft()]

  # Returns the rectangle's top edge vector.
  #
  # <script>drawGeometryEdge(exampleKey, 'topLeft', 'topEdge')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  topEdge: ->
    if @rotation is 0
      new agt.geom.Point @width, 0
    else
      new agt.geom.Point @width * Math.cos(@rotation),
                         @width * Math.sin(@rotation)

  # Returns the rectangle's left edge vector.
  #
  # <script>drawGeometryEdge(exampleKey, 'topLeft', 'leftEdge')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  leftEdge: ->
    if @rotation is 0
      new agt.geom.Point 0, @height
    else
      new agt.geom.Point @height * Math.cos(@rotation + Math.PI / 2),
                         @height * Math.sin(@rotation + Math.PI / 2)

  # Returns the rectangle's bottom edge vector.
  #
  # <script>drawGeometryEdge(exampleKey, 'bottomLeft', 'bottomEdge')</script>
  #
  # Returns a [Point]{agt.geom.Point}.
  bottomEdge: -> @topEdge()

{'fraction_non_alphanumeric': 0.15368583558471632, 'fraction_numerical': 0.006715553840216133, 'mean_word_length': 3.759735488611315, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7455226', 'n_tokens_mistral': 4404, 'n_tokens_neox': 4221, 'n_words': 1028}