Skip to content

Commit

Permalink
Added points checks
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Oct 27, 2023
1 parent 84106d6 commit ec71f0a
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/dn/Geom.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,7 @@ package dn;

class Geom {

/** Return TRUE if rectangle A touches or Collides rectangle B. **/
// public static inline function rectTouchesRect(aX:Float, aY:Float, aWid:Float, aHei:Float, bX:Float, bY:Float, bWid:Float, bHei:Float) {
// /*
// Source: https://www.baeldung.com/java-check-if-two-rectangles-overlap

// "The two given rectangles won't overlap if either of the below conditions is true:
// One of the two rectangles is above the top edge of the other rectangle
// One of the two rectangles is on the left side of the left edge of the other rectangle"
// */
// if( aY+aHei < bY || bY+bHei < aY )
// return false;
// else if( aX+aWid < bX || bX+bWid < aX )
// return false;
// else
// return true;
// }


/** Return TRUE if rectangle A Collides rectangle B. **/
/** Check if rectangle A collides rectangle B. **/
public static inline function rectCollidesRect(aX:Float, aY:Float, aWid:Float, aHei:Float, bX:Float, bY:Float, bWid:Float, bHei:Float) {
/*
Source: https://www.baeldung.com/java-check-if-two-rectangles-overlap
Expand All @@ -37,6 +19,7 @@ class Geom {
return true;
}

/** Check if a rectangle collides with a circle **/
public static inline function rectCollidesCircle(rx:Float, ry:Float, rWid:Float, rHei:Float, circleX:Float, circleY:Float, radius:Float) {
// Find the closest point on the rectangle to the center of the circle
final closestX = M.fclamp(circleX, rx, rx+rWid);
Expand All @@ -51,12 +34,24 @@ class Geom {
}



/** Check if a rectangle circle A with a circle B **/
public static inline function circleCollidesCircle(xA:Float, yA:Float, rA:Float, xB:Float, yB:Float, rB:Float) {
return M.distSqr(xA,yA,xB,yB) <= (rA+rB)*(rA+rB);
}


/** Check if a coordinate is inside a rectangle **/
public static inline function pointInsideRect(ptX:Float, ptY:Float, rx:Float, ry:Float, rWid:Float, rHei:Float) {
return ptX>=rx && ptX<rx+rWid && ptY>=ry && ptY<ry+rHei;
}


/** Check if a coordinate is inside a circle **/
public static inline function pointInsideCircle(ptX:Float, ptY:Float, circleX:Float, circleY:Float, radius:Float) {
return M.distSqr(ptX,ptY, circleX,circleY) <= radius*radius;
}


@:noCompletion
public static function __test() {
// TODO
Expand Down

0 comments on commit ec71f0a

Please sign in to comment.