-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.m
78 lines (63 loc) · 1.99 KB
/
Utilities.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Utilities.m
// Astral_iOS
//
// Created by Timothy J on 15/07/14.
// Copyright (c) 2014 timothy barraclough. All rights reserved.
//
#import "Utilities.h"
@implementation Utilities
+(float)roundNumber :(float) number toNearest:(float) round{
if(fmodf(number, round) <= (round / 2.0))
return number - fmodf(number, round); //Round down
else return number - fmodf(number, round) + round; //Round down, then up again
}
+(float)constrain :(float) number toMaximum:(float) max{
return (number > max) ? max : number;
}
+(float)constrain :(float) number toMinimum:(float) min{
return (number < min) ? min : number;
}
+(float)constrain :(float) number betweenMinimum:(float) min andMaximum:(float) max{
float temp = (number < min) ? min : number;
return (temp > max) ? max : temp;
}
/*
static inline CGPoint rwAdd(CGPoint a, CGPoint b) {
return CGPointMake(a.x + b.x, a.y + b.y);
}
*/
+(CGPoint) rwSub:(CGPoint) a and:(CGPoint) b{
return CGPointMake(a.x - b.x, a.y - b.y);
}
/*
static inline CGVector rwMult(CGVector a, float b) {
return CGVectorMake(a.dx * b, a.dy * b);
}
*/
+(float) rwLength:(CGPoint) a {
return sqrtf(a.x * a.x + a.y * a.y);
}
+(int)constrainInt :(int) number betweenMinimum:(int) min andMaximum:(int) max{
int temp = (number < min) ? min : number;
return (temp > max) ? max : temp;
}
+(float)negMod : (float)dividend mod:(float)divisor{
if (dividend >= divisor) return dividend-divisor;
if (dividend < 0) return divisor+dividend;
return dividend;
}
/*
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
*/
+ (NSTimeInterval) timeStamp {
return [[NSDate date] timeIntervalSince1970] * 1000;
}
@end