This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sat(a, b) | |
for i,v in ipairs(a.edges) do | |
local axis = perp(v) | |
local a_, b_ = project(a, axis), project(b, axis) | |
if not overlap(a_, b_) then return false end | |
end | |
for i,v in ipairs(b.edges) do | |
local axis = perp(v) | |
local a_, b_ = project(a, axis), project(b, axis) | |
if not overlap(a_, b_) then return false end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int sat(polygon a, polygon b){ | |
int i; | |
for (i=0;i<a.n;i++){ | |
vec axis = a.edges[i].dir; // Get the direction vector | |
axis = perp(axis); // Get the normal of the vector (90 degrees) | |
float *a_ = project(a,axis), *b_ = project(b,axis); // Find the projection of a and b onto axis | |
if (!overlap(a_,b_)) return 0; // If they do not overlap, then no collision | |
} | |
for (i=0;i<b.n;i++){ // repeat for b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = polygon{v(0,0),v(0,5),v(5,4),v(3,0)} | |
b = polygon{v(4,4),v(4,6),v(6,6),v(6,4)} | |
print(sat(a,b)) -- true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
polygon a = Polygon(4, v(0,0),v(0,3),v(3,3),v(3,0)), b = Polygon(4, v(4,4),v(4,6),v(6,6),v(6,4)); | |
printf("%d\n", sat(a,b)); // false | |
a = Polygon(4, v(0,0),v(0,5),v(5,4),v(3,0)); b = Polygon(4, v(4,4),v(4,6),v(6,6),v(6,4)); | |
printf("%d\n", sat(a,b)); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) { | |
int i, j, c = 0; | |
for (i = 0, j = nvert-1; i < nvert; j = i++) { | |
if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) | |
c = !c; | |
} | |
return c; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int multiplier = 7; | |
int (^myBlock)(int) = ^(int num) { | |
return num * multiplier; | |
}; | |
printf("%d", myBlock(3)); // prints "21" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *stringsArray = @[ @"string 1", | |
@"String 21", | |
@"string 12", | |
@"String 11", | |
@"String 02" ]; | |
static NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | | |
NSWidthInsensitiveSearch | NSForcedOrderingSearch; | |
NSLocale *currentLocale = [NSLocale currentLocale]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)showHideView:(id)sender | |
{ | |
// Fade out the view right away | |
[UIView animateWithDuration:1.0 | |
delay: 0.0 | |
options: UIViewAnimationOptionCurveEaseIn | |
animations:^{ | |
thirdView.alpha = 0.0; | |
} | |
completion:^(BOOL finished){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *string; | |
string = [[NSString alloc] initWithString:@"Hello"]; | |
NSLog(string); | |
[string release]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *string; | |
string = [NSString stringWithFormat:@"Hello"]; | |
NSLog(string); |