Fix the PointMapping
This commit is contained in:
@@ -408,26 +408,30 @@ namespace MarketData.CNNProcessing
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills the rectangle with the specified color
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
public void Fill(SKColor color)
|
||||
{
|
||||
SKRectI rect = new SKRectI(0, 0, Width, Height); // x, y, width, height
|
||||
bitmap.Erase(color, rect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DrawPoint - With translation
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="drawPoint"></param>
|
||||
public void DrawPoint(SKColor color,SKPoint drawPoint)
|
||||
{
|
||||
Validate();
|
||||
using SKCanvas canvas = new SKCanvas(bitmap);
|
||||
canvas.Clear();
|
||||
SKPoint txPoint = pointMapping.MapPoint(drawPoint);
|
||||
canvas.DrawPoint(drawPoint, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DrawPoint - With translation
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="drawPoint"></param>
|
||||
public void DrawPoint(SKColor color, SKPoint drawPoint)
|
||||
{
|
||||
Validate();
|
||||
using SKCanvas canvas = new SKCanvas(bitmap);
|
||||
canvas.Clear();
|
||||
SKPoint txPoint = pointMapping.MapPoint(drawPoint);
|
||||
canvas.DrawPoint(drawPoint, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DrawPoint - with given strokeWidth and translation
|
||||
/// </summary>
|
||||
|
||||
@@ -33,13 +33,23 @@ namespace MarketData.CNNProcessing
|
||||
XScalingFactor = pointMapping.XScalingFactor;
|
||||
YScalingFactor = pointMapping.YScalingFactor;
|
||||
}
|
||||
|
||||
// MapPoint will both scale the given point and translate the given point from an upper left origin system to a bottom left origin system
|
||||
|
||||
/// <summary>
|
||||
/// MapPoint will both scale the given point and translate the given point from an upper left origin system to a bottom left origin system
|
||||
/// Because of the scaling factor (XScalingFactor and YScalingFactor) it is possible for the resulting X,Y values to be rounded out of range.
|
||||
/// To remedy this we perform a boundary check of the X,Y points against the extents and set them to those extents if they are out of range.
|
||||
/// </summary>
|
||||
/// <param name="sourcePoint"></param>
|
||||
/// <returns></returns>
|
||||
public SKPoint MapPoint(SKPoint sourcePoint)
|
||||
{
|
||||
SKPoint mappedPoint = new SKPoint((int)((sourcePoint.X - XDataExtentMin) * XScalingFactor), (int)(Height - ((sourcePoint.Y - YDataExtentMin) * YScalingFactor)));
|
||||
SKPoint mappedPoint = new SKPoint((int)((sourcePoint.X - XDataExtentMin) * XScalingFactor), (int)((Height - 1) - ((sourcePoint.Y - YDataExtentMin) * YScalingFactor)));
|
||||
mappedPoint.X += (int)XMargin; // offset by the xMargin
|
||||
mappedPoint.Y -= (int)YMargin; // offset by the yMargin
|
||||
if (mappedPoint.X > XDataExtent) mappedPoint.X = (int)XDataExtent; // constrain X to XDataExtent
|
||||
if (mappedPoint.Y > YDataExtent) mappedPoint.Y = (int)YDataExtent; // constrain Y to YDataExtent
|
||||
if (mappedPoint.X < XDataExtentMin) mappedPoint.X = (int)XDataExtentMin; // constrain X to XDataExtentMin
|
||||
if (mappedPoint.Y < YDataExtentMin) mappedPoint.Y = (int)YDataExtentMin; // constrain Y to YDataExtentMin
|
||||
return mappedPoint;
|
||||
}
|
||||
// TranslatePoint will only translate the given point from an upper left origin system to a bottom left origin system
|
||||
@@ -48,7 +58,8 @@ namespace MarketData.CNNProcessing
|
||||
SKPoint mappedPoint=new SKPoint((int)sourcePoint.X,(int)(Height-sourcePoint.Y-1));
|
||||
return mappedPoint;
|
||||
}
|
||||
public double Width{get;private set;}
|
||||
|
||||
public double Width { get; private set; }
|
||||
public double Height{get;private set;}
|
||||
public double XDataExtent{get;private set;}
|
||||
public double XDataExtentMin{get;private set;}
|
||||
|
||||
Reference in New Issue
Block a user