Getting node position as float values?

Hi there,
I’m sure it’s a crazy simple question here but I can’t manage to find the answer on the forum.
I have an existing graph of nodes that I’d like to inject into A*Pathfinding for it to request and find paths.

I have a created a simple WorkItem to do so, setting my nodes position into a PointGraph.

            PointGraph pg = AstarPath.active.graphs[0] as PointGraph;
            IEnumerator<Node> ne = mn.node_enumerator;
            while (ne.MoveNext())
            {
                pg.AddNode((Int3)((Vector3)ne.Current.position));
            }

After that I use the Save to File feature. However when I Load from file the nodes I get from GetNodes() give me int3 position only.
For example: I insert a node at position (253862.8, 6257641.0) and GetNodes returns it with a position at (253862.9, -2147484.0, 0.0)

Is there a way to retrieve the exact position I gave?
Thanks.

Hi

You can convert between an Int3 and a Vector3 using explicit casts

Int3 p1 = (Int3)someVector;
Vector3 p2 = (Vector3)p1;

This is not a lossless conversion however. Int3s have a precision of 0.001 world units.
Since Int3s use fixed precision and stores the values in 32 bit integers, the maximum range for them is ± 2147483 (though I would recommend using values a lot smaller than that).
So if you create a node at coordinate 6257641.0 that is outside the valid range and it will wrap.
Why do you need such enormous coordinate values?

Generally for the fewest surprises I would recommend keeping coordinate values within ±15000 as within that range floating point coordinates also have a precision greater than 0.001.
Int3 coordinates are used instead of floating point coordinates because they are a lot nicer to deal with. Floating point edge cases are really annoying to have to deal with. For point graph they do not matter much, but for navmesh/recast graphs using floating point coordinates would have been horrible to deal with.

Hey Aron,
Thanks for the answer.

Why do you need such enormous coordinate values?

These coordinates are simply EPSG 3857 (pseudo mercator) based. These are distances, in meters, from the origin. As I work with real map data (real cities, real countries etc). The first pass of my system is based on these values. Of course I will reduce them soon to something that is easier to use.

To follow my question. Do you think you’ll implement Int3 <> Vector2 cast in A*Pathfinding one day?

Thanks for your help.

Hi

Ok.
I would suggest that you scale them down. Even if you were using floating point coordinates, those would have a terrible precision. For example around 6257641 a 32 bit float has a precision of 0.5 meters (see https://www.h-schmidt.net/FloatConverter/IEEE754.html).

An Int3 to Vector2 cast doesn’t really make sense as it discards information outright. Vector3 does have a Vector2 cast so I suppose you could do

Vector2 v2 = (Vector2)(Vector3)someInt3;

I would suggest that you scale them down. Even if you were using floating point coordinates, those would have a terrible precision. For example around 6257641 a 32 bit float has a precision of 0.5 meters (see https://www.h-schmidt.net/FloatConverter/IEEE754.html).

Yep I know, the data used in my first post is still rough :S I shouldn’t have posted it sorry.