Class: VectorSalad::StandardShapes::N

Inherits:
Object
  • Object
show all
Includes:
Mixins::At
Defined in:
lib/vector_salad/standard_shapes/n.rb

Overview

N node. A node is the simplest primitive but useless on its own. Use nodes to build up a path (see Path). A node is a point in space with x and y coordinates.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (N) initialize(x, y, type = :node)

Create an N node.

The coordinates must be nil if the node type is :mirror, else they must be numeric.

A node also has a type, the simplest is :node for corners. To create node types other than :node see the shorthand class methods.

Examples: new(50, 100) new(50, 100, :cubic) new(nil, nil, :mirror)

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

  • type (Maybe[*%i(node quadratic cubic g2 g4 left right)]) (defaults to: :node)


15
16
17
18
# File 'lib/vector_salad/standard_shapes/n.rb', line 15

def initialize(x, y, type)
  create(x, y, type)
  self
end

Instance Attribute Details

- (Object) type

Returns the value of attribute type



12
13
14
# File 'lib/vector_salad/standard_shapes/n.rb', line 12

def type
  @type
end

- (Object) x

Returns the value of attribute x



12
13
14
# File 'lib/vector_salad/standard_shapes/n.rb', line 12

def x
  @x
end

- (Object) y

Returns the value of attribute y



12
13
14
# File 'lib/vector_salad/standard_shapes/n.rb', line 12

def y
  @y
end

Class Method Details

+ (N) c(x, y)

Shorthand that creates a :cubic type bezier curve handle node. This "off curve" node isn't part of the path but distorts pulling it. Two :cubic nodes must come between two :node type nodes. E.g. n c c n. As the interaction of two cubic nodes distorts the line segment this can be quite difficult to imagine, see :quadratic or :spiro for easier alternatives to make curves.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (N)


62
63
64
# File 'lib/vector_salad/standard_shapes/n.rb', line 62

def self.c(x, y)
  new(x, y, :cubic)
end

+ (N) g(x, y)

Shorthand that creates a smooth spiro :g4 node. There are :g2 and :g4 spiro node types; :g4 is smoothest but has longer distance effects and may sometimes fail.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (N)


90
91
92
# File 'lib/vector_salad/standard_shapes/n.rb', line 90

def self.g(x, y)
  new(x, y, :g4)
end

+ (N) l(x, y)

Shorthand that creates a :left spiro node. It joins a straight line segment on the right to a curve on the left.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (N)


104
105
106
# File 'lib/vector_salad/standard_shapes/n.rb', line 104

def self.l(x, y)
  new(x, y, :left)
end

+ (N) m

Creates a :mirrored type node. It makes it easier to make smooth curves. The reflection is based on the cubic or quadratic node before the last standard :node so there must be one.

Returns:

  • (N)


51
52
53
# File 'lib/vector_salad/standard_shapes/n.rb', line 51

def self.m
  new(nil, nil, :mirror)
end

+ (N) n(x, y, type = :node)

Shorthand for calling new to create a node. The type defaults to :node for basic corner or line segment nodes. See the documentation for new for usage.

Parameters:

  • x (Maybe[Coord])
  • y (Maybe[Coord])
  • type (Maybe[Symbol]) (defaults to: :node)

Returns:

  • (N)


43
44
45
# File 'lib/vector_salad/standard_shapes/n.rb', line 43

def self.n(x, y, type = :node)
  new(x, y, type)
end

+ (N) q(x, y)

Shorthand that creates a :quadratic type bezier curve handle node. This "off curve" node isn't part of the path but distorts pulling it. One :quadratic node must come between two :node type nodes. E.g. n q n. Only one quadratic node is needed to make a curve, however :spiro type nodes are even easier for making smooth curves.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (N)


72
73
74
# File 'lib/vector_salad/standard_shapes/n.rb', line 72

def self.q(x, y)
  new(x, y, :quadratic)
end

+ (N) r(x, y)

Shorthand that creates a :right spiro node. It joins a straight line segment on the left to a curve on the right.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (N)


97
98
99
# File 'lib/vector_salad/standard_shapes/n.rb', line 97

def self.r(x, y)
  new(x, y, :right)
end

+ (N) s(x, y)

Shorthand that creates a smooth spiro :g2 node. Spiro nodes are "on curve" so the path bends through them, finding the smoothest possible route. They are perfect for making organic curves. There are :g2 and :g4 spiro node types; :g2 is most robust and a good all rounder.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (N)


82
83
84
# File 'lib/vector_salad/standard_shapes/n.rb', line 82

def self.s(x, y)
  new(x, y, :g2)
end

Instance Method Details

- (Any) [](x, y) Originally defined in module Mixins::At

Set the x, y coordinates of the shape.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (Any)

- (Coords) at Originally defined in module Mixins::At

Get the x, y coordinates of the shape.

Returns:

  • (Coords)

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

- (Any) at=(at) Originally defined in module Mixins::At

Set the x, y coordinates of the shape directly.

Parameters:

  • at (Coords)

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

Returns:

  • (Any)

- (Any) move(x, y) Originally defined in module Mixins::At

Move the shape relatively.

Parameters:

  • x (Coord)

    +Num; a coordinate+

  • y (Coord)

    +Num; a coordinate+

Returns:

  • (Any)