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:
parent
2608a353de
commit
0175b51655
@ -29,7 +29,7 @@ jobs:
|
||||
downloadDirectory: $(Build.SourcesDirectory)
|
||||
vstsFeed: WindowsApps
|
||||
vstsFeedPackage: calculator-internals
|
||||
vstsPackageVersion: 0.0.44
|
||||
vstsPackageVersion: 0.0.45
|
||||
|
||||
- template: ./build-single-architecture.yaml
|
||||
parameters:
|
||||
|
@ -96,7 +96,7 @@ jobs:
|
||||
downloadDirectory: $(Build.SourcesDirectory)
|
||||
vstsFeed: WindowsApps
|
||||
vstsFeedPackage: calculator-internals
|
||||
vstsPackageVersion: 0.0.44
|
||||
vstsPackageVersion: 0.0.45
|
||||
|
||||
- powershell: |
|
||||
# Just modify this line to indicate where your en-us PDP file is. Leave the other lines alone.
|
||||
|
@ -207,44 +207,15 @@ void GraphingCalculator::OnEquationsVectorChanged(IObservableVector<EquationView
|
||||
GraphingControl->PlotGraph(false);
|
||||
}
|
||||
|
||||
wstringstream GraphingCalculator::FormatTraceValue(double min, double max, float pointValue)
|
||||
{
|
||||
wstringstream traceValueString;
|
||||
|
||||
// Extract precision we will round to
|
||||
auto precision = static_cast<int>(floor(log10(max - min)) - 3);
|
||||
|
||||
// Determine if we want to show scientific notation instead
|
||||
if (precision <= -7 || precision >= 7)
|
||||
{
|
||||
traceValueString << scientific;
|
||||
}
|
||||
else
|
||||
{
|
||||
traceValueString << fixed;
|
||||
}
|
||||
|
||||
// If we are rounding to a decimal place, set the precision
|
||||
if (precision < 0)
|
||||
{
|
||||
traceValueString << setprecision(::min(7, abs(precision))) << pointValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
traceValueString << setprecision(0) << pointValue;
|
||||
}
|
||||
|
||||
return traceValueString;
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnTracePointChanged(Point newPoint)
|
||||
void GraphingCalculator::OnTracePointChanged(double xPointValue, double yPointValue)
|
||||
{
|
||||
wstringstream traceValueString;
|
||||
|
||||
double xAxisMin, xAxisMax, yAxisMin, yAxisMax;
|
||||
GraphingControl->GetDisplayRanges(&xAxisMin, &xAxisMax, &yAxisMin, &yAxisMax);
|
||||
|
||||
traceValueString << "(" << FormatTraceValue(xAxisMin, xAxisMax, newPoint.X).str() << ", " << FormatTraceValue(yAxisMin, yAxisMax, newPoint.Y).str() << ")";
|
||||
traceValueString << "(" << xPointValue << ", ";
|
||||
traceValueString << setprecision(15) << yPointValue << ")";
|
||||
|
||||
TraceValue->Text = ref new String(traceValueString.str().c_str());
|
||||
|
||||
|
@ -55,9 +55,9 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
|
||||
void OnZoomOutCommand(Object ^ parameter);
|
||||
|
||||
void OnShareClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
|
||||
|
||||
void OnShowTracePopupChanged(bool newValue);
|
||||
void OnTracePointChanged(Windows::Foundation::Point newPoint);
|
||||
void OnTracePointChanged(double xPointValue, double yPointValue);
|
||||
void OnPointerPointChanged(Windows::Foundation::Point newPoint);
|
||||
private:
|
||||
void OnDataRequested(
|
||||
@ -104,8 +104,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
|
||||
void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args);
|
||||
void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e);
|
||||
void GraphMenuFlyoutItem_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e);
|
||||
std::wstringstream FormatTraceValue(double min, double max, float pointValue);
|
||||
void OnVisualStateChanged(Platform::Object ^ sender, Windows::UI::Xaml::VisualStateChangedEventArgs ^ e);
|
||||
void GraphViewButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void ShowShareError();
|
||||
void OnGraphingCalculatorLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
|
@ -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;
|
||||
|
@ -40,6 +40,7 @@ namespace MockGraphingImpl
|
||||
virtual HRESULT GetClosePointData(
|
||||
double inScreenPointX,
|
||||
double inScreenPointY,
|
||||
double precision,
|
||||
int& formulaIdOut,
|
||||
float& xScreenPointOut,
|
||||
float& yScreenPointOut,
|
||||
@ -52,11 +53,9 @@ namespace MockGraphingImpl
|
||||
formulaIdOut = 0;
|
||||
xScreenPointOut = 0;
|
||||
yScreenPointOut = 0;
|
||||
precision = 0;
|
||||
xValueOut = 0;
|
||||
yValueOut = 0;
|
||||
rhoValueOut = 0;
|
||||
thetaValueOut = 0;
|
||||
tValueOut = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -72,7 +71,7 @@ namespace MockGraphingImpl
|
||||
virtual HRESULT ChangeRange(Graphing::Renderer::ChangeRangeAction action)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
virtual HRESULT MoveRangeByRatio(double ratioX, double ratioY)
|
||||
{
|
||||
return S_OK;
|
||||
@ -110,6 +109,7 @@ namespace MockGraphingImpl
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
double m_xMin;
|
||||
double m_xMax;
|
||||
|
@ -7,3 +7,5 @@
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
@ -23,7 +23,7 @@ namespace Graphing::Renderer
|
||||
virtual HRESULT SetDpi(float dpiX, float dpiY) = 0;
|
||||
|
||||
virtual HRESULT DrawD2D1(ID2D1Factory* pDirect2dFactory, ID2D1RenderTarget* pRenderTarget, bool& hasSomeMissingDataOut) = 0;
|
||||
virtual HRESULT GetClosePointData(double inScreenPointX, double inScreenPointY, int& formulaIdOut, float& xScreenPointOut, float& yScreenPointOut, double& xValueOut, double& yValueOut, double& rhoValueOut, double& thetaValueOut, double& tValueOut) = 0;
|
||||
virtual HRESULT GetClosePointData(double inScreenPointX, double inScreenPointY, double precision, int& formulaIdOut, float& xScreenPointOut, float& yScreenPointOut, double& xValueOut, double& yValueOut, double& rhoValueOut, double& thetaValueOut, double& tValueOut) = 0;
|
||||
|
||||
virtual HRESULT ScaleRange(double centerX, double centerY, double scale) = 0;
|
||||
virtual HRESULT ChangeRange(ChangeRangeAction action) = 0;
|
||||
@ -34,6 +34,5 @@ namespace Graphing::Renderer
|
||||
virtual HRESULT PrepareGraph() = 0;
|
||||
|
||||
virtual HRESULT GetBitmap(std::shared_ptr<Graphing::IBitmap>& bitmapOut, bool& hasSomeMissingDataOut) = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user