/
CGPoint_Util.m
32 lines (27 loc) 路 993 Bytes
/
CGPoint_Util.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
//
// CGPoint_Util.c
// SmartDeviceLink-iOS
//
// Created by Muller, Alexander (A.) on 6/14/16.
// Copyright 漏 2016 smartdevicelink. All rights reserved.
//
#include "CGPoint_Util.h"
#include "math.h"
CGPoint CGPointAverageOfPoints(CGPoint point1, CGPoint point2) {
CGFloat xAverage = (point1.x + point2.x)/2.0f;
CGFloat yAverage = (point1.y + point2.y)/2.0f;
return CGPointMake(xAverage, yAverage);
}
CGPoint CGPointCenterOfPoints(CGPoint point1, CGPoint point2) {
CGFloat xCenter = (point1.x + point2.x) / 2.0f;
CGFloat yCenter = (point1.y + point2.y) / 2.0f;
return CGPointMake(xCenter, yCenter);
}
CGPoint CGPointDisplacementOfPoints(CGPoint point1, CGPoint point2) {
CGFloat xDisplacement = point1.x - point2.x;
CGFloat yDisplacement = point1.y - point2.y;
return CGPointMake(xDisplacement, yDisplacement);
}
CGFloat CGPointDistanceBetweenPoints(CGPoint point1, CGPoint point2) {
return hypotf(point1.x - point2.x, point1.y - point2.y);
}