Class: Miyako::SizeStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/Miyako/API/struct_size.rb

Overview

サイズ情報のための構造体クラス

サイズ変更メソッドを追加

Instance Method Summary collapse

Instance Method Details

#*(other) ⇒ Object

インスタンスのかけ算

もう一方が整数のとき、w,hにotherを掛けたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を掛けたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない

other

整数もしくはPoint構造体

返却値

Point構造体



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/Miyako/API/struct_size.rb', line 112

def *(other)
  ret = self.dup
  if other.kind_of?(Numeric)
    ret[0] *= other
    ret[1] *= other
  elsif other.methods.include?(:[])
    ret[0] *= other[0]
    ret[1] *= other[1]
  else
    raise MiyakoError, "this parameter cannot access!"
  end
  ret
end

#+(other) ⇒ Object

インスタンスの足し算

もう一方が整数のとき、w,hにotherを足したものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を足したものを返す それ以外の時は例外が発生する 自分自身の値は変わらない

other

整数もしくはPoint構造体

返却値

Point構造体



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/Miyako/API/struct_size.rb', line 70

def +(other)
  ret = self.dup
  if other.kind_of?(Numeric)
    ret[0] += other
    ret[1] += other
  elsif other.methods.include?(:[])
    ret[0] += other[0]
    ret[1] += other[1]
  else
    raise MiyakoError, "this parameter cannot access!"
  end
  ret
end

#-(other) ⇒ Object

インスタンスの引き算

もう一方が整数のとき、w,hからotherを引いたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を引いたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない

other

整数もしくはPoint構造体

返却値

Point構造体



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/Miyako/API/struct_size.rb', line 91

def -(other)
  ret = self.dup
  if other.kind_of?(Numeric)
    ret[0] -= other
    ret[1] -= other
  elsif other.methods.include?(:[])
    ret[0] -= other[0]
    ret[1] -= other[1]
  else
    raise MiyakoError, "this parameter cannot access!"
  end
  ret
end

#/(other) ⇒ Object

インスタンスの割り算

もう一方が整数のとき、w,hからotherを割ったものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を割ったものを返す それ以外の時は例外が発生する 自分自身の値は変わらない

other

整数もしくはPoint構造体

返却値

Point構造体



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/Miyako/API/struct_size.rb', line 133

def /(other)
  ret = self.dup
  if other.kind_of?(Numeric)
    raise MiyakoValueError, "0 div!" if other == 0
    ret[0] /= other
    ret[1] /= other
  elsif other.methods.include?(:[])
    raise MiyakoValueError, "0 div!" if (other[0] == 0 || other[1] == 0)
    ret[0] /= other[0]
    ret[1] /= other[1]
  else
    raise MiyakoError, "this parameter cannot access!"
  end
  ret
end

#resize(dw, dh) ⇒ Object

サイズを変更したインスタンスを返す(変化量を指定)

引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない

dw

幅変更。単位はピクセル

dh

高さ変更。単位はピクセル

返却値

自分自身の複製を更新したインスタンス



49
50
51
# File 'lib/Miyako/API/struct_size.rb', line 49

def resize(dw, dh)
  self.dup.resize!(dw,dh)
end

#resize!(dw, dh) ⇒ Object

サイズを変更する(変化量を指定)

ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す

dw

幅変更。単位はピクセル

dh

高さ変更。単位はピクセル

返却値

自分自身を返す



32
33
# File 'lib/Miyako/API/struct_size.rb', line 32

def resize!(dw, dh)
end

#resize_to(w, h) ⇒ Object

サイズを変更したインスタンスを返す

引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない

w

幅変更。単位はピクセル

h

高さ変更。単位はピクセル

返却値

自分自身の複製を更新したインスタンス



59
60
61
# File 'lib/Miyako/API/struct_size.rb', line 59

def resize_to(w, h)
  self.dup.resize_to!(w,h)
end

#resize_to!(w, h) ⇒ Object

サイズを変更する

ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す

w

幅変更。単位はピクセル

h

高さ変更。単位はピクセル

返却値

自分自身を返す



40
41
# File 'lib/Miyako/API/struct_size.rb', line 40

def resize_to!(w, h)
end

#to_aryObject

:nodoc:



149
150
151
# File 'lib/Miyako/API/struct_size.rb', line 149

def to_ary #:nodoc:
  [self[0], self[1]]
end