Class: Miyako::RectStruct
- Defined in:
- lib/Miyako/API/struct_rect.rb
Overview
矩形情報のための構造体クラス
矩形変更メソッドを追加
Instance Method Summary collapse
-
#*(other) ⇒ Object
インスタンスのかけ算 もう一方が整数のとき、x,yにotherを掛けたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を掛けたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#+(other) ⇒ Object
インスタンスの足し算 もう一方が整数のとき、x,yにotherを足したものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を足したものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#-(other) ⇒ Object
インスタンスの引き算 もう一方が整数のとき、x,yからotherを引いたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を引いたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#/(other) ⇒ Object
インスタンスの割り算 もう一方が整数のとき、x,yからotherを割ったものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を割ったものを返す それ以外の時は例外が発生する 自分自身の値は変わらない other:: 整数もしくはPoint構造体 返却値:: Point構造体.
-
#between?(x, y) ⇒ Boolean
指定の座標が矩形の範囲内かを問い合わせる x:: 指定のx座標 y:: 指定のy座標 返却値:: 座標が矩形の範囲内ならtrueを返す.
-
#in_range?(x, y) ⇒ Boolean
指定の座標が矩形の範囲内かを問い合わせる x:: 指定のx座標 y:: 指定のy座標 返却値:: 座標が矩形の範囲内ならtrueを返す.
-
#move(dx, dy) ⇒ Object
位置を変更したインスタンスを返す(変化量を指定) 引数で指定したぶん移動させたときの位置を新しくインスタンスを生成して返す 自分自身の値は変わらない dx:: 移動量(x方向)。単位はピクセル dy:: 移動量(y方向)。単位はピクセル 返却値:: 自分自身の複製を更新したインスタンス.
-
#move!(dx, dy) ⇒ Object
位置を変更する(変化量を指定) ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す dx:: 移動量(x方向)。単位はピクセル dy:: 移動量(y方向)。単位はピクセル 返却値:: 自分自身を返す.
-
#move_to(x, y) ⇒ Object
位置を変更したインスタンスを返す(位置指定) 引数で指定したぶん移動させたときの位置を新しくインスタンスを生成して返す 自分自身の値は変わらない x:: 移動先位置(x方向)。単位はピクセル y:: 移動先位置(y方向)。単位はピクセル 返却値:: 自分自身の複製を更新したインスタンス.
-
#move_to!(x, y) ⇒ Object
位置を変更する(位置指定) ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す x:: 移動先位置(x方向)。単位はピクセル y:: 移動先位置(y方向)。単位はピクセル 返却値:: 自分自身を返す.
-
#pos ⇒ Object
矩形の左上位置部分のみ返す 返却値:: Position構造体のインスタンス.
-
#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:: 高さ変更。単位はピクセル 返却値:: 自分自身を返す.
-
#size ⇒ Object
矩形の大きさのみ返す 返却値:: Size構造体のインスタンス.
-
#to_ary ⇒ Object
矩形情報を配列に変換する [left, top, width, height]の配列を生成して返す。 返却値:: 生成した配列.
-
#to_square ⇒ Object
矩形情報をSquare構造体に変換する 返却値:: 生成したSquare構造体.
Instance Method Details
#*(other) ⇒ Object
インスタンスのかけ算
もう一方が整数のとき、x,yにotherを掛けたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を掛けたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない
- other
-
整数もしくはPoint構造体
- 返却値
-
Point構造体
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/Miyako/API/struct_rect.rb', line 148 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
インスタンスの足し算
もう一方が整数のとき、x,yにotherを足したものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を足したものを返す それ以外の時は例外が発生する 自分自身の値は変わらない
- other
-
整数もしくはPoint構造体
- 返却値
-
Point構造体
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/Miyako/API/struct_rect.rb', line 106 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
インスタンスの引き算
もう一方が整数のとき、x,yからotherを引いたものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を引いたものを返す それ以外の時は例外が発生する 自分自身の値は変わらない
- other
-
整数もしくはPoint構造体
- 返却値
-
Point構造体
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/Miyako/API/struct_rect.rb', line 127 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
インスタンスの割り算
もう一方が整数のとき、x,yからotherを割ったものを返す Point構造体や配列など、[]メソッドがつかえるもののとき、x,y同士を割ったものを返す それ以外の時は例外が発生する 自分自身の値は変わらない
- other
-
整数もしくはPoint構造体
- 返却値
-
Point構造体
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/Miyako/API/struct_rect.rb', line 169 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 |
#between?(x, y) ⇒ Boolean
指定の座標が矩形の範囲内かを問い合わせる
- x
-
指定のx座標
- y
-
指定のy座標
- 返却値
-
座標が矩形の範囲内ならtrueを返す
197 198 199 |
# File 'lib/Miyako/API/struct_rect.rb', line 197 def between?(x, y) return in_range?(x, y) end |
#in_range?(x, y) ⇒ Boolean
指定の座標が矩形の範囲内かを問い合わせる
- x
-
指定のx座標
- y
-
指定のy座標
- 返却値
-
座標が矩形の範囲内ならtrueを返す
189 190 191 |
# File 'lib/Miyako/API/struct_rect.rb', line 189 def in_range?(x, y) return (x >= self[0] && y >= self[1] && x < self[0] + self[2] && y < self[1] + self[3]) end |
#move(dx, dy) ⇒ Object
位置を変更したインスタンスを返す(変化量を指定)
引数で指定したぶん移動させたときの位置を新しくインスタンスを生成して返す 自分自身の値は変わらない
- dx
-
移動量(x方向)。単位はピクセル
- dy
-
移動量(y方向)。単位はピクセル
- 返却値
-
自分自身の複製を更新したインスタンス
49 50 51 |
# File 'lib/Miyako/API/struct_rect.rb', line 49 def move(dx, dy) self.dup.move!(dx, dy) end |
#move!(dx, dy) ⇒ Object
位置を変更する(変化量を指定)
ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
- dx
-
移動量(x方向)。単位はピクセル
- dy
-
移動量(y方向)。単位はピクセル
- 返却値
-
自分自身を返す
32 33 |
# File 'lib/Miyako/API/struct_rect.rb', line 32 def move!(dx, dy) end |
#move_to(x, y) ⇒ Object
位置を変更したインスタンスを返す(位置指定)
引数で指定したぶん移動させたときの位置を新しくインスタンスを生成して返す 自分自身の値は変わらない
- x
-
移動先位置(x方向)。単位はピクセル
- y
-
移動先位置(y方向)。単位はピクセル
- 返却値
-
自分自身の複製を更新したインスタンス
59 60 61 |
# File 'lib/Miyako/API/struct_rect.rb', line 59 def move_to(x, y) self.dup.move_to!(x, y) end |
#move_to!(x, y) ⇒ Object
位置を変更する(位置指定)
ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
- x
-
移動先位置(x方向)。単位はピクセル
- y
-
移動先位置(y方向)。単位はピクセル
- 返却値
-
自分自身を返す
40 41 |
# File 'lib/Miyako/API/struct_rect.rb', line 40 def move_to!(x, y) end |
#pos ⇒ Object
矩形の左上位置部分のみ返す
- 返却値
-
Position構造体のインスタンス
203 204 205 |
# File 'lib/Miyako/API/struct_rect.rb', line 203 def pos return Point.new(self[0], self[1]) end |
#resize(dw, dh) ⇒ Object
サイズを変更したインスタンスを返す(変化量を指定)
引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない
- dw
-
幅変更。単位はピクセル
- dh
-
高さ変更。単位はピクセル
- 返却値
-
自分自身の複製を更新したインスタンス
85 86 87 |
# File 'lib/Miyako/API/struct_rect.rb', line 85 def resize(dw, dh) self.dup.resize!(dw,dh) end |
#resize!(dw, dh) ⇒ Object
サイズを変更する(変化量を指定)
ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
- dw
-
幅変更。単位はピクセル
- dh
-
高さ変更。単位はピクセル
- 返却値
-
自分自身を返す
68 69 |
# File 'lib/Miyako/API/struct_rect.rb', line 68 def resize!(dw, dh) end |
#resize_to(w, h) ⇒ Object
サイズを変更したインスタンスを返す
引数で指定したぶん変えたときの大きさを新しくインスタンスを生成して返す 自分自身の値は変わらない
- w
-
幅変更。単位はピクセル
- h
-
高さ変更。単位はピクセル
- 返却値
-
自分自身の複製を更新したインスタンス
95 96 97 |
# File 'lib/Miyako/API/struct_rect.rb', line 95 def resize_to(w, h) self.dup.resize_to!(w,h) end |
#resize_to!(w, h) ⇒ Object
サイズを変更する
ブロックを渡したとき、ブロックの評価した結果、偽になったときは移動させた値を元に戻す
- w
-
幅変更。単位はピクセル
- h
-
高さ変更。単位はピクセル
- 返却値
-
自分自身を返す
76 77 |
# File 'lib/Miyako/API/struct_rect.rb', line 76 def resize_to!(w, h) end |
#size ⇒ Object
矩形の大きさのみ返す
- 返却値
-
Size構造体のインスタンス
209 210 211 |
# File 'lib/Miyako/API/struct_rect.rb', line 209 def size return Size.new(self[2], self[3]) end |
#to_ary ⇒ Object
矩形情報を配列に変換する
[left, top, width, height]の配列を生成して返す。
- 返却値
-
生成した配列
216 217 218 |
# File 'lib/Miyako/API/struct_rect.rb', line 216 def to_ary [self[0], self[1], self[2], self[3]] end |