class Point

class Point

lib/geometry/point.tya:2

Point provides the geometry/Point standard library API.

Source
# Point provides the geometry/Point standard library API.
class Point
  # Point.x stores instance state.
  # @type Int
  x: 0

  # Point.y stores instance state.
  # @type Int
  y: 0

  # Point.initialize provides the geometry/Point standard library operation.
  # @param x Int x value.
  # @param y Int y value.
  # @return Self the initialized object.
  initialize: x = 0, y = 0 ->
    self.x = self.number(x, "x")
    self.y = self.number(y, "y")

  # Point.distance provides the geometry/Point standard library operation.
  # @param a Int a value.
  # @param b Int b value.
  # @return Any the resulting value.
  distance: a, b = nil ->
    if b == nil
      b = a
      a = self
    Vector2(0, 0).distance(self.to_vector(a), self.to_vector(b))

  # Point.equal? provides the geometry/Point standard library operation.
  # @param a Int a value.
  # @param b Int b value.
  # @return Boolean whether the condition is true.
  equal?: a, b = nil ->
    if b == nil
      b = a
      a = self
    a.class == Point and b.class == Point and a.x == b.x and a.y == b.y

  # Point.expect provides the geometry/Point standard library operation.
  # @param value String value value.
  # @param name String name value.
  # @return Any the resulting value.
  expect: value, name ->
    if value.class != Point
      raise error("geometry.Point: " + name + " must be a Point")

  # Point.from_vector provides the geometry/Point standard library operation.
  # @param v Any v value.
  # @return Self the resulting value.
  from_vector: v ->
    if v.class != Vector2
      raise error("geometry.Point.from_vector: v must be a Vector2")
    Point(v.x, v.y)

  # Point.new provides the geometry/Point standard library operation.
  # @param x Int x value.
  # @param y Int y value.
  # @return Self the resulting value.
  new: x, y ->
    Point(x, y)

  # Point.number provides the geometry/Point standard library operation.
  # @param value String value value.
  # @param name String name value.
  # @return Any the resulting value.
  number: value, name ->
    if value.class != Number
      raise error("geometry.Point: " + name + " must be a number")
    value

  # Point.to_vector provides the geometry/Point standard library operation.
  # @param p Any p value.
  # @return Any the resulting value.
  to_vector: p = nil ->
    if p == nil
      p = self
    self.expect(p, "p")
    Vector2(p.x, p.y)

  # Point.translate provides the geometry/Point standard library operation.
  # @param p Any p value.
  # @param v Any v value.
  # @return Any the resulting value.
  translate: p, v = nil ->
    if v == nil
      v = p
      p = self
    self.expect(p, "p")
    if v.class != Vector2
      raise error("geometry.Point.translate: v must be a Vector2")
    Point(p.x + v.x, p.y + v.y)

Instance Variables

x

Point.x

lib/geometry/point.tya:5

Point.x stores instance state.

Source
  # Point.x stores instance state.
  # @type Int
  x: 0

y

Point.y

lib/geometry/point.tya:9

Point.y stores instance state.

Source
  # Point.y stores instance state.
  # @type Int
  y: 0

Methods

distance

Point.distance(a, b = nil)

lib/geometry/point.tya:23

Point.distance provides the geometry/Point standard library operation.

Source
  # Point.distance provides the geometry/Point standard library operation.
  # @param a Int a value.
  # @param b Int b value.
  # @return Any the resulting value.
  distance: a, b = nil ->
    if b == nil
      b = a
      a = self
    Vector2(0, 0).distance(self.to_vector(a), self.to_vector(b))

equal?

Point.equal?(a, b = nil)

lib/geometry/point.tya:33

Point.equal? provides the geometry/Point standard library operation.

Source
  # Point.equal? provides the geometry/Point standard library operation.
  # @param a Int a value.
  # @param b Int b value.
  # @return Boolean whether the condition is true.
  equal?: a, b = nil ->
    if b == nil
      b = a
      a = self
    a.class == Point and b.class == Point and a.x == b.x and a.y == b.y

expect

Point.expect(value, name)

lib/geometry/point.tya:43

Point.expect provides the geometry/Point standard library operation.

Source
  # Point.expect provides the geometry/Point standard library operation.
  # @param value String value value.
  # @param name String name value.
  # @return Any the resulting value.
  expect: value, name ->
    if value.class != Point
      raise error("geometry.Point: " + name + " must be a Point")

from_vector

Point.from_vector(v)

lib/geometry/point.tya:50

Point.from_vector provides the geometry/Point standard library operation.

Source
  # Point.from_vector provides the geometry/Point standard library operation.
  # @param v Any v value.
  # @return Self the resulting value.
  from_vector: v ->
    if v.class != Vector2
      raise error("geometry.Point.from_vector: v must be a Vector2")
    Point(v.x, v.y)

initialize

Point.initialize(x = 0, y = 0)

lib/geometry/point.tya:15

Point.initialize provides the geometry/Point standard library operation.

Source
  # Point.initialize provides the geometry/Point standard library operation.
  # @param x Int x value.
  # @param y Int y value.
  # @return Self the initialized object.
  initialize: x = 0, y = 0 ->
    self.x = self.number(x, "x")
    self.y = self.number(y, "y")

new

Point.new(x, y)

lib/geometry/point.tya:59

Point.new provides the geometry/Point standard library operation.

Source
  # Point.new provides the geometry/Point standard library operation.
  # @param x Int x value.
  # @param y Int y value.
  # @return Self the resulting value.
  new: x, y ->
    Point(x, y)

number

Point.number(value, name)

lib/geometry/point.tya:66

Point.number provides the geometry/Point standard library operation.

Source
  # Point.number provides the geometry/Point standard library operation.
  # @param value String value value.
  # @param name String name value.
  # @return Any the resulting value.
  number: value, name ->
    if value.class != Number
      raise error("geometry.Point: " + name + " must be a number")
    value

to_vector

Point.to_vector(p = nil)

lib/geometry/point.tya:74

Point.to_vector provides the geometry/Point standard library operation.

Source
  # Point.to_vector provides the geometry/Point standard library operation.
  # @param p Any p value.
  # @return Any the resulting value.
  to_vector: p = nil ->
    if p == nil
      p = self
    self.expect(p, "p")
    Vector2(p.x, p.y)

translate

Point.translate(p, v = nil)

lib/geometry/point.tya:84

Point.translate provides the geometry/Point standard library operation.

Source
  # Point.translate provides the geometry/Point standard library operation.
  # @param p Any p value.
  # @param v Any v value.
  # @return Any the resulting value.
  translate: p, v = nil ->
    if v == nil
      v = p
      p = self
    self.expect(p, "p")
    if v.class != Vector2
      raise error("geometry.Point.translate: v must be a Vector2")
    Point(p.x + v.x, p.y + v.y)