Sha256: 32902a4876d9b469983c67391ae74b67864d1878e3b1a48d8e18b34d44050c20

Contents?: true

Size: 1006 Bytes

Versions: 5

Compression:

Stored size: 1006 Bytes

Contents

module Api
  # Adds additional functionality to message object Api::Point2D
  module Point2DExtension
    # @private
    # Hashes on x and y
    def hash
      [x, y].hash
    end

    # @private
    def eql?(other)
      self.class == other.class && hash == other.hash
    end

    # Returns self
    # @return [self]
    def to_p2d = self

    # Create a new 3d Point, by adding a y axis.
    # @param z [Float, Integer]
    # @return [Api::Point]
    def to_3d(z: 0)
      Api::Point[x, y, z]
    end

    # Adds additional functionality to message class Api::Point2D
    module ClassMethods
      # Shorthand for creating an instance for [x, y]
      # @example
      #   Api::Point2D[2,4] # Where x is 2.0 and y is 4.0
      # @param x [Float, Integer]
      # @param y [Float, Integer]
      # @return [Api::Point2D]
      def [](x, y)
        Api::Point2D.new(x: x, y: y)
      end
    end
  end
end
Api::Point2D.include Api::Point2DExtension
Api::Point2D.extend Api::Point2DExtension::ClassMethods

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sc2ai-0.4.3 lib/sc2ai/protocol/extensions/point_2_d.rb
sc2ai-0.4.2 lib/sc2ai/protocol/extensions/point_2_d.rb
sc2ai-0.4.1 lib/sc2ai/protocol/extensions/point_2_d.rb
sc2ai-0.4.0 lib/sc2ai/protocol/extensions/point_2_d.rb
sc2ai-0.3.0 lib/sc2ai/protocol/extensions/point_2_d.rb