Audacity 3.2.0
RealFormat.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 RealFormat.cpp
6
7 Dominic Mazzoni
8 Michael Papadopoulos split from Ruler.h
9
10**********************************************************************/
11
12#include "RealFormat.h"
13
15{
16 static RealFormat instance{ false };
17 return instance;
18}
19
21{
22 static RealFormat instance{ true };
23 return instance;
24}
25
27 double units, double& major, double& minor, double& minorMinor,
28 int& mDigits
29) const
30{
31 double d = 0.000001;
32 mDigits = 6;
33 for (;;) {
34 if (units < d) {
35 minor = d;
36 major = d * 5.0;
37 return;
38 }
39 d *= 5.0;
40 if (units < d) {
41 minor = d;
42 major = d * 2.0;
43 return;
44 }
45 d *= 2.0;
46 mDigits--;
47 // More than 10 digit numbers? Something is badly wrong.
48 // Probably units is coming in with too high a value.
49 wxASSERT(mDigits >= -10);
50 if (mDigits < -10)
51 break;
52 }
53 if (mLog) {
54 mDigits++;
55 }
56 minor = d;
57 major = d * 2.0;
58}
59
61 wxString& s, double d, double, double minor, int mDigits, TickType tickType
62) const
63{
64 // Replace -0 with 0
65 if (d < 0.0 && (d + minor > 0.0) && !mLog)
66 d = 0.0;
67 if (minor >= 1.0)
68 s.Printf(wxT("%d"), (int)floor(d + 0.5));
69 else {
70 s.Printf(wxString::Format(wxT("%%.%df"), mDigits), d);
71 }
72}
73
74RealFormat::~RealFormat() = default;
wxT("CloseDown"))
void SetTickSizes(double units, double &major, double &minor, double &minorMinor, int &mDigits) const override
Definition: RealFormat.cpp:26
const bool mLog
Definition: RealFormat.h:35
static const RealFormat & LinearInstance()
Definition: RealFormat.cpp:14
static const RealFormat & LogInstance()
Definition: RealFormat.cpp:20
~RealFormat() override
void SetLabelString(wxString &s, double d, double units, double minor, int mDigits, TickType tickType) const override
Definition: RealFormat.cpp:60