Module: VectorSalad::Mixins::At

Included in:
StandardShapes::Circle, StandardShapes::IsoTri, StandardShapes::N, StandardShapes::Oval, StandardShapes::Polygon, StandardShapes::Rect
Defined in:
lib/vector_salad/mixins/at.rb

Overview

Mixin for positioning shapes.

Instance Method Summary (collapse)

Instance Method Details

- (Any) [](x, y)

Set the x, y coordinates of the shape.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (Any)


9
10
11
12
13
# File 'lib/vector_salad/mixins/at.rb', line 9

def [](x, y)
  shape = clone
  shape.at = [x, y]
  shape
end

- (Coords) at

Get the x, y coordinates of the shape.

Returns:

  • (Coords)

    +[Num, Num] an x,y coordinate array+



17
18
19
# File 'lib/vector_salad/mixins/at.rb', line 17

def at
  [@x, @y]
end

- (Any) at=(at)

Set the x, y coordinates of the shape directly.

Parameters:

  • at (Coords)

    +[Num, Num] an x,y coordinate array+

Returns:

  • (Any)


23
24
25
26
# File 'lib/vector_salad/mixins/at.rb', line 23

def at=(at)
  @x, @y = *at
  self
end

- (Any) move(x, y)

Move the shape relatively.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (Any)


30
31
32
33
34
# File 'lib/vector_salad/mixins/at.rb', line 30

def move(x, y)
  shape = clone
  shape.at = [shape.at[0] + x, shape.at[1] + y]
  shape
end