NPlot.TradingDateTimeAxis.PhysicalToWorld C# (CSharp) Method

PhysicalToWorld() public method

Transforms a physical coordinate to an axis world coordinate given the physical extremites of the axis.
public PhysicalToWorld ( PointF p, PointF physicalMin, PointF physicalMax, bool clip ) : double
p PointF the point to convert
physicalMin PointF the physical minimum extremity of the axis
physicalMax PointF the physical maximum extremity of the axis
clip bool whether or not to clip the world value to lie in the range of the axis if it is outside.
return double
        public override double PhysicalToWorld(
            PointF p,
            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;
            }

            // normalised axis dir vector
            float axis_X = _physicalMax.X - _physicalMin.X;
            float axis_Y = _physicalMax.Y - _physicalMin.Y;
            float len = (float)Math.Sqrt(axis_X * axis_X + axis_Y * axis_Y);
            axis_X /= len;
            axis_Y /= len;

            // point relative to axis physical minimum.
            PointF posRel = new PointF(p.X - _physicalMin.X, p.Y - _physicalMin.Y);

            // dist of point projection on axis, normalised.
            float prop = (axis_X * posRel.X + axis_Y * posRel.Y) / len;

            //double world = prop * (WorldMax - WorldMin) + WorldMin;
            double world = prop * (virtualWorldMax_ - virtualWorldMin_) + virtualWorldMin_;
            world = ReverseSparseWorldRemap(world);

            // if want clipped value, return extrema if outside range.
            if (clip)
            {
                world = Math.Max(world, WorldMin);
                world = Math.Min(world, WorldMax);
            }

            return world;
        }