Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RogueReborn
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mikhail Andrenkov
RogueReborn
Commits
16e1708d
Commit
16e1708d
authored
8 years ago
by
Ian Prins
Browse files
Options
Downloads
Patches
Plain Diff
add method for distance between two points
parent
d2cd17b5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/coord.cpp
+6
-1
6 additions, 1 deletion
src/coord.cpp
src/include/coord.h
+2
-0
2 additions, 0 deletions
src/include/coord.h
with
8 additions
and
1 deletion
src/coord.cpp
+
6
−
1
View file @
16e1708d
#include
"include/coord.h"
#include
<string>
#include
<cmath>
#include
<algorithm>
Coord
::
Coord
(
int
x
,
int
y
)
:
x
(
x
)
...
...
@@ -72,4 +73,8 @@ bool Coord::operator!=(const Coord& other) {
std
::
string
Coord
::
toString
()
const
{
return
std
::
to_string
(
x
)
+
", "
+
std
::
to_string
(
y
);
}
\ No newline at end of file
}
int
Coord
::
distanceTo
(
const
Coord
&
other
)
const
{
return
std
::
max
(
std
::
abs
(
x
-
other
.
x
),
std
::
abs
(
y
-
other
.
y
));
}
This diff is collapsed.
Click to expand it.
src/include/coord.h
+
2
−
0
View file @
16e1708d
...
...
@@ -25,6 +25,8 @@ class Coord {
Coord
asScreen
();
Coord
copy
();
std
::
string
toString
()
const
;
// maximum distance in either dimension
int
distanceTo
(
const
Coord
&
)
const
;
private:
int
x
,
y
;
static
const
int
MAPX
=
0
,
MAPY
=
2
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment