function _DetermineIfOverlapped (source, target){ //For now, a basic implementation that looks at the vertices of the rectangle to see if they intersec /*NOTE: http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/ is a good place to start when growing this function up. */ if(source instanceof target.constructor) throw "Only supported for circle on rectangle hot action!" var circle = source instanceof Circle ? source: target; var rectangle = source instanceof Rectangle ? source: target; var circlePos = _getWorldPosition(circle); var rectanglePos = _getWorldPosition(rectangle); var circ = { x: circlePos.x, y: circlePos.y, r: circle.radius }; var rect = { x: rectanglePos.x, y: rectanglePos.y, width: rectangle.size[0], height: rectangle.size[1] }; // Find the closest point to the circle within the rectangle var closestX = MathUtilities.clamp(circ.x, [rect.x - rect.width/2, rect.x + rect.width/2]); var closestY = MathUtilities.clamp(circ.y, [rect.y - rect.height/2, rect.y + rect.height/2]); // Calculate the distance between the circle's center and this closest point var distanceX = circ.x - closestX; var distanceY = circ.y - closestY; // If the distance is less than the circle's radius, an intersection occurs var distanceSquared = Math.pow(distanceX,2) + Math.pow(distanceY,2); var overlapped = distanceSquared < Math.pow(circ.r,2); return overlapped; }
Slider.prototype.set = function set(value) { if (value === this.options.value) return; this.options.value = Utilities.clamp(value, this.options.range); _updateLabel.call(this); this.eventOutput.emit('change', { value: value }); };