Init
This commit is contained in:
50
DataDisplay/Common/PointMapping.cs
Normal file
50
DataDisplay/Common/PointMapping.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using SkiaSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DataDisplay.Common
|
||||
{
|
||||
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))/(XDataExtent-XDataExtentMin);
|
||||
YScalingFactor=(Height-(YMargin*2))/(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((float)((sourcePoint.X-XDataExtentMin)*XScalingFactor),(float)(Height-((sourcePoint.Y-YDataExtentMin)*YScalingFactor)));
|
||||
mappedPoint.X+=(float)XMargin; // offset by the xMargin
|
||||
mappedPoint.Y-=(float)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((float)sourcePoint.X,(float)(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;}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user