Class: CGRect
- Inherits:
-
Object
- Object
- CGRect
- Defined in:
- lib/geomotion/cg_rect.rb
Class Method Summary collapse
- .infinite ⇒ Object
-
.layout(rect1, options) ⇒ Object
OPTIONS: [:above, :below, :left_of, :right_of, :margins] :margins is array of [top, right, bottom, left] EX CGRect.layout(rect1, above: rect2, left_of: rect3, margins: [0, 10, 20, 0]).
-
.make(options = {}) ⇒ Object
CGRect.make # default rect: {x: 0, y: 0, size: height:0} # aka CGRectZero CGRect.make(x: 10, y: 30) # default size: [0, 0] CGRect.make(x: 10, y: 30, width:100, height: 20).
- .null ⇒ Object
- .zero ⇒ Object (also: empty)
Instance Method Summary collapse
- #*(scale) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
-
#/(scale) ⇒ Object
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many errors.
- #==(rect) ⇒ Object
-
#above(margin = 0, options = {}) ⇒ Object
adjacent rects.
-
#apply(options) ⇒ Object
most rect modifiers call this method in one way or another.
- #before(margin = 0, options = {}) ⇒ Object
- #below(margin = 0, options = {}) ⇒ Object
- #beside(margin = 0, options = {}) ⇒ Object (also: #after)
- #bottom_center(absolute = false) ⇒ Object
- #bottom_left(absolute = false) ⇒ Object
- #bottom_right(absolute = false) ⇒ Object
- #center(absolute = false) ⇒ Object
- #center_left(absolute = false) ⇒ Object
- #center_right(absolute = false) ⇒ Object
- #centered_in(rect, absolute = false) ⇒ Object
- #contains?(rect_or_point) ⇒ Boolean
- #down(dist = nil, options = {}) ⇒ Object
- #empty? ⇒ Boolean
-
#from_bottom(options = {}) ⇒ Object
Create a rect inside the receiver, on the bottom side.
-
#from_left(options = {}) ⇒ Object
Create a rect inside the receiver, on the left side.
-
#from_right(options = {}) ⇒ Object
Create a rect inside the receiver, on the right side.
-
#from_top(options = {}) ⇒ Object
Create a rect inside the receiver, on the top side.
- #grow(size, options = nil) ⇒ Object
- #grow_height(amount, options = {}) ⇒ Object
- #grow_left(amount, options = {}) ⇒ Object
- #grow_up(amount, options = {}) ⇒ Object
- #grow_width(amount, options = {}) ⇒ Object
- #height(setter = nil, options = nil) ⇒ Object
- #height=(_height) ⇒ Object
- #infinite? ⇒ Boolean
- #inset(insets) ⇒ Object
- #inspect ⇒ Object
- #intersection_with(rect) ⇒ Object
- #intersects?(rect) ⇒ Boolean
-
#left(dist = nil, options = {}) ⇒ Object
modified rects.
- #max_x ⇒ Object
- #max_y ⇒ Object
- #mid_x ⇒ Object
- #mid_y ⇒ Object
-
#min_x ⇒ Object
bounds.
- #min_y ⇒ Object
- #null? ⇒ Boolean
- #offset(point_or_x, y = nil) ⇒ Object
- #right(dist = nil, options = {}) ⇒ Object
-
#round ⇒ Object
others.
- #shorter(dist, options = {}) ⇒ Object (also: #shrink_up)
- #shrink(size, options = nil) ⇒ Object
- #shrink_down(amount, options = {}) ⇒ Object
- #shrink_height(amount, options = {}) ⇒ Object
- #shrink_right(amount, options = {}) ⇒ Object
- #shrink_width(amount, options = {}) ⇒ Object
- #taller(dist, options = {}) ⇒ Object (also: #grow_down)
- #thinner(dist, options = {}) ⇒ Object (also: #shrink_left)
- #top_center(absolute = false) ⇒ Object
- #top_left(absolute = false) ⇒ Object
- #top_right(absolute = false) ⇒ Object
- #union_with(rect) ⇒ Object
- #up(dist = nil, options = {}) ⇒ Object
- #wider(dist, options = {}) ⇒ Object (also: #grow_right)
- #width(setter = nil, options = nil) ⇒ Object
- #width=(_width) ⇒ Object
-
#x(setter = nil, options = nil) ⇒ Object
getters/setters.
- #x=(_x) ⇒ Object
- #y(setter = nil, options = nil) ⇒ Object
- #y=(_y) ⇒ Object
Class Method Details
.infinite ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/geomotion/cg_rect.rb', line 40 def infinite # This actually returns the not-very-infinite value of: # [[-1.7014114289565e+38, -1.7014114289565e+38], [3.402822857913e+38, 3.402822857913e+38]] # originally this method returned [[-Infinity, -Infinity], [Infinity, Infinity]], # but that rect ended up returning `false` for any point in the method # CGRect.infinite.contains?(point). CGRectInfinite returns `true` for any # (sensible) point, so we'll go with that instead CGRectInfinite.dup end |
.layout(rect1, options) ⇒ Object
OPTIONS: [:above, :below, :left_of, :right_of, :margins]
:margins is array of [top, right, bottom, left]
EX CGRect.layout(rect1, above: rect2, left_of: rect3, margins: [0, 10, 20, 0])
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/geomotion/cg_rect.rb', line 53 def layout(rect1, ) if .empty? p "No options provided in #{self.class}.layout" return rect1 end rect = self.new rect.size = rect1.size [:margins] ||= [] margins = {} [:top, :right, :bottom, :left].each_with_index do |margin, index| margins[margin] = [:margins][index] || 0 end rect.y = [:above].up(rect.height + margins[:bottom]).y if [:above] rect.y = [:below].below(margins[:top]).y if [:below] rect.x = [:left_of].left(rect.width + margins[:right]).x if [:left_of] rect.x = [:right_of].beside(margins[:left]).x if [:right_of] rect end |
.make(options = {}) ⇒ Object
CGRect.make # default rect: {x: 0, y: 0, size: height:0}
# aka CGRectZero
CGRect.make(x: 10, y: 30) # default size: [0, 0] CGRect.make(x: 10, y: 30, width:100, height: 20)
point = CGPoint.make(x: 10, y: 30) size = CGSize.make(width: 100, height: 20) CGRect.make(origin: point, size: size)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/geomotion/cg_rect.rb', line 12 def make( = {}) if [:origin] x = [:origin][0] y = [:origin][1] else x = [:x] || 0 y = [:y] || 0 end if [:size] w = [:size][0] h = [:size][1] else w = [:width] || 0 h = [:height] || 0 end self.new([x, y], [w, h]) end |
.null ⇒ Object
35 36 37 38 |
# File 'lib/geomotion/cg_rect.rb', line 35 def null # Don't just return CGRectNull; can be mutated CGRect.new([Float::INFINITY, Float::INFINITY], [0, 0]) end |
.zero ⇒ Object Also known as: empty
30 31 32 |
# File 'lib/geomotion/cg_rect.rb', line 30 def zero CGRect.new([0, 0], [0, 0]) end |
Instance Method Details
#*(scale) ⇒ Object
489 490 491 492 493 494 495 496 |
# File 'lib/geomotion/cg_rect.rb', line 489 def *(scale) case scale when Numeric return CGRect.new(self.origin, self.size * scale) else super end end |
#+(other) ⇒ Object
474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/geomotion/cg_rect.rb', line 474 def +(other) case other when CGRect return self.union_with(other) when CGSize return CGRect.new([self.origin.x, self.origin.y], [self.size.width + other.width, self.size.height + other.height]) when CGPoint return self.offset(other.x, other.y) when UIOffset return self.offset(other.horizontal, other.vertical) when UIEdgeInsets return self.inset(other) end end |
#-(other) ⇒ Object
647 648 649 |
# File 'lib/geomotion/cg_rect.rb', line 647 def -(other) self.+(-other) end |
#-@ ⇒ Object
643 644 645 |
# File 'lib/geomotion/cg_rect.rb', line 643 def -@ CGRect.new(-self.origin, -self.size) end |
#/(scale) ⇒ Object
it is tempting to define this as self * (1.0/scale) but floating point errors result in too many errors
500 501 502 503 504 505 506 507 |
# File 'lib/geomotion/cg_rect.rb', line 500 def /(scale) case scale when Numeric return CGRect.new(self.origin, self.size / scale) else super end end |
#==(rect) ⇒ Object
639 640 641 |
# File 'lib/geomotion/cg_rect.rb', line 639 def ==(rect) rect.is_a?(CGRect) && CGRectEqualToRect(self, rect) end |
#above(margin = 0, options = {}) ⇒ Object
adjacent rects
313 314 315 316 317 318 319 320 321 |
# File 'lib/geomotion/cg_rect.rb', line 313 def above(margin = 0, ={}) margin, = 0, margin if margin.is_a?(NSDictionary) margin = .delete(:margin) if .key?(:margin) height = [:height] || self.size.height self.apply({ up: height + margin }.merge()) end |
#apply(options) ⇒ Object
most rect modifiers call this method in one way or another
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/geomotion/cg_rect.rb', line 166 def apply() rect = CGRectStandardize(CGRect.new(self.origin, self.size)) .each do |method, value| case method when :left rect.origin.x -= value when :right rect.origin.x += value when :up rect.origin.y -= value when :down rect.origin.y += value when :wider, :grow_right rect.size.width += value when :thinner, :shrink_left rect.size.width -= value when :taller, :grow_down rect.size.height += value when :shorter, :shrink_up rect.size.height -= value when :x rect.origin.x = value when :y rect.origin.y = value when :origin rect.origin = value when :width rect.size.width = value when :height rect.size.height = value when :size rect.size = value when :grow rect = rect.grow(value) when :grow_up rect.size.height += value rect.origin.y -= value when :shrink_down rect.size.height -= value rect.origin.y += value when :grow_left rect.size.width += value rect.origin.x -= value when :shrink_right rect.size.width -= value rect.origin.x += value when :grow_width rect = rect.grow_width(value) when :grow_height rect = rect.grow_height(value) when :shrink rect = rect.shrink(value) when :shrink_width rect = rect.shrink_width(value) when :shrink_height rect = rect.shrink_height(value) when :offset rect = rect.offset(value) else raise "Unknow option #{method}" end end return rect end |
#before(margin = 0, options = {}) ⇒ Object
332 333 334 335 336 337 338 339 340 |
# File 'lib/geomotion/cg_rect.rb', line 332 def before(margin = 0, ={}) margin, = 0, margin if margin.is_a?(NSDictionary) margin = .delete(:margin) if .key?(:margin) width = [:width] || self.size.width self.apply({ left: width + margin }.merge()) end |
#below(margin = 0, options = {}) ⇒ Object
323 324 325 326 327 328 329 330 |
# File 'lib/geomotion/cg_rect.rb', line 323 def below(margin = 0, ={}) margin, = 0, margin if margin.is_a?(NSDictionary) margin = .delete(:margin) if .key?(:margin) self.apply({ down: self.size.height + margin }.merge()) end |
#beside(margin = 0, options = {}) ⇒ Object Also known as: after
342 343 344 345 346 347 348 349 |
# File 'lib/geomotion/cg_rect.rb', line 342 def beside(margin = 0, ={}) margin, = 0, margin if margin.is_a?(NSDictionary) margin = .delete(:margin) if .key?(:margin) self.apply({ right: self.size.width + margin }.merge()) end |
#bottom_center(absolute = false) ⇒ Object
453 454 455 |
# File 'lib/geomotion/cg_rect.rb', line 453 def bottom_center(absolute = false) cgrect_offset(absolute) + CGPoint.new(self.size.width / 2, self.size.height) end |
#bottom_left(absolute = false) ⇒ Object
457 458 459 |
# File 'lib/geomotion/cg_rect.rb', line 457 def bottom_left(absolute = false) cgrect_offset(absolute) + CGPoint.new(0, self.size.height) end |
#bottom_right(absolute = false) ⇒ Object
449 450 451 |
# File 'lib/geomotion/cg_rect.rb', line 449 def bottom_right(absolute = false) cgrect_offset(absolute) + CGPoint.new(self.size.width, self.size.height) end |
#center(absolute = false) ⇒ Object
429 430 431 |
# File 'lib/geomotion/cg_rect.rb', line 429 def center(absolute = false) cgrect_offset(absolute) + CGPoint.new(self.size.width / 2, self.size.height / 2) end |
#center_left(absolute = false) ⇒ Object
461 462 463 |
# File 'lib/geomotion/cg_rect.rb', line 461 def center_left(absolute = false) cgrect_offset(absolute) + CGPoint.new(0, self.size.height / 2) end |
#center_right(absolute = false) ⇒ Object
445 446 447 |
# File 'lib/geomotion/cg_rect.rb', line 445 def center_right(absolute = false) cgrect_offset(absolute) + CGPoint.new(self.size.width, self.size.height / 2) end |
#centered_in(rect, absolute = false) ⇒ Object
470 471 472 |
# File 'lib/geomotion/cg_rect.rb', line 470 def centered_in(rect, absolute = false) self.size.centered_in(rect, absolute) end |
#contains?(rect_or_point) ⇒ Boolean
628 629 630 631 632 633 634 635 636 637 |
# File 'lib/geomotion/cg_rect.rb', line 628 def contains?(rect_or_point) case rect_or_point when CGPoint CGRectContainsPoint(self, rect_or_point) when CGRect CGRectContainsRect(self, rect_or_point) else super # raises an error end end |
#down(dist = nil, options = {}) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/geomotion/cg_rect.rb', line 268 def down(dist=nil, ={}) if dist.nil? NSLog("Using the default value of `0` in `CGRect#down` is deprecated.") dist = 0 end raise "You must specify an amount in `CGRect#down`" unless dist.is_a?(Numeric) self.apply({ down: dist }.merge()) end |
#empty? ⇒ Boolean
607 608 609 |
# File 'lib/geomotion/cg_rect.rb', line 607 def empty? CGRectIsEmpty(self) end |
#from_bottom(options = {}) ⇒ Object
Create a rect inside the receiver, on the bottom side. If ‘margin` is supplied, the rect will be moved that number of points up.
401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/geomotion/cg_rect.rb', line 401 def from_bottom(={}) height = [:height] margin = .delete(:margin) || 0 raise "You must specify a height in `CGRect#from_bottom`" unless height offset = cgrect_offset(.delete(:absolute)) self.apply({ x: offset.x, y: offset.y + self.size.height - height - margin, width: self.size.width, height: height }.merge()) end |
#from_left(options = {}) ⇒ Object
Create a rect inside the receiver, on the left side. If ‘margin` is supplied, the rect will be moved that number of points to the right.
356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/geomotion/cg_rect.rb', line 356 def from_left(={}) width = [:width] margin = .delete(:margin) || 0 raise "You must specify a width in `CGRect#from_left`" unless width offset = cgrect_offset(.delete(:absolute)) self.apply({ x: offset.x + margin, y: offset.y, height: self.size.height, width: width }.merge()) end |
#from_right(options = {}) ⇒ Object
Create a rect inside the receiver, on the right side. If ‘margin` is supplied, the rect will be moved that number of points to the left.
371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/geomotion/cg_rect.rb', line 371 def from_right(={}) width = [:width] margin = .delete(:margin) || 0 raise "You must specify a width in `CGRect#from_right`" unless width offset = cgrect_offset(.delete(:absolute)) self.apply({ x: offset.x + self.size.width - width - margin, y: offset.y, height: self.size.height, width: width }.merge()) end |
#from_top(options = {}) ⇒ Object
Create a rect inside the receiver, on the top side. If ‘margin` is supplied, the rect will be moved that number of points down.
386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/geomotion/cg_rect.rb', line 386 def from_top(={}) height = [:height] margin = .delete(:margin) || 0 raise "You must specify a height in `CGRect#from_top`" unless height offset = cgrect_offset(.delete(:absolute)) self.apply({ x: offset.x, y: offset.y + margin, width: self.size.width, height: height }.merge()) end |
#grow(size, options = nil) ⇒ Object
529 530 531 532 533 534 535 536 537 538 |
# File 'lib/geomotion/cg_rect.rb', line 529 def grow(size, =nil) if size.is_a? Numeric size = CGSize.new(size, size) end rect = CGRectInset(self, -size[0], -size[1]) if return rect.apply() end return rect end |
#grow_height(amount, options = {}) ⇒ Object
564 565 566 |
# File 'lib/geomotion/cg_rect.rb', line 564 def grow_height(amount, ={}) return self.grow([0, amount], ) end |
#grow_left(amount, options = {}) ⇒ Object
542 543 544 545 546 547 548 |
# File 'lib/geomotion/cg_rect.rb', line 542 def grow_left(amount, ={}) raise "You must specify an amount in `CGRect#grow_left`" unless amount.is_a?(Numeric) self.apply({ grow_left: amount }.merge()) end |
#grow_up(amount, options = {}) ⇒ Object
552 553 554 555 556 557 558 |
# File 'lib/geomotion/cg_rect.rb', line 552 def grow_up(amount, ={}) raise "You must specify an amount in `CGRect#grow_up`" unless amount.is_a?(Numeric) self.apply({ grow_up: amount }.merge()) end |
#grow_width(amount, options = {}) ⇒ Object
560 561 562 |
# File 'lib/geomotion/cg_rect.rb', line 560 def grow_width(amount, ={}) return self.grow([amount, 0], ) end |
#height(setter = nil, options = nil) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/geomotion/cg_rect.rb', line 150 def height(setter=nil, =nil) if setter rect = CGRect.new(self.origin, [self.size.width, setter]) if return rect.apply() end return rect end return CGRectGetHeight(self) end |
#height=(_height) ⇒ Object
161 162 163 |
# File 'lib/geomotion/cg_rect.rb', line 161 def height=(_height) self.size.height = _height end |
#infinite? ⇒ Boolean
611 612 613 |
# File 'lib/geomotion/cg_rect.rb', line 611 def infinite? self.size.infinite? || CGRectEqualToRect(self, CGRectInfinite) end |
#inset(insets) ⇒ Object
517 518 519 |
# File 'lib/geomotion/cg_rect.rb', line 517 def inset(insets) UIEdgeInsetsInsetRect(self, insets) end |
#inspect ⇒ Object
651 652 653 |
# File 'lib/geomotion/cg_rect.rb', line 651 def inspect "#{self.class.name}([#{self.origin.x}, #{self.origin.y}], [#{self.size.width}, #{self.size.height}])" end |
#intersection_with(rect) ⇒ Object
509 510 511 |
# File 'lib/geomotion/cg_rect.rb', line 509 def intersection_with(rect) CGRectIntersection(self, rect) end |
#intersects?(rect) ⇒ Boolean
619 620 621 622 623 624 625 626 |
# File 'lib/geomotion/cg_rect.rb', line 619 def intersects?(rect) case rect when CGRect CGRectIntersectsRect(self, rect) else super # raises an error end end |
#left(dist = nil, options = {}) ⇒ Object
modified rects
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/geomotion/cg_rect.rb', line 232 def left(dist=nil, ={}) if dist.nil? NSLog("Using the default value of `0` in `CGRect#left` is deprecated.") dist = 0 end raise "You must specify an amount in `CGRect#left`" unless dist.is_a?(Numeric) self.apply({ left: dist }.merge()) end |
#max_x ⇒ Object
88 89 90 |
# File 'lib/geomotion/cg_rect.rb', line 88 def max_x CGRectGetMaxX(self) end |
#max_y ⇒ Object
100 101 102 |
# File 'lib/geomotion/cg_rect.rb', line 100 def max_y CGRectGetMaxY(self) end |
#mid_x ⇒ Object
84 85 86 |
# File 'lib/geomotion/cg_rect.rb', line 84 def mid_x CGRectGetMidX(self) end |
#mid_y ⇒ Object
96 97 98 |
# File 'lib/geomotion/cg_rect.rb', line 96 def mid_y CGRectGetMidY(self) end |
#min_x ⇒ Object
bounds
80 81 82 |
# File 'lib/geomotion/cg_rect.rb', line 80 def min_x CGRectGetMinX(self) end |
#min_y ⇒ Object
92 93 94 |
# File 'lib/geomotion/cg_rect.rb', line 92 def min_y CGRectGetMinY(self) end |
#null? ⇒ Boolean
615 616 617 |
# File 'lib/geomotion/cg_rect.rb', line 615 def null? CGRectIsNull(self) end |
#offset(point_or_x, y = nil) ⇒ Object
521 522 523 524 525 526 527 |
# File 'lib/geomotion/cg_rect.rb', line 521 def offset(point_or_x, y=nil) if y CGRectOffset(self, point_or_x, y) else CGRectOffset(self, point_or_x[0], point_or_x[1]) end end |
#right(dist = nil, options = {}) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/geomotion/cg_rect.rb', line 244 def right(dist=nil, ={}) if dist.nil? NSLog("Using the default value of `0` in `CGRect#right` is deprecated.") dist = 0 end raise "You must specify an amount in `CGRect#right`" unless dist.is_a?(Numeric) self.apply({ right: dist }.merge()) end |
#round ⇒ Object
others
466 467 468 |
# File 'lib/geomotion/cg_rect.rb', line 466 def round CGRect.new([self.origin.x.round, self.origin.y.round], [self.size.width.round, self.size.height.round]) end |
#shorter(dist, options = {}) ⇒ Object Also known as: shrink_up
304 305 306 307 308 309 310 |
# File 'lib/geomotion/cg_rect.rb', line 304 def shorter(dist, ={}) raise "You must specify an amount in `CGRect#shorter`" unless dist.is_a?(Numeric) self.apply({ shorter: dist }.merge()) end |
#shrink(size, options = nil) ⇒ Object
568 569 570 571 572 573 574 575 576 577 |
# File 'lib/geomotion/cg_rect.rb', line 568 def shrink(size, =nil) if size.is_a? Numeric size = CGSize.new(size, size) end rect = CGRectInset(self, size[0], size[1]) if return rect.apply() end return rect end |
#shrink_down(amount, options = {}) ⇒ Object
591 592 593 594 595 596 597 |
# File 'lib/geomotion/cg_rect.rb', line 591 def shrink_down(amount, ={}) raise "You must specify an amount in `CGRect#shrink_down`" unless amount.is_a?(Numeric) self.apply({ shrink_down: amount }.merge()) end |
#shrink_height(amount, options = {}) ⇒ Object
603 604 605 |
# File 'lib/geomotion/cg_rect.rb', line 603 def shrink_height(amount, ={}) return self.shrink([0, amount], ) end |
#shrink_right(amount, options = {}) ⇒ Object
581 582 583 584 585 586 587 |
# File 'lib/geomotion/cg_rect.rb', line 581 def shrink_right(amount, ={}) raise "You must specify an amount in `CGRect#shrink_right`" unless amount.is_a?(Numeric) self.apply({ shrink_right: amount }.merge()) end |
#shrink_width(amount, options = {}) ⇒ Object
599 600 601 |
# File 'lib/geomotion/cg_rect.rb', line 599 def shrink_width(amount, ={}) return self.shrink([amount, 0], ) end |
#taller(dist, options = {}) ⇒ Object Also known as: grow_down
296 297 298 299 300 301 302 |
# File 'lib/geomotion/cg_rect.rb', line 296 def taller(dist, ={}) raise "You must specify an amount in `CGRect#taller`" unless dist.is_a?(Numeric) self.apply({ taller: dist }.merge()) end |
#thinner(dist, options = {}) ⇒ Object Also known as: shrink_left
288 289 290 291 292 293 294 |
# File 'lib/geomotion/cg_rect.rb', line 288 def thinner(dist, ={}) raise "You must specify an amount in `CGRect#thinner`" unless dist.is_a?(Numeric) self.apply({ thinner: dist }.merge()) end |
#top_center(absolute = false) ⇒ Object
437 438 439 |
# File 'lib/geomotion/cg_rect.rb', line 437 def top_center(absolute = false) cgrect_offset(absolute) + CGPoint.new(self.size.width / 2, 0) end |
#top_left(absolute = false) ⇒ Object
433 434 435 |
# File 'lib/geomotion/cg_rect.rb', line 433 def top_left(absolute = false) cgrect_offset(absolute) + CGPoint.new(0, 0) end |
#top_right(absolute = false) ⇒ Object
441 442 443 |
# File 'lib/geomotion/cg_rect.rb', line 441 def top_right(absolute = false) cgrect_offset(absolute) + CGPoint.new(self.size.width, 0) end |
#union_with(rect) ⇒ Object
513 514 515 |
# File 'lib/geomotion/cg_rect.rb', line 513 def union_with(rect) CGRectUnion(self, rect) end |
#up(dist = nil, options = {}) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/geomotion/cg_rect.rb', line 256 def up(dist=nil, ={}) if dist.nil? NSLog("Using the default value of `0` in `CGRect#up` is deprecated.") dist = 0 end raise "You must specify an amount in `CGRect#up`" unless dist.is_a?(Numeric) self.apply({ up: dist }.merge()) end |
#wider(dist, options = {}) ⇒ Object Also known as: grow_right
280 281 282 283 284 285 286 |
# File 'lib/geomotion/cg_rect.rb', line 280 def wider(dist, ={}) raise "You must specify an amount in `CGRect#wider`" unless dist.is_a?(Numeric) self.apply({ wider: dist }.merge()) end |
#width(setter = nil, options = nil) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/geomotion/cg_rect.rb', line 135 def width(setter=nil, =nil) if setter rect = CGRect.new(self.origin, [setter, self.size.height]) if return rect.apply() end return rect end return CGRectGetWidth(self) end |
#width=(_width) ⇒ Object
146 147 148 |
# File 'lib/geomotion/cg_rect.rb', line 146 def width=(_width) self.size.width = _width end |
#x(setter = nil, options = nil) ⇒ Object
getters/setters
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/geomotion/cg_rect.rb', line 105 def x(setter=nil, =nil) if setter rect = CGRect.new([setter, self.origin.y], self.size) if return rect.apply() end return rect end return min_x end |
#x=(_x) ⇒ Object
116 117 118 |
# File 'lib/geomotion/cg_rect.rb', line 116 def x=(_x) self.origin.x = _x end |
#y(setter = nil, options = nil) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/geomotion/cg_rect.rb', line 120 def y(setter=nil, =nil) if setter rect = CGRect.new([self.origin.x, setter], self.size) if return rect.apply() end return rect end return min_y end |
#y=(_y) ⇒ Object
131 132 133 |
# File 'lib/geomotion/cg_rect.rb', line 131 def y=(_y) self.origin.y = _y end |