Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit type conversion between Position and TilePosition #237

Closed
heinermann opened this issue Jan 19, 2014 · 5 comments
Closed

Explicit type conversion between Position and TilePosition #237

heinermann opened this issue Jan 19, 2014 · 5 comments

Comments

@heinermann
Copy link
Member

From blued...@gmail.com on September 16, 2010 10:06:50

Currently, Position and TilePosition objects are implicitly converted to each other. This means that this is possible:

BWAPI::Position a(100,100);
BWAPI::TilePosition b = a;

This sometimes causes accidental problems because the .getDistance function returns other distances when comparing Positions and the same converted TilePositions. Also, converting to a TilePosition causes accuracy loss.

Another related issue is that when converting BWAPI::Position::Invalid to a TilePosition it does not become equal to BWAPI::TilePosition::Invalid.

To solve this I would like to suggest using explicit type conversion instead of implicit, which would mean the above would need to be written as:

BWAPI::Position a(100,100);
BWAPI::TilePosition b = (BWAPI::TilePosition)a;

Original issue: http://code.google.com/p/bwapi/issues/detail?id=238

@heinermann
Copy link
Member Author

From AHeinerm on September 19, 2010 08:47:01

Labels: Type-Defect Priority-Low Component-Persistence Component-Logic Usability

@heinermann
Copy link
Member Author

From AHeinerm on September 29, 2010 12:35:27

I don't quite understand.
Converting to TilePosition does what it should.

I fixed the Positions::Invalid != TilePositions::Invalid issue though.

It doesn't matter how you change it, b will always equal a/32.

Status: Questionable

@heinermann
Copy link
Member Author

From blued...@gmail.com on September 30, 2010 08:14:11

Converting to a TilePosition indeed works.

The thing I suggest changing is that currently, Positions are converted automatically to TilePositions. (As illustrated in the example.) This is not correct behavior considering converting between them causes loss of accuracy.

The only thing that would need changing in the BWAPI source code is:

TilePosition(const BWAPI::Position&);
to
explicit TilePosition(const BWAPI::Position&);

(and any implicitely converted Position will now generate a warning or error)

@heinermann
Copy link
Member Author

From lowerlo...@gmail.com on October 17, 2010 14:29:29

Status: Accepted
Owner: lowerlogic

@heinermann
Copy link
Member Author

From AHeinerm on October 20, 2010 11:35:34

This issue was closed by revision r2892 .

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant