forked from natikgadzhi/XNMaths
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XNFloatRange.m
86 lines (68 loc) · 1.56 KB
/
XNFloatRange.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
79
80
81
82
83
84
85
86
//
// XNRange.m
// XNMaths
//
// Created by Нат Гаджибалаев on 24.11.09.
// Copyright 2009 Нат Гаджибалаев. All rights reserved.
//
#import "XNFloatRange.h"
@implementation XNFloatRange
@synthesize min, max;
#pragma mark -
#pragma mark Class initializers
+ (XNFloatRange*) rangeWithMin:(CGFloat)aMin max:(CGFloat)aMax
{
return [[[XNFloatRange alloc] initWithMin:aMin max:aMax] autorelease];
}
+ (XNFloatRange*) rangeWithRange:(NSRange)range
{
return [[[XNFloatRange alloc] initWithRange:range] autorelease];
}
+ (XNFloatRange*) rangeWithCArray:(CGFloat*)array withCapacity:(NSUInteger)capacity
{
return [[[XNFloatRange alloc] initWithCArray:array withCapacity:capacity] autorelease];
}
#pragma mark -
#pragma mark Instance initializers
- (XNFloatRange*) initWithMin:(CGFloat)aMin max:(CGFloat)aMax
{
self = [super init];
min = aMin;
max = aMax;
return self;
}
- (XNFloatRange*) initWithRange:(NSRange)range
{
self = [super init];
min = (CGFloat)(range.location);
max = (CGFloat)(range.length);
return self;
}
- (XNFloatRange*) initWithCArray:(CGFloat*)array withCapacity:(NSUInteger)capacity
{
self = [super init];
min = array[0];
max = array[0];
for( NSUInteger i = 0; i < capacity; i++ ){
if( array[i] < min ){
min = array[i];
}
if( array[i] > max){
max = array[i];
}
}
return self;
}
#pragma mark -
#pragma mark Instance logic
- (CGFloat) length
{
return fabsf(max - min);
}
#pragma mark -
#pragma mark Copying
- (XNFloatRange *) copy
{
return [[XNFloatRange alloc]initWithMin: min max: max];
}
@end