public WorldToPhysical ( double coord, PointF physicalMin, PointF physicalMax, bool clip ) : PointF | ||
coord | double | The coordinate value to transform. |
physicalMin | PointF | The physical position corresponding to the world minimum of the axis. |
physicalMax | PointF | The physical position corresponding to the world maximum of the axis. |
clip | bool | if false, then physical value may extend outside worldMin / worldMax. If true, the physical value returned will be clipped to physicalMin or physicalMax if it lies outside this range. |
Результат | PointF |
public override PointF WorldToPhysical(
double coord,
PointF physicalMin,
PointF physicalMax,
bool clip)
{
// (1) account for reversed axis. Could be tricky and move
// this out, but would be a little messy.
PointF _physicalMin;
PointF _physicalMax;
if (this.Reversed)
{
_physicalMin = physicalMax;
_physicalMax = physicalMin;
}
else
{
_physicalMin = physicalMin;
_physicalMax = physicalMax;
}
// (2) if want clipped value, return extrema if outside range.
if (clip)
{
if (WorldMin < WorldMax)
{
if (coord > WorldMax)
{
return _physicalMax;
}
if (coord < WorldMin)
{
return _physicalMin;
}
}
else
{
if (coord < WorldMax)
{
return _physicalMax;
}
if (coord > WorldMin)
{
return _physicalMin;
}
}
}
// (3) we are inside range or don't want to clip.
coord = SparseWorldRemap(coord);
double range = virtualWorldMax_ - virtualWorldMin_;
double prop = (double)((coord - virtualWorldMin_) / range);
//double range = WorldMax - WorldMin;
//double prop = (double)((coord - WorldMin) / range);
//if (range1 != range)
// range1 = range;
// Force clipping at bounding box largeClip times that of real bounding box
// anyway. This is effectively at infinity.
const double largeClip = 100.0;
if (prop > largeClip && clip)
prop = largeClip;
if (prop < -largeClip && clip)
prop = -largeClip;
if (range == 0)
{
if (coord >= virtualWorldMin_)
prop = largeClip;
if (coord < virtualWorldMin_)
prop = -largeClip;
}
// calculate the physical coordinate.
PointF offset = new PointF(
(float)(prop * (_physicalMax.X - _physicalMin.X)),
(float)(prop * (_physicalMax.Y - _physicalMin.Y)));
return new PointF(_physicalMin.X + offset.X, _physicalMin.Y + offset.Y);
}