@@ -87,17 +87,23 @@ public DataPoint(DateTime time, double value)
8787 [ DebuggerStepThrough ]
8888 public double Gradient ( in DataPoint b , bool return0OnEquality = true )
8989 {
90- if ( this . X == b . X ) return this . GradientEquality ( b , return0OnEquality ) ;
90+ double delta_y = b . Y - this . Y ;
91+ double delta_x = b . X - this . X ;
9192
92- return ( b . Y - this . Y ) / ( b . X - this . X ) ;
93+ if ( delta_x == 0d ) return this . GradientEquality ( b , return0OnEquality ) ;
94+
95+ return delta_y / delta_x ;
9396 }
9497 //---------------------------------------------------------------------
9598 [ DebuggerStepThrough ]
9699 internal double Gradient ( in DataPoint b , double deltaY , bool return0OnEquality = true )
97100 {
98- if ( this . X == b . X ) return this . GradientEquality ( b , return0OnEquality ) ;
101+ double delta_y = b . Y + deltaY - this . Y ;
102+ double delta_x = b . X - this . X ;
103+
104+ if ( delta_x == 0d ) return this . GradientEquality ( b , return0OnEquality ) ;
99105
100- return ( b . Y + deltaY - this . Y ) / ( b . X - this . X ) ;
106+ return delta_y / delta_x ;
101107 }
102108 //---------------------------------------------------------------------
103109 // Uncommon code-path
@@ -132,9 +138,12 @@ private double GradientEquality(in DataPoint b, bool return0OnEquality)
132138 /// </remarks>
133139 public double CalculatePoint ( double gradient , double x )
134140 {
135- if ( this . X == x ) return this . Y ;
141+ double y = this . Y ;
142+ x -= this . X ;
143+
144+ if ( x == 0 ) return y ;
136145
137- return this . Y + gradient * ( x - this . X ) ;
146+ return y + gradient * x ;
138147 }
139148 //---------------------------------------------------------------------
140149 /// <summary>
0 commit comments