/// <summary> /// Gets the 2 control point indices of the line closest to the specified point (x,y) /// </summary> public bool GetLineNear( PiecewiseLinearFunction1d pwlFunc, Point2 pt, out int cp0, out int cp1, float tolerance ) { cp0 = -1; cp1 = -1; if ( pwlFunc.NumControlPoints < 2 ) { return false; } float sqrTol = tolerance * tolerance; LineSegment2 seg = new LineSegment2( ); for ( int cpIndex = 1; cpIndex < pwlFunc.NumControlPoints; ++cpIndex ) { seg.Start = pwlFunc[ cpIndex - 1 ]; seg.End = pwlFunc[ cpIndex ]; if ( seg.GetSqrDistanceToPoint( pt ) < sqrTol ) { cp0 = cpIndex - 1; cp1 = cpIndex; return true; } } return false; }
/// <summary> /// Sets the function to be controller by this handler /// </summary> public PiecewiseGraphInputHandler( PiecewiseLinearFunction1d function ) : base(function) { }