-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRFGeometry.h
103 lines (82 loc) · 2.63 KB
/
RFGeometry.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*!
RFGeometry
RFKit
Math and Graphics helper
Copyright (c) 2012-2016, 2018 BB9z
https://github.com/BB9z/RFKit
The MIT License (MIT)
http://www.opensource.org/licenses/mit-license.php
*/
#import "RFRuntime.h"
#pragma mark - Const
#ifndef RFMathNotChange
# define RFMathNotChange CGFLOAT_MAX
#endif
extern const CGPoint CGPointNotChange;
extern const CGRect CGRectNotChange;
extern const CGSize CGSizeNotChange;
#pragma mark - Anchor
typedef NS_ENUM(NSInteger, RFResizeAnchor) {
RFResizeAnchorCenter = 0,
RFResizeAnchorTop,
RFResizeAnchorBottom,
RFResizeAnchorLeft,
RFResizeAnchorRight,
RFResizeAnchorTopLeft,
RFResizeAnchorTopRight,
RFResizeAnchorBottomLeft,
RFResizeAnchorBottomRight,
} ;
typedef NS_ENUM(NSInteger, RFAlignmentAnchor) {
RFAlignmentAnchorCenter = 0,
RFAlignmentAnchorTop,
RFAlignmentAnchorBottom,
RFAlignmentAnchorLeft,
RFAlignmentAnchorRight,
RFAlignmentAnchorTopLeft,
RFAlignmentAnchorTopRight,
RFAlignmentAnchorBottomLeft,
RFAlignmentAnchorBottomRight,
} ;
#pragma mark -
#pragma mark CGPoint
CGPoint CGPointMid(CGPoint a, CGPoint b);
CGFloat CGPointDistance(CGPoint a, CGPoint b);
CGPoint CGPointAtLineRatio(CGPoint start, CGPoint end, CGFloat ratio);
CGPoint CGPointOfRectCenter(CGRect a);
#pragma mark CGSize
CGSize CGSizeFromPoints(CGPoint a, CGPoint b);
CGSize CGSizeScaled(CGSize original, double scale);
#pragma mark CGRect
typedef NS_ENUM(NSInteger, RFCGRectChangeFlag) {
RFCGRectChangeX = 0,
RFCGRectChangeY,
RFCGRectChangeWidth,
RFCGRectChangeHeight
};
CGRect CGRectMakeWithPoints(CGPoint a, CGPoint b);
CGRect CGRectMakeWithCenterAndSize(CGPoint centerPoint, CGSize rectSize);
CGRect CGRectResize(CGRect original, CGSize newSize, RFResizeAnchor resizeAnchor);
// center not changed
CG_INLINE CGRect CGRectScaled(CGRect original, double scale) {
return CGRectResize(original, CGSizeMake(original.size.width *scale, original.size.height *scale), RFResizeAnchorCenter);
}
CGRect CGRectChange(CGRect original, RFCGRectChangeFlag flag, CGFloat newValue);
#pragma mark CGAngle
// radian measure
typedef CGFloat CGAngle;
CGAngle CGAngleFromPoints(CGPoint start, CGPoint end);
CGFloat CGAngleDegrees(CGAngle a);
#pragma mark UIEdgeInsets
/**
Creates an edge inset.
*/
CG_INLINE UIEdgeInsets UIEdgeInsetsMakeWithSameMargin(CGFloat margin) {
return (UIEdgeInsets){ .top = margin, .left = margin, .bottom = margin, .right = margin };
}
/**
Creats an reverse inset.
*/
CG_INLINE UIEdgeInsets UIEdgeInsetsReverse(UIEdgeInsets insets) {
return (UIEdgeInsets){ .top = -insets.top, .left = -insets.left, .bottom = -insets.bottom, .right = -insets.right };
}