Updated APIs to use new GetClosePointData() from Graphing Engine. (#1250)
* Updated APIs to use new GetClosePointData() from Graphing Engine. Now specifiying precision on API consumption to aid with correct display and rounding. * Updated function to be const-corect * Updated to use correct APIs * Converted TraceValue from Point to two doubles, point's X and Y was using float and conversion between float and doubles was causing unwanted rounding. * Update to pch file and fixing typo * Point to updated graphing version
This commit is contained in:
committed by
GitHub
parent
2608a353de
commit
0175b51655
@@ -649,7 +649,7 @@ namespace GraphControl
|
||||
if (m_renderMain->Tracing)
|
||||
{
|
||||
TracingChangedEvent(true);
|
||||
TracingValueChangedEvent(m_renderMain->TraceValue);
|
||||
TracingValueChangedEvent(m_renderMain->XTraceValue, m_renderMain->YTraceValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -21,7 +21,7 @@ public
|
||||
delegate void TracingChangedEventHandler(bool newValue);
|
||||
|
||||
public
|
||||
delegate void TracingValueChangedEventHandler(Windows::Foundation::Point value);
|
||||
delegate void TracingValueChangedEventHandler(double xPointValue, double yPointValue);
|
||||
public
|
||||
delegate void PointerValueChangedEventHandler(Windows::Foundation::Point value);
|
||||
|
||||
@@ -82,13 +82,6 @@ public enum class GraphViewChangedReason
|
||||
void ZoomFromCenter(double scale);
|
||||
void ResetGrid();
|
||||
|
||||
property Windows::Foundation::Point TraceValue
|
||||
{
|
||||
Windows::Foundation::Point get()
|
||||
{
|
||||
return m_renderMain->TraceValue;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::Foundation::Point TraceLocation
|
||||
{
|
||||
|
@@ -33,8 +33,7 @@ namespace GraphControl::DX
|
||||
: m_deviceResources{ panel }
|
||||
, m_nearestPointRenderer{ &m_deviceResources }
|
||||
, m_backgroundColor{ {} }
|
||||
, m_swapChainPanel{ panel }
|
||||
, m_TraceValue(Point(0, 0))
|
||||
, m_swapChainPanel{ panel }
|
||||
, m_TraceLocation(Point(0, 0))
|
||||
, m_Tracing(false)
|
||||
{
|
||||
@@ -157,21 +156,28 @@ namespace GraphControl::DX
|
||||
critical_section::scoped_lock lock(m_criticalSection);
|
||||
|
||||
int formulaId = -1;
|
||||
float nearestPointLocationX, nearestPointLocationY;
|
||||
double nearestPointValueX, nearestPointValueY, rhoValueOut, thetaValueOut, tValueOut;
|
||||
double outNearestPointValueX, outNearestPointValueY;
|
||||
float outNearestPointLocationX, outNearestPointLocationY;
|
||||
double rhoValueOut, thetaValueOut, tValueOut;
|
||||
|
||||
double xAxisMin, xAxisMax, yAxisMin, yAxisMax;
|
||||
m_graph->GetRenderer()->GetDisplayRanges(xAxisMin, xAxisMax, yAxisMin, yAxisMax);
|
||||
double precision = this->GetPrecision(xAxisMax, xAxisMin);
|
||||
|
||||
m_Tracing = m_graph->GetRenderer()->GetClosePointData(
|
||||
trackPoint.X,
|
||||
trackPoint.Y,
|
||||
precision,
|
||||
formulaId,
|
||||
nearestPointLocationX,
|
||||
nearestPointLocationY,
|
||||
nearestPointValueX,
|
||||
nearestPointValueY,
|
||||
outNearestPointLocationX,
|
||||
outNearestPointLocationY,
|
||||
outNearestPointValueX,
|
||||
outNearestPointValueY,
|
||||
rhoValueOut,
|
||||
thetaValueOut,
|
||||
tValueOut)
|
||||
== S_OK;
|
||||
m_Tracing = m_Tracing && !isnan(nearestPointLocationX) && !isnan(nearestPointLocationY);
|
||||
m_Tracing = m_Tracing && !isnan(outNearestPointLocationX) && !isnan(outNearestPointLocationY);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -181,6 +187,22 @@ namespace GraphControl::DX
|
||||
return m_Tracing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the precision value by computing the max and min
|
||||
/// through this formula:
|
||||
/// 10^(floor(log(max-min))-3)
|
||||
/// https://github.com/microsoft/calculator/issues/998
|
||||
/// </summary>
|
||||
/// <param name="maxAxis">max axis</param>
|
||||
/// <param name="minAxis">min axis</param>
|
||||
/// <returns>the precision value</returns>
|
||||
double RenderMain::GetPrecision(const double maxAxis, const double minAxis)
|
||||
{
|
||||
double exponent = static_cast<double>(floor(log10(maxAxis - minAxis)) - 3);
|
||||
double precision = pow(10, exponent);
|
||||
return precision;
|
||||
}
|
||||
|
||||
void RenderMain::SetPointRadius(float radius)
|
||||
{
|
||||
m_nearestPointRenderer.SetRadius(radius);
|
||||
@@ -297,23 +319,27 @@ namespace GraphControl::DX
|
||||
}
|
||||
|
||||
int formulaId = -1;
|
||||
float nearestPointLocationX, nearestPointLocationY;
|
||||
double nearestPointValueX, nearestPointValueY, rhoValueOut, thetaValueOut, tValueOut;
|
||||
|
||||
double outNearestPointValueX, outNearestPointValueY;
|
||||
double rhoValueOut, thetaValueOut, tValueOut;
|
||||
float outNearestPointLocationX, outNearestPointLocationY;
|
||||
double xAxisMin, xAxisMax, yAxisMin, yAxisMax;
|
||||
renderer->GetDisplayRanges(xAxisMin, xAxisMax, yAxisMin, yAxisMax);
|
||||
double precision = this->GetPrecision(xAxisMax, xAxisMin);
|
||||
if (renderer->GetClosePointData(
|
||||
trackPoint.X,
|
||||
trackPoint.Y,
|
||||
precision,
|
||||
formulaId,
|
||||
nearestPointLocationX,
|
||||
nearestPointLocationY,
|
||||
nearestPointValueX,
|
||||
nearestPointValueY,
|
||||
outNearestPointLocationX,
|
||||
outNearestPointLocationY,
|
||||
outNearestPointValueX,
|
||||
outNearestPointValueY,
|
||||
rhoValueOut,
|
||||
thetaValueOut,
|
||||
tValueOut)
|
||||
== S_OK)
|
||||
{
|
||||
if (!isnan(nearestPointLocationX) && !isnan(nearestPointLocationY))
|
||||
if (!isnan(outNearestPointLocationX) && !isnan(outNearestPointLocationY))
|
||||
{
|
||||
auto lineColors = m_graph->GetOptions().GetGraphColors();
|
||||
|
||||
@@ -323,11 +349,12 @@ namespace GraphControl::DX
|
||||
m_nearestPointRenderer.SetColor(D2D1::ColorF(dotColor.R * 65536 + dotColor.G * 256 + dotColor.B, 1.0));
|
||||
}
|
||||
|
||||
m_TraceLocation = Point(nearestPointLocationX, nearestPointLocationY);
|
||||
m_TraceLocation = Point(outNearestPointLocationX, outNearestPointLocationY);
|
||||
m_nearestPointRenderer.Render(m_TraceLocation);
|
||||
m_Tracing = true;
|
||||
m_TraceLocation = Point(nearestPointLocationX, nearestPointLocationY);
|
||||
m_TraceValue = Point(nearestPointValueX, nearestPointValueY);
|
||||
m_TraceLocation = Point(outNearestPointLocationX, outNearestPointLocationY);
|
||||
m_XTraceValue = outNearestPointValueX;
|
||||
m_YTraceValue = outNearestPointValueY;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -94,11 +94,19 @@ namespace GraphControl::DX
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::Foundation::Point TraceValue
|
||||
property double XTraceValue
|
||||
{
|
||||
Windows::Foundation::Point get()
|
||||
double get()
|
||||
{
|
||||
return m_TraceValue;
|
||||
return m_XTraceValue;
|
||||
}
|
||||
}
|
||||
|
||||
property double YTraceValue
|
||||
{
|
||||
double get()
|
||||
{
|
||||
return m_YTraceValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +150,8 @@ namespace GraphControl::DX
|
||||
// Other event handlers.
|
||||
void OnCompositionScaleChanged(Windows::UI::Xaml::Controls::SwapChainPanel ^ sender, Object ^ args);
|
||||
void OnSizeChanged(Platform::Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
|
||||
|
||||
|
||||
double GetPrecision(const double maxAxis, const double minAxis);
|
||||
private:
|
||||
DX::DeviceResources m_deviceResources;
|
||||
NearestPointRenderer m_nearestPointRenderer;
|
||||
@@ -177,10 +186,11 @@ namespace GraphControl::DX
|
||||
|
||||
// Track our independent input on a background worker thread.
|
||||
Windows::Foundation::IAsyncAction ^ m_inputLoopWorker = nullptr;
|
||||
Windows::UI::Core::CoreIndependentInputSource ^ m_coreInput = nullptr;
|
||||
Windows::UI::Core::CoreIndependentInputSource ^ m_coreInput = nullptr;
|
||||
|
||||
double m_XTraceValue;
|
||||
double m_YTraceValue;
|
||||
|
||||
// What is the current trace value
|
||||
Windows::Foundation::Point m_TraceValue;
|
||||
|
||||
// And where is it located on screen
|
||||
Windows::Foundation::Point m_TraceLocation;
|
||||
|
Reference in New Issue
Block a user