Module: ComicWalker::ItemDecoder::Unknown

Defined in:
lib/comic_walker/item_decoder/unknown.rb

Class Method Summary collapse

Class Method Details

.calcPositionWithRest_(a, f, b, e) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)
  • e (Integer)

Returns:

  • (Integer)


85
86
87
# File 'lib/comic_walker/item_decoder/unknown.rb', line 85

def calcPositionWithRest_(a, f, b, e)
  a * e + (a >= f ? b : 0)
end

.calculate_moves(width, height, rect_width, rect_height, pattern) ⇒ Array<Hash>

Calculate moves.

Parameters:

  • width (Integer)

    Width of the image

  • height (Integer)

    Height of the image

  • rect_width (Integer)

    Width of the sub-image

  • rect_height (Integer)

    Height of the sub-image

  • pattern (Integer)

    pattern? integer ranging from 1 to 4

Returns:

  • (Array<Hash>)

    List of hash that represents a move



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/comic_walker/item_decoder/unknown.rb', line 15

def calculate_moves(width, height, rect_width, rect_height, pattern)
  wcnt = width / rect_width
  hcnt = height / rect_height
  width %= rect_width
  height %= rect_height
  moves = []
  w_t0 = wcnt - (43*pattern)%wcnt
  w_t1 =
    if w_t0 % wcnt == 0
      (wcnt - 4) % wcnt
    else
      w_t0
    end
  h_t0 = hcnt - 47 * pattern % hcnt;
  h_t1 =
    if h_t0 % hcnt == 0
      (hcnt - 4) % hcnt
    else
      h_t0;
    end

  if width > 0 && height > 0
    x = w_t1 * rect_width
    y = h_t1 * rect_height
    moves.push(srcX: x, srcY: y, destX: x, destY: y, width: width, height: height)
  end

  if height > 0
    wcnt.times do |j|
      l = calcXCoordinateXRest_(j, wcnt, pattern)
      k = calcYCoordinateXRest_(l, w_t1, h_t1, hcnt, pattern)
      destX = calcPositionWithRest_(l, w_t1, width, rect_width)
      destY = k * rect_height
      srcX = calcPositionWithRest_(j, w_t1, width, rect_width)
      srcY = h_t1 * rect_height
      moves.push(srcX: srcX, srcY: srcY, destX: destX, destY: destY, width: rect_width, height: height)
    end
  end
  if width > 0
    hcnt.times do |i|
      k = calcYCoordinateYRest_(i, hcnt, pattern)
      l = calcXCoordinateYRest_(k, w_t1, h_t1, wcnt, pattern)
      destX = l * rect_width
      destY = calcPositionWithRest_(k, h_t1, height, rect_height)
      srcX = w_t1 * rect_width
      srcY = calcPositionWithRest_(i, h_t1, height, rect_height)
      moves.push(srcX: srcX, srcY: srcY, destX: destX, destY: destY, width: width, height: rect_height)
    end
  end
  wcnt.times do |j|
    hcnt.times do |i|
      p = (j + 29 * pattern + 31 * i) % wcnt
      k = (i + 37 * pattern + 41 * p) % hcnt
      q = p >= calcXCoordinateYRest_(k, w_t1, h_t1, wcnt, pattern) ? width : 0
      m = k >= calcYCoordinateXRest_(p, w_t1, h_t1, hcnt, pattern) ? height : 0
      destX = p * rect_width + q
      destY = k * rect_height + m
      srcX = j * rect_width + (j >= w_t1 ? width : 0)
      srcY = i * rect_height + (i >= h_t1 ? height : 0)
      moves.push(srcX: srcX, srcY: srcY, destX: destX, destY: destY, width: rect_width, height: rect_height)
    end
  end
  moves
end

.calcXCoordinateXRest_(a, f, b) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)

Returns:

  • (Integer)


93
94
95
# File 'lib/comic_walker/item_decoder/unknown.rb', line 93

def calcXCoordinateXRest_(a, f, b)
  (a + 61 * b) % f
end

.calcXCoordinateYRest_(a, f, b, e, d) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)
  • e (Integer)
  • d (Integer)

Returns:

  • (Integer)


121
122
123
124
125
126
127
128
129
130
131
# File 'lib/comic_walker/item_decoder/unknown.rb', line 121

def calcXCoordinateYRest_(a, f, b, e, d)
  c = 1 == d % 2
  if a < b ? c : !c
    e -= f
    b = f
  else
    e = f
    b = 0
  end
  (a + 67*d + f + 71) % e + b
end

.calcYCoordinateXRest_(a, f, b, e, d) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)
  • e (Integer)
  • d (Integer)

Returns:

  • (Integer)


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/comic_walker/item_decoder/unknown.rb', line 103

def calcYCoordinateXRest_(a, f, b, e, d)
  c = 1 == d % 2
  if a < f ? c : !c
    e = b
    f = 0
  else
    e -= b
    f = b
  end
  (a + 53*d + 59*b) % e + f
end

.calcYCoordinateYRest_(a, f, b) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)

Returns:

  • (Integer)


137
138
139
# File 'lib/comic_walker/item_decoder/unknown.rb', line 137

def calcYCoordinateYRest_(a, f, b)
  (a + 73*b) % f
end