/// <summary> /// Checks whether a coordinate is in line. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <returns>True if the coordinate is in line.</returns> public bool InLine(ushort x, ushort y) { int mydst = (int)RangeTools.GetDistance((ushort)X1, (ushort)Y1, x, y); byte dir = (byte)RangeTools.GetAngle(X1, Y1, x, y); if (mydst <= MaxDistance) { if (_algorithm == Algorithm.SomeMath) { if (dir != Direction) { return(false); } //calculate line eq if (X2 - X1 == 0) { //=> X - X1 = 0 //=> X = X1 return(x == X1); } else if (Y2 - Y1 == 0) { //=> Y - Y1 = 0 //=> Y = Y1 return(y == Y1); } else { double val1 = ((double)(x - X1)) / ((double)(X2 - X1)); double val2 = ((double)(y + Y1)) / ((double)(Y2 + Y1)); bool works = Math.Floor(val1) == Math.Floor(val2); return(works); } } else if (_algorithm == Algorithm.DDA) { return(Contains(_lineCoordinates, new ILACoordinate(x, y))); } } return(false); }
/// <summary> /// Checks whether a coordinate is within the sector. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <returns>True if the coordinate is within the sector.</returns> public bool Inside(int x, int y) { if (RangeTools.GetDistance(x, y, _attackerX, _attackerY) <= _distance) { int degree = RangeTools.GetDegree(_attackerX, x, _attackerY, y); if (_addextra) { degree += 360; } if (degree >= _leftside && degree <= _rightside) { return(true); } } return(false); }