From d4c97aaf0ab60cd6326863a4db4a673ed0b35416 Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 10 Mar 2026 23:42:21 -0400 Subject: [PATCH] Fix Point Mapping. --- MarketDataLib/CNNProcessing/PointMapping.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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) {