Class: XRVG::Shape

Inherits:
Object show all
Includes:
Attributable
Defined in:
lib/shape.rb

Overview

To provide a set of services a shape class must provide

Direct Known Subclasses

Curve

Instance Method Summary collapse

Methods included from Attributable

included, #initialize

Instance Method Details

#contour(*args) ⇒ Object

must return the contour of the shape, of Curve type

abstract

not yet used

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/shape.rb', line 24

def contour( *args )
  raise NotImplementedError.new("#{self.class.name}#contour is an abstract method.")
end

#default_styleObject

return the default style for a Shape instance

is done on instance, because for Curve for example, strokewidth is proportional to length



55
56
57
# File 'lib/shape.rb', line 55

def default_style()
  return Style[:fill, Color.black ]
end

#sizeObject

compute size of the shape, from viewbox



47
48
49
50
# File 'lib/shape.rb', line 47

def size()
  xmin, ymin, xmax, ymax = self.viewbox
  return [xmax-xmin, ymax-ymin]
end

#surfaceObject

compute the “surface” of the viewbox of the shape

use size method



62
63
64
65
# File 'lib/shape.rb', line 62

def surface
  width, height = self.size
  return width * height
end

#svgObject

must return the svg description of the shape

abstract

must be defined

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/shape.rb', line 33

def svg()
  raise NotImplementedError.new("#{self.class.name}#svg is an abstract method.")
end

#viewboxObject

must return the enclosing box of the shape, that is [xmin, ymin, xmax, ymax]

abstract

must be defined

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/shape.rb', line 42

def viewbox()
  raise NotImplementedError.new("#{self.class.name}#viewbox is an abstract method.")
end