/// <summary> /// Creates a new sector. /// </summary> /// <param name="attackerX">The attacker x.</param> /// <param name="attackerY">The attacker y.</param> /// <param name="attackX">The attack x.</param> /// <param name="attackY">The attack y.</param> public Sector(int attackerX, int attackerY, int attackX, int attackY) { _attackerX = attackerX; _attackerY = attackerY; _attackX = attackX; _attackY = attackY; _degree = RangeTools.GetDegree(attackerX, attackX, attackerY, attackY); _addextra = false; }
/// <summary> /// Creates a new ILA algorithm. /// </summary> /// <param name="x1">The x1 coordinate.</param> /// <param name="x2">The x2 coordinate.</param> /// <param name="y1">The y1 coordinate.</param> /// <param name="y2">The y2 coordinate.</param> /// <param name="maxDistance">The max distance.</param> /// <param name="algorithm">The algorithm type.</param> public ILA(ushort x1, ushort x2, ushort y1, ushort y2, byte maxDistance = 10, Algorithm algorithm = Algorithm.DDA) { _algorithm = algorithm; this.X1 = x1; this.Y1 = y1; this.X2 = x2; this.Y2 = y2; this.MaxDistance = maxDistance; if (_algorithm == Algorithm.DDA) { _lineCoordinates = LineCoords(x1, y1, x2, y2); } Direction = (byte)RangeTools.GetAngle(x1, y1, x2, y2);; }
/// <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); }