in_circle_rad() - Avoid mult if obviously outside circle
Most places that invoke this already avoid outside testing inherently (e.g., "for (y = -r; y <= r; y++) ..."), but a few places don't, so I'm _hoping_ this might be beneficial to avoid a handful of multiplication operations. (Worst case, we can add the test optionally, and have it dump some debug output, so we can track down places that waste clockcycles testing points obviously outside a circle.)
This commit is contained in:
parent
5be398cd6d
commit
cb6f190c58
1 changed files with 14 additions and 2 deletions
|
|
@ -21201,7 +21201,12 @@ static void flip_starter(void)
|
|||
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* Returns whether a button click is valid, based on the
|
||||
* "no button distinction" setting.
|
||||
*
|
||||
* @param Uint8 button -- the button clicked (we check for 1, 2, or 3)
|
||||
* @return int -- 1/true if the button is recognized, else 0/false
|
||||
* (2 & 3 are only valid if "no button distiction" is enabled)
|
||||
*/
|
||||
static int valid_click(Uint8 button)
|
||||
{
|
||||
|
|
@ -21213,10 +21218,17 @@ static int valid_click(Uint8 button)
|
|||
|
||||
|
||||
/**
|
||||
* FIXME
|
||||
* Returns whether a point is within a circle.
|
||||
*
|
||||
* @param int x -- x position relative to center of circle
|
||||
* @param int y -- y position [ditto]
|
||||
* @param int rad -- radius of circle
|
||||
* @return int -- 1/true if (x,y) is within the circle, else 0/false
|
||||
*/
|
||||
static int in_circle_rad(int x, int y, int rad)
|
||||
{
|
||||
if (abs(x) > rad || abs(y) > rad) // short circuit to avoid unnecessary math
|
||||
return (0);
|
||||
if ((x * x) + (y * y) - (rad * rad) < 0)
|
||||
return (1);
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue