@@ -4,8 +4,6 @@ import { RangeType } from "../../Enums/RangeType.js";
44import { checkDistance } from "../../Utils/MathUtils.js" ;
55import { squareExp } from "./Constants.js" ;
66
7- const tempPos : ICoordinates = { x : 0 , y : 0 } ;
8-
97/**
108 */
119export abstract class BaseRange {
@@ -85,28 +83,22 @@ export class Circle extends BaseRange {
8583 intersects ( range : BaseRange ) : boolean {
8684 const pos1 = this . position ,
8785 pos2 = range . position ,
88- r = this . radius ;
89-
90- tempPos . x = Math . abs ( pos2 . x - pos1 . x ) ;
91- tempPos . y = Math . abs ( pos2 . y - pos1 . y ) ;
86+ r = this . radius ,
87+ dx = Math . abs ( pos2 . x - pos1 . x ) ,
88+ dy = Math . abs ( pos2 . y - pos1 . y ) ;
9289
9390 if ( range instanceof Circle || range . type === ( RangeType . circle as string ) ) {
9491 const circleRange = range as Circle ,
9592 rSum = r + circleRange . radius ,
96- dist = Math . hypot ( tempPos . x , tempPos . y ) ;
93+ dist = Math . hypot ( dx , dy ) ;
9794
9895 return rSum > dist ;
9996 } else if ( range instanceof Rectangle || range . type === ( RangeType . rectangle as string ) ) {
10097 const rectRange = range as Rectangle ,
10198 { width, height } = rectRange . size ,
102- edges = Math . pow ( tempPos . x - width , squareExp ) + Math . pow ( tempPos . y - height , squareExp ) ;
103-
104- return (
105- edges <= r ** squareExp ||
106- ( tempPos . x <= r + width && tempPos . y <= r + height ) ||
107- tempPos . x <= width ||
108- tempPos . y <= height
109- ) ;
99+ edges = Math . pow ( dx - width , squareExp ) + Math . pow ( dy - height , squareExp ) ;
100+
101+ return edges <= r ** squareExp || ( dx <= r + width && dy <= r + height ) || dx <= width || dy <= height ;
110102 }
111103
112104 return false ;
0 commit comments