Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For anyone using objective-c:</p> <pre><code>- (BOOL)rectContainsLine:(CGRect)rect startPoint:(CGPoint)lineStart endPoint:(CGPoint)lineEnd { BOOL (^LineIntersectsLine)(CGPoint, CGPoint, CGPoint, CGPoint) = ^BOOL(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) { CGFloat q = //Distance between the lines' starting rows times line2's horizontal length (line1Start.y - line2Start.y) * (line2End.x - line2Start.x) //Distance between the lines' starting columns times line2's vertical length - (line1Start.x - line2Start.x) * (line2End.y - line2Start.y); CGFloat d = //Line 1's horizontal length times line 2's vertical length (line1End.x - line1Start.x) * (line2End.y - line2Start.y) //Line 1's vertical length times line 2's horizontal length - (line1End.y - line1Start.y) * (line2End.x - line2Start.x); if( d == 0 ) return NO; CGFloat r = q / d; q = //Distance between the lines' starting rows times line 1's horizontal length (line1Start.y - line2Start.y) * (line1End.x - line1Start.x) //Distance between the lines' starting columns times line 1's vertical length - (line1Start.x - line2Start.x) * (line1End.y - line1Start.y); CGFloat s = q / d; if( r &lt; 0 || r &gt; 1 || s &lt; 0 || s &gt; 1 ) return NO; return YES; }; /*Test whether the line intersects any of: *- the bottom edge of the rectangle *- the right edge of the rectangle *- the top edge of the rectangle *- the left edge of the rectangle *- the interior of the rectangle (both points inside) */ return (LineIntersectsLine(lineStart, lineEnd, CGPointMake(rect.origin.x, rect.origin.y), CGPointMake(rect.origin.x + rect.size.width, rect.origin.y)) || LineIntersectsLine(lineStart, lineEnd, CGPointMake(rect.origin.x + rect.size.width, rect.origin.y), CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height)) || LineIntersectsLine(lineStart, lineEnd, CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height), CGPointMake(rect.origin.x, rect.origin.y + rect.size.height)) || LineIntersectsLine(lineStart, lineEnd, CGPointMake(rect.origin.x, rect.origin.y + rect.size.height), CGPointMake(rect.origin.x, rect.origin.y)) || (CGRectContainsPoint(rect, lineStart) &amp;&amp; CGRectContainsPoint(rect, lineEnd))); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload