diff --git a/MarketDataLib/CNNProcessing/PointMapping.cs b/MarketDataLib/CNNProcessing/PointMapping.cs index 3318038..e08f43c 100644 --- a/MarketDataLib/CNNProcessing/PointMapping.cs +++ b/MarketDataLib/CNNProcessing/PointMapping.cs @@ -25,11 +25,17 @@ namespace MarketData.CNNProcessing // 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 Point MapPoint(Point sourcePoint) { - Point mappedPoint=new Point((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; + int x = (int)((sourcePoint.X - XDataExtentMin) * XScalingFactor + XMargin); + int y = (int)(Height - 1 - ((sourcePoint.Y - YDataExtentMin) * YScalingFactor) - YMargin); + + // clamp to bounds + x = Math.Max(0, Math.Min(x, (int)Width - 1)); + y = Math.Max(0, Math.Min(y, (int)Height - 1)); + + return new Point(x, y); } + + // TranslatePoint will only translate the given point from an upper left origin system to a bottom left origin system public Point TranslatePoint(Point sourcePoint) {