Class: Moon::Painter3

Inherits:
Object show all
Defined in:
lib/moon/packages/data_painter/painter3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Painter3

Returns a new instance of Painter3.

Parameters:


7
8
9
# File 'lib/moon/packages/data_painter/painter3.rb', line 7

def initialize(target)
  @target = target
end

Instance Attribute Details

#targetMoon::DataMatrix (readonly)

Returns:


4
5
6
# File 'lib/moon/packages/data_painter/painter3.rb', line 4

def target
  @target
end

Instance Method Details

#clear(n = nil) ⇒ Object

Replace all data with the default

Parameters:


21
22
23
# File 'lib/moon/packages/data_painter/painter3.rb', line 21

def clear(n = nil)
  fill(n || @target.default)
end

#fill(n) ⇒ Object

Replace all the data with (n)

Parameters:


14
15
16
# File 'lib/moon/packages/data_painter/painter3.rb', line 14

def fill(n)
  target.map_with_xyz { |_, _, _, _| n }
end

#fill_cube(cube, value) ⇒ Object #fill_cube(x, y, z, w, h, d, v) ⇒ Object

Overloads:


75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/moon/packages/data_painter/painter3.rb', line 75

def fill_cube(*args)
  case args.size
  when 2
    cube, value = *args
    x, y, z, w, h, d = *cube
    fill_cube_xyzwhd(x, y, z, w, h, d, value)
  when 7
    fill_cube_xyzwhd(*args)
  else
    raise ArgumentError,
          "wrong argument count #{args.size} (expected 2:(rect, value) or 5:(x, y, w, h, value))"
  end
end

#fill_cube_xyzwhd(x, y, z, w, h, d, v) ⇒ self

Parameters:

Returns:

  • (self)

60
61
62
# File 'lib/moon/packages/data_painter/painter3.rb', line 60

def fill_cube_xyzwhd(x, y, z, w, h, d, v)
  map_cube(x, y, z, w, h, d) { v }
end

#map_cube(cube) ⇒ self #map_cube(x, y, z, w, h, depth) ⇒ self

Overloads:

Yield Parameters:

Yield Returns:

Returns:

  • (self)

40
41
42
43
44
45
46
47
48
49
50
# File 'lib/moon/packages/data_painter/painter3.rb', line 40

def map_cube(*args)
  x, y, z, w, h, d = *Cube.extract(args.size > 1 ? args : args.first)
  d.times do |k|
    h.times do |j|
      w.times do |i|
        target[x + i, y + j, z + k] = yield target[x + i, y + j, z + k], i, j, k
      end
    end
  end
  self
end