You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
446 B
C++
26 lines
446 B
C++
|
2 years ago
|
#include "shape.hpp" // Shape class interface
|
||
|
5 years ago
|
|
||
|
2 years ago
|
Shape::Shape(std::int16_t x0, std::int16_t y0)
|
||
|
5 years ago
|
: x(x0),
|
||
|
|
y(y0)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
2 years ago
|
void Shape::moveBy(std::int16_t dx, std::int16_t dy) {
|
||
|
5 years ago
|
this->x += dx;
|
||
|
|
this->y += dy;
|
||
|
|
}
|
||
|
|
|
||
|
|
uint16_t Shape::distanceFrom(Shape const * other) const
|
||
|
|
{
|
||
|
2 years ago
|
std::int16_t dx = x - other->x;
|
||
|
|
std::int16_t dy = y - other->y;
|
||
|
5 years ago
|
if (dx < 0) {
|
||
|
|
dx = -dx;
|
||
|
|
}
|
||
|
|
if (dy < 0) {
|
||
|
|
dy = -dy;
|
||
|
|
}
|
||
|
|
return dx + dy;
|
||
|
|
}
|