diff --git a/build/pipelines/templates/build-app-internal.yaml b/build/pipelines/templates/build-app-internal.yaml index de8992b..460c1c3 100644 --- a/build/pipelines/templates/build-app-internal.yaml +++ b/build/pipelines/templates/build-app-internal.yaml @@ -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: diff --git a/build/pipelines/templates/prepare-release-internalonly.yaml b/build/pipelines/templates/prepare-release-internalonly.yaml index 93035e2..00e978d 100644 --- a/build/pipelines/templates/prepare-release-internalonly.yaml +++ b/build/pipelines/templates/prepare-release-internalonly.yaml @@ -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. diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp index 26542d5..d7337b9 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp @@ -207,44 +207,15 @@ void GraphingCalculator::OnEquationsVectorChanged(IObservableVectorPlotGraph(false); } -wstringstream GraphingCalculator::FormatTraceValue(double min, double max, float pointValue) -{ - wstringstream traceValueString; - - // Extract precision we will round to - auto precision = static_cast(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()); diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h index 9cb083a..c825c97 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h @@ -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); diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index 45b18b8..2c75e20 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -649,7 +649,7 @@ namespace GraphControl if (m_renderMain->Tracing) { TracingChangedEvent(true); - TracingValueChangedEvent(m_renderMain->TraceValue); + TracingValueChangedEvent(m_renderMain->XTraceValue, m_renderMain->YTraceValue); } else { diff --git a/src/GraphControl/Control/Grapher.h b/src/GraphControl/Control/Grapher.h index 89bce3f..88351f5 100644 --- a/src/GraphControl/Control/Grapher.h +++ b/src/GraphControl/Control/Grapher.h @@ -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 { diff --git a/src/GraphControl/DirectX/RenderMain.cpp b/src/GraphControl/DirectX/RenderMain.cpp index 87fac0d..ee2ba60 100644 --- a/src/GraphControl/DirectX/RenderMain.cpp +++ b/src/GraphControl/DirectX/RenderMain.cpp @@ -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; } + /// + /// 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 + /// + /// max axis + /// min axis + /// the precision value + double RenderMain::GetPrecision(const double maxAxis, const double minAxis) + { + double exponent = static_cast(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 { diff --git a/src/GraphControl/DirectX/RenderMain.h b/src/GraphControl/DirectX/RenderMain.h index b9b6e01..eec3fa6 100644 --- a/src/GraphControl/DirectX/RenderMain.h +++ b/src/GraphControl/DirectX/RenderMain.h @@ -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; diff --git a/src/GraphingImpl/Mocks/GraphRenderer.h b/src/GraphingImpl/Mocks/GraphRenderer.h index 343f749..78d13c5 100644 --- a/src/GraphingImpl/Mocks/GraphRenderer.h +++ b/src/GraphingImpl/Mocks/GraphRenderer.h @@ -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; diff --git a/src/GraphingImpl/pch.h b/src/GraphingImpl/pch.h index f7ba376..d4a5d07 100644 --- a/src/GraphingImpl/pch.h +++ b/src/GraphingImpl/pch.h @@ -7,3 +7,5 @@ #endif #include +#include +#include diff --git a/src/GraphingInterfaces/IGraphRenderer.h b/src/GraphingInterfaces/IGraphRenderer.h index 58924ce..d7cdbaa 100644 --- a/src/GraphingInterfaces/IGraphRenderer.h +++ b/src/GraphingInterfaces/IGraphRenderer.h @@ -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& bitmapOut, bool& hasSomeMissingDataOut) = 0; - }; }