48 lines
2.1 KiB
C#
Executable File
48 lines
2.1 KiB
C#
Executable File
using SkiaSharp;
|
|
|
|
namespace MarketData.CNNProcessing
|
|
{
|
|
public class PointMapping
|
|
{
|
|
public PointMapping(double width,double height,double xDataExtent,double xDataExtentMin,double yDataExtent,double yDataExtentMin,double xMarginExtent=0.00,double yMarginExtent=0.00)
|
|
{
|
|
Width=width;
|
|
Height=height;
|
|
XMargin=xMarginExtent;
|
|
YMargin=yMarginExtent;
|
|
XDataExtent=xDataExtent;
|
|
XDataExtentMin=xDataExtentMin;
|
|
YDataExtent=yDataExtent;
|
|
YDataExtentMin=yDataExtentMin;
|
|
XScalingFactor=(Width-(XMargin*2.00))/(XDataExtent-XDataExtentMin);
|
|
YScalingFactor=(Height-(YMargin*2.00))/(YDataExtent-YDataExtentMin);
|
|
}
|
|
// MapPoint will both scale the given point and translate the given point from an upper left origin system to a bottom left origin system
|
|
public SKPoint MapPoint(SKPoint sourcePoint)
|
|
{
|
|
SKPoint mappedPoint=new SKPoint((int)((sourcePoint.X-XDataExtentMin)*XScalingFactor),(int)(Height-((sourcePoint.Y-YDataExtentMin)*YScalingFactor)));
|
|
mappedPoint.X+=(int)XMargin; // offset by the xMargin
|
|
mappedPoint.Y-=(int)YMargin; // offset by the yMargin
|
|
return mappedPoint;
|
|
}
|
|
// TranslatePoint will only translate the given point from an upper left origin system to a bottom left origin system
|
|
public SKPoint TranslatePoint(SKPoint sourcePoint)
|
|
{
|
|
SKPoint mappedPoint=new SKPoint((int)sourcePoint.X,(int)(Height-sourcePoint.Y-1));
|
|
return mappedPoint;
|
|
}
|
|
public double Width{get;private set;}
|
|
public double Height{get;private set;}
|
|
public double XDataExtent{get;private set;}
|
|
public double XDataExtentMin{get;private set;}
|
|
public double XRange{get{return XDataExtent-XDataExtentMin;}}
|
|
public double YDataExtent{get;private set;}
|
|
public double YDataExtentMin{get;private set;}
|
|
public double YRange{get{return YDataExtent-YDataExtentMin;}}
|
|
public double XMargin{get;private set;}
|
|
public double YMargin{get;private set;}
|
|
public double XScalingFactor{get;private set;}
|
|
public double YScalingFactor{get;private set;}
|
|
}
|
|
}
|