36 function map(value, istart, istop, ostart, ostop) {
37 return ostart + (ostop - ostart) * ((value - istart) / (istop - istart))
49 function clamp(value, min, max) {
50 if (value < min)
return min
51 if (value > max)
return max
56 function rectDistance(rect1, rect2) {
57 return pointDistance(Qt.point(rect1.x + rect1.width / 2, rect1.y + rect1.height / 2),
58 Qt.point(rect2.x + rect2.width / 2, rect2.y + rect2.height / 2))
62 function pointDistance(point1, point2) {
63 return Math.sqrt(Math.pow(point1.x - point2.x, 2) +
64 Math.pow(point1.y - point2.y, 2)
69 function intersectionRect(r1, r2) {
70 var xmin = Math.max(r1.x, r2.x);
71 var xmax1 = r1.x + r1.width;
72 var xmax2 = r2.x + r2.width;
73 var xmax = Math.min(xmax1, xmax2);
74 var out = {x:0, y:0, width:0, height:0}
76 var ymin = Math.max(r1.y, r2.y);
77 var ymax1 = r1.y + r1.height;
78 var ymax2 = r2.y + r2.height;
79 var ymax = Math.min(ymax1, ymax2);
83 out.width = xmax - xmin;
84 out.height = ymax - ymin;
90 function easeOutCubic(t) {
return (--t)*t*t+1 }
92 function linearAnimation(startProgress, endProgress, startValue, endValue, progress) {
94 return (progress - startProgress) * (endValue - startValue) / (endProgress - startProgress) + startValue;