Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/radius-raid/js/util.js
1324 views
1
/*==============================================================================
2
Miscellaneous
3
==============================================================================*/
4
window['requestAnimFrame']=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();
5
6
$.util = {};
7
$.pi = Math.PI;
8
$.twopi = $.pi * 2;
9
10
/*==============================================================================
11
Random Range
12
==============================================================================*/
13
$.util.rand = function( min, max ) {
14
return Math.random() * ( max - min ) + min;
15
};
16
17
/*==============================================================================
18
Calculations
19
==============================================================================*/
20
$.util.distance = function( p1x, p1y, p2x, p2y ) {
21
var xDistance = p1x - p2x,
22
yDistance = p1y - p2y;
23
return Math.sqrt( Math.pow( xDistance, 2 ) + Math.pow( yDistance, 2 ) );
24
};
25
26
$.util.rectInRect = function( r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h ) {
27
return !( r2x > r1x + r1w ||
28
r2x + r2w < r1x ||
29
r2y > r1y + r1h ||
30
r2y + r2h < r1y );
31
};
32
33
$.util.arcInRect = function( ax, ay, ar, rx, ry, rw, rh ) {
34
return !( ax + ar <= rx || ax - ar >= rx + rw || ay + ar <= ry || ay - ar >= ry + rh );
35
};
36
37
$.util.arcIntersectingRect = function( ax, ay, ar, rx, ry, rw, rh ) {
38
return !( ax <= rx - ar || ax >= rx + rw + ar || ay <= ry - ar || ay >= ry + rh + ar );
39
};
40
41
$.util.pointInRect = function( px, py, rx, ry, rw, rh ) {
42
return ( px >= rx && px <= rx + rw && py >= ry && py <= ry + rh );
43
};
44
45
/*==============================================================================
46
Shapes
47
==============================================================================*/
48
$.util.circle = function( ctx, x, y, radius ) {
49
var radius = radius <= 0 ? 1 : radius;
50
ctx.beginPath();
51
ctx.arc( x, y, radius, 0, $.twopi, false );
52
};
53
54
$.util.fillCircle = function( ctx, x, y, radius, fillStyle ) {
55
$.util.circle( ctx, x, y, radius );
56
ctx.fillStyle = fillStyle;
57
ctx.fill();
58
};
59
60
$.util.strokeCircle = function( ctx, x, y, radius, strokeStyle, lineWidth ) {
61
$.util.circle( ctx, x, y, radius );
62
ctx.lineWidth = lineWidth;
63
ctx.strokeStyle = strokeStyle;
64
ctx.stroke();
65
};
66
67
/*==============================================================================
68
Miscellaneous
69
==============================================================================*/
70
$.util.pad = function( amount, digits ){
71
amount += '';
72
if( amount.length < digits ) {
73
amount = '0' + amount;
74
return $.util.pad( amount, digits );
75
} else {
76
return amount;
77
}
78
};
79
80
$.util.convertTime = function( seconds ) {
81
var minutes = Math.floor( seconds / 60 );
82
var seconds = Math.floor( seconds % 60 );
83
return $.util.pad( minutes, 2 ) + ':' + $.util.pad( seconds, 2 );
84
};
85
86
$.util.commas = function( nStr ) {
87
nStr += '';
88
var x = nStr.split( '.' ),
89
x1 = x[ 0 ],
90
x2 = x.length > 1 ? '.' + x[ 1 ] : '',
91
rgx = /(\d+)(\d{3})/;
92
while( rgx.test( x1 ) ) {
93
x1 = x1.replace( rgx, '$1' + ',' + '$2' );
94
}
95
return x1 + x2;
96
};
97
98
99
$.util.isset = function( prop ) {
100
return typeof prop != 'undefined';
101
};
102