Gets from a set of points only points that are h-neighbors for a point with integer coordinates x and y. "point" Given point with integer coordinates x and y. "h" Distance around a given point. "points" A given set of points.
class Point:
public readonly struct Point : System.IEquatable<Point>
{
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
public int X { get; }
public int Y { get; }
public static bool operator ==(Point left, Point right)
{
return left.Equals(right);
}
public static bool operator !=(Point left, Point right)
{
return !(left == right);
}
public override int GetHashCode()
{
return this.X.GetHashCode() ^ this.Y.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj is null)
{
return false;
}
if (!(obj is Point))
{
return false;
}
if (obj.GetType() != this.GetType())
{
return false;
}
Point point = (Point)obj;
return this.Equals(point);
}
public bool Equals(Point other)
{
return this.X == other.X && this.Y == other.Y;
}
}
Method:
public static Point[] GetNeighbors(Point point, int h, params Point[] points)
{
}
I don’t know how to solve this problem, I tried to solve it using:
for (int i = 0; i <= points.Length - 1; i++)
{
PointsCoordinate[i] = Math.Sqrt(Math.Pow(points[i].X, 2) + Math.Pow(points[i].Y, 2));
}
After that I will find nearest values of point using list or et cetera , but in this case I have to return exactly nearest points from array not values , how can I solve this , mb I have the wrong approach to solving this problem. I need to connect sorted values with Points in array, help me please
