Handling nonexistant coordinates?

  • Thread starter Anders Eriksson
  • Start date
A

Anders Eriksson

I have a class that is called Coordinates. It contains coordinates for 4
axes (X, Y, Z, A (rotating axis)).

The coordinates are read from a text file and stored as doubles.

Sometimes there isn't a value for one axis, but since I store them as
double...

How can I store a non-value for an axis?

// Anders
--
English isn't my first language.
So any error or strangeness is due to the translation.
Please correct my English so that I may become better.


private class Coordinates
{
private double _x;
private double _y;
private double _z;
private double _a;

public double X { get { return _x; } set { _x = value; } }
public double Y { get { return _y; } set { _y = value; } }
public double Z { get { return _z; } set { _z = value; } }
public double A { get { return _a; } set { _a = value; } }

public void SetCoords(Dictionary<string, string> dict)
{
bool brc = false;
string buf = "";

brc = dict.TryGetValue("MARK_OFFSET_X", out buf);
if (brc)
strY = buf;
else
Y = 0.0;

brc = dict.TryGetValue("MARK_OFFSET_Y", out buf);
if (brc)
X = -1 * Convert.ToDouble(buf, NumberFormatInfo.InvariantInfo);
else
X = 0.0;

brc = dict.TryGetValue("MARK_OFFSET_Z", out buf);
if (brc)
strZ = buf;
else
Z = 0.0;

brc = dict.TryGetValue("MARK_OFFSET_A", out buf);
if (brc)
strA = buf;
else
A = 0.0;
}
}
 
A

Anders Eriksson

Short answer: using the Nullable<T> struct.
Hmmm... A new concept for me, but I like it!

By the way, the code example you posted is somewhat hard to understand:

• You seem to be assigning the X value to the Y variable and vice a versa
Yes. The customer has his own coordinate system where the axes are
rotated 90°. Thus X => Y and Y => -X
• You are using undeclared variables for three of the values ("strY",
"strZ", and "strA")
I'm sorry but I don't understand this. In my code I use the coordinates
as double, but in some of the functions for the axes I have to use
string. So I created a second property that returns the coordinate as
string. I'm guessing from your comment that I have done something wrong,
so if you could show me how to do this properly, I would be grateful!
• You are assigning 0 for the values that are not found in the
dictionary; is that an acceptable value to use for missing values?
No, that's why I needed the non-value.
Finally, I would recommend that you not post significant text after your
signature.
Sorry about that! It wont happen again!

Thank you (and all other replies) for helping me yet again!

// Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top