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 *firstName = @"Bobo"; | |
NSString *lastName = @"Shone"; | |
int age = @"100"; | |
UIImage *avatar = image; | |
NSData *imageData = UIImageJPEGRepresentation(avatar, 100); | |
// Store the data | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
[defaults setObject:firstName forKey:@"firstName"]; | |
[defaults setObject:lastName forKey:@"lastname"]; |
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
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
NSString *firstName = [defaults objectForKey:@"firstName"]; | |
NSString *lastName = [defaults objectForKey:@"lastname"]; | |
int age = [defaults integerForKey:@"age"]; | |
NSData *imageData = [defaults dataForKey:@"image"]; | |
UIImage *avatar = [UIImage imageWithData:imageData]; |
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
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
NSString *firstName = [defaults objectForKey:@"firstName"]; | |
NSString *lastName = [defaults objectForKey:@"lastname"]; | |
int age = [defaults integerForKey:@"age"]; | |
NSData *imageData = [defaults dataForKey:@"image"]; | |
UIImage *avatar = [UIImage imageWithData:imageData]; |
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 | |
array = [NSArray arrayWithObjects:a, b, c, nil]; | |
array = @[ a, b, c ]; | |
// NSDictionary | |
dict = [NSDictionary dictionaryWithObjects:@[o1, o2, o3] forKeys:@[k1, k2, k3]]; | |
dict = @{ k1 : o1, k2 : o2, k3 : o3 }; |
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
bool sat(polygon a, polygon b){ | |
for (int i = 0; i < a.edges.length; i++){ | |
vector axis = a.edges[i].direction; // Get the direction vector of the edge | |
axis = vec_normal(axis); // We need to find the normal of the axis vector. | |
axis = vec_unit(axis); // We also need to "normalize" this vector, or make its length/magnitude equal to 1 | |
// Find the projection of the two polygons onto the axis | |
segment proj_a = project(a, axis), proj_b = project(b, axis); | |
if(!seg_overlap(proj_a, proj_b)) return false; // If they do not overlap, then return false |
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 vec(x, y) | |
return {x, y} | |
end | |
v = vec -- shortcut | |
function dot(v1, v2) | |
return v1[1]*v2[1] + v1[2]*v2[2] | |
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
a = polygon{v(0,0),v(0,1),v(1,1),v(1,0)} |
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
typedef struct {float x, y;} vec; | |
vec v(float x, float y){ | |
vec a = {x, y}; // shorthand for declaration | |
return a; | |
} | |
float dot(vec a, vec b){ | |
return a.x*b.x+a.y*b.y; | |
} |
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
-- We keep a running range (min and max) values of the projection, and then use that as our shadow | |
function project(a, axis) | |
axis = normalize(axis) | |
local min = dot(a.vertices[1],axis) | |
local max = min | |
for i,v in ipairs(a.vertices) do | |
local proj = dot(v, axis) -- projection | |
if proj < min then min = proj end | |
if proj > max then max = proj 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
float* project(polygon a, vec axis){ | |
axis = normalize(axis); | |
int i; | |
float min = dot(a.vertices[0],axis); float max = min; // min and max are the start and finish points | |
for (i=0;i<a.n;i++){ | |
float proj = dot(a.vertices[i],axis); // find the projection of every point on the polygon onto the line. | |
if (proj < min) min = proj; if (proj > max) max = proj; | |
} | |
float* arr = (float*)malloc(2*sizeof(float)); | |
arr[0] = min; arr[1] = max; |
OlderNewer