Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jwo
Created December 9, 2014 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwo/9a34535993686e6edd5f to your computer and use it in GitHub Desktop.
Save jwo/9a34535993686e6edd5f to your computer and use it in GitHub Desktop.
Code in a book. Author must have been like "I'mma gonna drop this right here."
-(Line *)lineAtPoint:(CGPoint)p
{
for (Line *l in self.finishedLines){
CGPoint start = l.begin;
CGPoint end = l.end;
for (float t=0.0; t<=1.0; t+= 0.05){
float x = start.x + t * (end.x - start.x);
float y = start.y + t * (end.y - start.y);
if (hypot(x - p.x, y - p.y) < 20.0){
return l;
}
}
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment