Class: Miyako::SizeStruct
- Defined in:
- lib/Miyako/API/struct_size.rb
Overview
サイズ情報のための構造体クラス
サイズ変更メソッドを追加
Instance Method Summary collapse
-
#*(other) ⇒ Object
インスタンスのかけ算 もう一方が整数のとき、w,hにotherを掛けたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を掛けたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#+(other) ⇒ Object
インスタンスの足し算 もう一方が整数のとき、w,hにotherを足したものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を足したものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#-(other) ⇒ Object
インスタンスの引き算 もう一方が整数のとき、w,hからotherを引いたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を引いたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#/(other) ⇒ Object
インスタンスの割り算 もう一方が整数のとき、w,hからotherを割ったものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を割ったものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#resize(dw, dh) ⇒ Object
サイズを変更したインスタンスを返す(変化量を指定) 引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない dw:: 幅変更。単位はピクセル dh:: 高さ変更。単位はピクセル 返却値:: 自分自身の複製を更新したインスタンス.
-
#resize!(dw, dh) ⇒ Object
サイズを変更する(変化量を指定) ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す dw:: 幅変更。単位はピクセル dh:: 高さ変更。単位はピクセル 返却値:: 自分自身を返す.
-
#resize_to(w, h) ⇒ Object
サイズを変更したインスタンスを返す 引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない w:: 幅変更。単位はピクセル h:: 高さ変更。単位はピクセル 返却値:: 自分自身の複製を更新したインスタンス.
-
#resize_to!(w, h) ⇒ Object
サイズを変更する ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す w:: 幅変更。単位はピクセル h:: 高さ変更。単位はピクセル 返却値:: 自分自身を返す.
-
#to_ary ⇒ Object
:nodoc:.
- #update!(obj) ⇒ Object
- #update_by_point!(obj) ⇒ Object
- #update_by_rect!(obj) ⇒ Object
- #update_by_size!(obj) ⇒ Object
- #update_by_square!(obj) ⇒ Object
Instance Method Details
#*(other) ⇒ Object
インスタンスのかけ算
もう一方が整数のとき、w,hにotherを掛けたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を掛けたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない
- other
-
整数もしくはPoint構造体
- 返却値
-
Point構造体
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/Miyako/API/struct_size.rb', line 138 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構造体
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/Miyako/API/struct_size.rb', line 96 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構造体
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/Miyako/API/struct_size.rb', line 117 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構造体
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/Miyako/API/struct_size.rb', line 159 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
-
高さ変更。単位はピクセル
- 返却値
-
自分自身の複製を更新したインスタンス
75 76 77 |
# File 'lib/Miyako/API/struct_size.rb', line 75 def resize(dw, dh) self.dup.resize!(dw,dh) end |
#resize!(dw, dh) ⇒ Object
サイズを変更する(変化量を指定)
ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
- dw
-
幅変更。単位はピクセル
- dh
-
高さ変更。単位はピクセル
- 返却値
-
自分自身を返す
58 59 |
# File 'lib/Miyako/API/struct_size.rb', line 58 def resize!(dw, dh) end |
#resize_to(w, h) ⇒ Object
サイズを変更したインスタンスを返す
引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない
- w
-
幅変更。単位はピクセル
- h
-
高さ変更。単位はピクセル
- 返却値
-
自分自身の複製を更新したインスタンス
85 86 87 |
# File 'lib/Miyako/API/struct_size.rb', line 85 def resize_to(w, h) self.dup.resize_to!(w,h) end |
#resize_to!(w, h) ⇒ Object
サイズを変更する
ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
- w
-
幅変更。単位はピクセル
- h
-
高さ変更。単位はピクセル
- 返却値
-
自分自身を返す
66 67 |
# File 'lib/Miyako/API/struct_size.rb', line 66 def resize_to!(w, h) end |
#to_ary ⇒ Object
:nodoc:
175 176 177 |
# File 'lib/Miyako/API/struct_size.rb', line 175 def to_ary #:nodoc: [self[0], self[1]] end |
#update!(obj) ⇒ Object
27 28 29 30 31 |
# File 'lib/Miyako/API/struct_size.rb', line 27 def update!(obj) self[0] = obj[0] self[1] = obj[1] self end |
#update_by_point!(obj) ⇒ Object
33 34 35 |
# File 'lib/Miyako/API/struct_size.rb', line 33 def update_by_point!(obj) self end |
#update_by_rect!(obj) ⇒ Object
41 42 43 44 45 |
# File 'lib/Miyako/API/struct_size.rb', line 41 def update_by_rect!(obj) self[0] = obj[2] self[1] = obj[3] self end |
#update_by_size!(obj) ⇒ Object
37 38 39 |
# File 'lib/Miyako/API/struct_size.rb', line 37 def update_by_size!(obj) update!(obj) end |
#update_by_square!(obj) ⇒ Object
47 48 49 50 51 |
# File 'lib/Miyako/API/struct_size.rb', line 47 def update_by_square!(obj) self[0] = obj[2]-obj[0]+1 self[1] = obj[3]-obj[1]+1 self end |