-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathutils.js
128 lines (114 loc) · 3.72 KB
/
utils.js
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const averagePoints = require('./utils/averagePoints');
const degreesToRadians = require('./utils/degreesToRadians');
const radiansToDegrees = require('./utils/radiansToDegrees');
const pointInPolygon = require('./utils/pointInPolygon');
const distance = require('./utils/distance');
const degreesFromCenter = require('./utils/degreesFromCenter');
const radiansFromCenter = require('./utils/radiansFromCenter');
const scalePoints = require('./utils/scalePoints');
const translatePoints = require('./utils/translatePoints');
const insideCanvas = require('./utils/insideCanvas');
const rotateDegreesAroundCenter = require('./utils/rotateDegreesAroundCenter');
const rotateRadiansAroundCenter = require('./utils/rotateRadiansAroundCenter');
/**
* Math utility libraries
* @exports utils
*/
const utils = {
/**
* Gets the average point value in an array of points.
* @function
* @param {Array} points
* @return {Object} An object with x and y values
*/
averagePoints,
/**
* Convert degrees to raidans
* @function
* @param {Number} degrees
* @return {Number} A value in radians
*/
degreesToRadians,
/**
* Convert radians to degrees
* @function
* @param {Number} radians
* @return {Number} A value in degrees
*/
radiansToDegrees,
/**
* Checks if a point is in a polygon
* @function
* @param {Object} point Object with an x and y value
* @param {Array} polygon Array of points
* @return {Boolean} True if the point is inside the polygon
*/
pointInPolygon,
/**
* Returns the distance between 2 points
* @function
* @param {Object} point1 Object with an x and y value
* @param {Object} point2 Object with an x and y value
* @return {Number} The distance
*/
distance,
/**
* Degrees a point is offset from a center point
* @function
* @param {Object} center Object with an x and y value
* @param {Object} point Object with an x and y value
* @return {Number} A value in degrees
*/
degreesFromCenter,
/**
* Radians a point is offset from a center point
* @function
* @param {Object} center Object with an x and y value
* @param {Object} point Object with an x and y value
* @return {Number} A value in radians
*/
radiansFromCenter,
/**
* Scale a point or array of points.
* @function
* @param {Object|Array} points A point or array of points
* @param {Object} scale Object with an x and y value
* @return {Object|Array} A scaled point or array of points
*/
scalePoints,
/**
* Translate a point or array of points
* @function
* @param {Object|Array} points A point or array of points
* @param {Object} offset Object with an x and y value
* @return {Object|Array} A translated point or array of points
*/
translatePoints,
/**
* Check whether a point is inside a canvas
* @function
* @param {Object} point A point to test
* @param {Object} canvas Object with height and width properties
* @return {Boolean} True if inside canvas else false
*/
insideCanvas,
/**
* Get a point based around the rotation in radians of one point around a center
* @function
* @param {Object} center Object with an x and y value
* @param {Object} point Object with an x and y value
* @param {Number} angle an angle in radians
* @return {Object} A new point that has been rotated
*/
rotateRadiansAroundCenter,
/**
* Get a point based around the rotation in degrees of one point around a center
* @function
* @param {Object} center Object with an x and y value
* @param {Object} point Object with an x and y value
* @param {Number} angle an angle in degrees
* @return {Object} A new point that has been rotated
*/
rotateDegreesAroundCenter,
};
module.exports = utils;