Get radial distance between vector1 and vector2 A small script to calculate total units of distance between two vector entities. Especially useful in games and grid snaps, inventory snaps etc..

typedef struct COORD
{
    int X, Y;
} coord;

int get_dist (coord entity1, coord entity2)
{
    int minuendX    = max(entity1.X, entity2.X);
    int minuendY    = max(entity2.Y, entity2.Y);
    int subtrahendX = min(entity1.X, entity2.X);
    int subtrahendY = min(entity2.Y, entity2.Y);

    return (minuendX - subtrahendX) + (minuendY - subtrahendY);
}
There is a typo in the y components, both times only entity2 is used. I believe that is a copy-paste error.

Your distance is better known as the manhattan distance. I suggest naming the method after it to avoid surprises.

An other method of getting it uses the absolute value of the differences:

int get_manhattan_dist (coord entity1, coord entity2)
{
    return abs(entity1.X - entity2.X) + abs(entity1.Y - entity2.Y);
}


Of course if you have the manhattan distance you can easily provide the euclidean distance

double get_euclid_dist (coord entity1, coord entity2)
{
    double diffX    = entity1.X - entity2.X;
    double diffY    = entity1.Y - entity2.Y;

    return hypot(diffX, diffY);
}