Module: Draught::Pathlike

Included in:
Line, Path
Defined in:
lib/draught/pathlike.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



35
36
37
38
# File 'lib/draught/pathlike.rb', line 35

def ==(other)
  return false if number_of_points != other.number_of_points
  points.zip(other.points).all? { |a, b| a == b }
end

#[](index_start_or_range, length = nil) ⇒ Object

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/draught/pathlike.rb', line 15

def [](index_start_or_range, length = nil)
  raise NotImplementedError, "Pathlike objects must implement [] access on their points, returning a new instance"
end

#approximates?(other, delta) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/draught/pathlike.rb', line 40

def approximates?(other, delta)
  return false if number_of_points != other.number_of_points
  points.zip(other.points).all? { |a, b| a.approximates?(b, delta) }
end

#box_typeObject



53
54
55
# File 'lib/draught/pathlike.rb', line 53

def box_type
  [:path]
end

#containersObject



49
50
51
# File 'lib/draught/pathlike.rb', line 49

def containers
  []
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/draught/pathlike.rb', line 31

def empty?
  points.empty?
end

#firstObject



23
24
25
# File 'lib/draught/pathlike.rb', line 23

def first
  points.first
end

#lastObject



27
28
29
# File 'lib/draught/pathlike.rb', line 27

def last
  points.last
end

#number_of_pointsObject



19
20
21
# File 'lib/draught/pathlike.rb', line 19

def number_of_points
  points.length
end

#pathsObject



45
46
47
# File 'lib/draught/pathlike.rb', line 45

def paths
  []
end

#pointsObject

Raises:

  • (NotImplementedError)


3
4
5
# File 'lib/draught/pathlike.rb', line 3

def points
  raise NotImplementedError, "Pathlike objects must return an array of their points"
end

#transform(transformation) ⇒ Object

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/draught/pathlike.rb', line 11

def transform(transformation)
  raise NotImplementedError, "Pathlike objects must implement transformation by Affine transform or point-taking lambda"
end

#translate(vector) ⇒ Object

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/draught/pathlike.rb', line 7

def translate(vector)
  raise NotImplementedError, "Pathlike objects must implement translation by Vector"
end