Skip to content

Commit 42098c5

Browse files
authored
Doing some improvements to continuity. (#395)
Breaking Continuity related objects into their own namespace. Adding unit tests for some math utilities. Putting constants as enum classes in a more central place.
1 parent 6887c0a commit 42098c5

File tree

76 files changed

+2732
-3163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2732
-3163
lines changed

src/AnimationCanvas.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ static auto CalcUserScaleAndOffset(std::pair<wxPoint, wxPoint> const& sizeAndOff
9595
// always choose x when the new aspect ratio is smaller than the show.
9696
// This will keep the whole field on in the canvas
9797
if (newSizeRatio < showAspectRatio) {
98-
newvalue = newX / (float)CoordUnits2Int(x);
98+
newvalue = newX / (float)CalChart::CoordUnits2Int(x);
9999
} else {
100-
newvalue = newY / (float)CoordUnits2Int(y);
100+
newvalue = newY / (float)CalChart::CoordUnits2Int(y);
101101
}
102-
auto userScale = newvalue * (CoordUnits2Int(1 << 16) / 65536.0);
102+
auto userScale = newvalue * (CalChart::CoordUnits2Int(1 << 16) / 65536.0);
103103

104104
auto offsetx = sizeAndOffset.second.x + sizeAndOffset.first.x / 2;
105105
auto offsety = sizeAndOffset.second.y + sizeAndOffset.first.y / 2;
@@ -167,7 +167,7 @@ void AnimationCanvas::OnLeftUpMouseEvent(wxMouseEvent& event)
167167

168168
// if mouse lifted very close to where clicked, then it is a previous beat
169169
// move
170-
if ((std::abs(mMouseEnd.x - mMouseStart.x) < Int2CoordUnits(1) / 2) && (std::abs(mMouseEnd.y - mMouseStart.y) < Int2CoordUnits(1) / 2)) {
170+
if ((std::abs(mMouseEnd.x - mMouseStart.x) < CalChart::Int2CoordUnits(1) / 2) && (std::abs(mMouseEnd.y - mMouseStart.y) < CalChart::Int2CoordUnits(1) / 2)) {
171171
mView->ToggleTimer();
172172
} else {
173173
mView->SelectMarchersInBox(mMouseStart, mMouseEnd, event.AltDown());
@@ -217,7 +217,7 @@ void AnimationCanvas::UpdateScaleAndOrigin()
217217
auto window_size = GetSize();
218218
auto boundingBox = mZoomOnMarchers ? mView->GetMarcherSizeAndOffset() : mView->GetShowSizeAndOffset();
219219
if (mZoomOnMarchers) {
220-
auto amount = Int2CoordUnits(mStepsOutForMarcherZoom);
220+
auto amount = CalChart::Int2CoordUnits(mStepsOutForMarcherZoom);
221221
boundingBox.first += wxPoint(amount, amount) * 2;
222222
boundingBox.second -= wxPoint(amount, amount);
223223
}

src/AnimationErrorsPanel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void AnimationErrorsPanel::OnItemActivated(wxTreeListEvent& event)
101101
}
102102

103103
// Implementation details
104-
void AnimationErrorsPanel::UpdateErrors(std::vector<CalChart::AnimationErrors> const& errors, std::map<int, SelectionList> const& collisions)
104+
void AnimationErrorsPanel::UpdateErrors(std::vector<CalChart::AnimationErrors> const& errors, std::map<int, CalChart::SelectionList> const& collisions)
105105
{
106106
if (errors == mCurrentErrors) {
107107
return;
@@ -114,7 +114,7 @@ void AnimationErrorsPanel::UpdateErrors(std::vector<CalChart::AnimationErrors> c
114114

115115
// we create a mapping between the generated errors and the items we've put in the list
116116
// categorize by animation error, mapping them to the sheet and ErrorMarker
117-
std::map<CalChart::AnimateError, std::vector<std::tuple<int, SelectionList>>> allErrors;
117+
std::map<CalChart::AnimateError, std::vector<std::tuple<int, CalChart::SelectionList>>> allErrors;
118118
for (auto i = 0ul; i < mCurrentErrors.size(); ++i) {
119119
for (auto&& error : mCurrentErrors[i].GetErrors()) {
120120
allErrors[error.first].push_back({ i, error.second.pntgroup });

src/AnimationErrorsPanel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class AnimationErrorsPanel : public wxPanel {
5050
void OnItemActivated(wxTreeListEvent& event);
5151

5252
// Internals
53-
void UpdateErrors(std::vector<CalChart::AnimationErrors> const& errors, std::map<int, SelectionList> const& collisions);
53+
void UpdateErrors(std::vector<CalChart::AnimationErrors> const& errors, std::map<int, CalChart::SelectionList> const& collisions);
5454

5555
CalChartView* mView{};
5656
wxTreeListCtrl* mTreeCtrl{};
5757
std::vector<CalChart::AnimationErrors> mCurrentErrors{};
58-
std::map<wxTreeListItem, std::tuple<int, SelectionList>> mErrorLookup{};
58+
std::map<wxTreeListItem, std::tuple<int, CalChart::SelectionList>> mErrorLookup{};
5959
};

src/AnimationView.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "CalChartSheet.h"
3030
#include "CalChartShowMode.h"
3131
#include "CalChartSizes.h"
32+
#include "CalChartUtils.h"
3233
#include "CalChartView.h"
3334
#include "draw.h"
34-
#include "math_utils.h"
3535
#include "platconf.h"
3636

3737
#include <wx/dcbuffer.h>
@@ -106,17 +106,17 @@ void AnimationView::OnDrawDots(wxDC& dc, CalChartConfiguration const& config)
106106
dc.SetPen(brushAndPen.second);
107107
}
108108
} else if (mView->IsSelected(info.index)) {
109-
switch (info.mDirection) {
110-
case CalChart::AnimateDir::SW:
111-
case CalChart::AnimateDir::W:
112-
case CalChart::AnimateDir::NW: {
109+
switch (AngleToDirection(info.mFacingDirection)) {
110+
case CalChart::Direction::SouthWest:
111+
case CalChart::Direction::West:
112+
case CalChart::Direction::NorthWest: {
113113
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_BACK);
114114
dc.SetBrush(brushAndPen.first);
115115
dc.SetPen(brushAndPen.second);
116116
} break;
117-
case CalChart::AnimateDir::SE:
118-
case CalChart::AnimateDir::E:
119-
case CalChart::AnimateDir::NE: {
117+
case CalChart::Direction::SouthEast:
118+
case CalChart::Direction::East:
119+
case CalChart::Direction::NorthEast: {
120120
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_HILIT_FRONT);
121121
dc.SetBrush(brushAndPen.first);
122122
dc.SetPen(brushAndPen.second);
@@ -128,17 +128,17 @@ void AnimationView::OnDrawDots(wxDC& dc, CalChartConfiguration const& config)
128128
}
129129
}
130130
} else {
131-
switch (info.mDirection) {
132-
case CalChart::AnimateDir::SW:
133-
case CalChart::AnimateDir::W:
134-
case CalChart::AnimateDir::NW: {
131+
switch (AngleToDirection(info.mFacingDirection)) {
132+
case CalChart::Direction::SouthWest:
133+
case CalChart::Direction::West:
134+
case CalChart::Direction::NorthWest: {
135135
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_BACK);
136136
dc.SetBrush(brushAndPen.first);
137137
dc.SetPen(brushAndPen.second);
138138
} break;
139-
case CalChart::AnimateDir::SE:
140-
case CalChart::AnimateDir::E:
141-
case CalChart::AnimateDir::NE: {
139+
case CalChart::Direction::SouthEast:
140+
case CalChart::Direction::East:
141+
case CalChart::Direction::NorthEast: {
142142
auto brushAndPen = config.Get_CalChartBrushAndPen(COLOR_POINT_ANIM_FRONT);
143143
dc.SetBrush(brushAndPen.first);
144144
dc.SetPen(brushAndPen.second);
@@ -154,7 +154,7 @@ void AnimationView::OnDrawDots(wxDC& dc, CalChartConfiguration const& config)
154154
auto x = position.x + mView->GetShowMode().Offset().x;
155155
auto y = position.y + mView->GetShowMode().Offset().y;
156156
auto drawPosition = fDIP(wxPoint(x, y));
157-
auto rectangleSize = fDIP(wxSize(Int2CoordUnits(1), Int2CoordUnits(1)));
157+
auto rectangleSize = fDIP(wxSize(CalChart::Int2CoordUnits(1), CalChart::Int2CoordUnits(1)));
158158

159159
dc.DrawRectangle(drawPosition - rectangleSize / 2, rectangleSize);
160160
}
@@ -169,7 +169,7 @@ void AnimationView::OnDrawSprites(wxDC& dc, CalChartConfiguration const& config)
169169
for (auto info : mAnimation->GetAllAnimateInfo()) {
170170
auto image_offset = !GetAnimationFrame()->TimerOn() ? 0 : OnBeat() ? 1
171171
: 2;
172-
auto image_index = static_cast<int>(info.mDirection) + image_offset * 8;
172+
auto image_index = AngleToQuadrant(info.mFacingDirection) + image_offset * 8;
173173
auto image = mSpriteImages[image_index];
174174
image = image.Scale(image.GetWidth() * scale, image.GetHeight() * scale);
175175
if (mView->IsSelected(info.index)) {
@@ -331,13 +331,13 @@ MarcherInfo AnimationView::GetMarcherInfo(int which) const
331331
MarcherInfo info{};
332332
if (mAnimation) {
333333
auto anim_info = mAnimation->GetAnimateInfo(which);
334-
info.direction = NormalizeAngleRad((anim_info.mRealDirection * M_PI / 180.0));
334+
info.direction = NormalizeAngleRad((anim_info.mFacingDirection * M_PI / 180.0));
335335

336336
auto position = anim_info.mPosition;
337-
info.x = CoordUnits2Float(position.x);
337+
info.x = CalChart::CoordUnits2Float(position.x);
338338
// because the coordinate system for continuity and OpenGL are different,
339339
// correct here.
340-
info.y = -1.0 * CoordUnits2Float(position.y);
340+
info.y = -1.0 * CalChart::CoordUnits2Float(position.y);
341341
}
342342
return info;
343343
}

src/BackgroundImages.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "BackgroundImages.h"
2424
#include "CalChartImage.h"
25+
#include "CalChartTypes.h"
2526
#include <algorithm>
2627

2728
class BackgroundImage {
@@ -80,12 +81,6 @@ BackgroundImage::BackgroundImage(const wxImage& image, int x, int y, int scaled_
8081
mBitmap = wxBitmap(mImage.Scale(scaled_width, scaled_height, wxIMAGE_QUALITY_HIGH));
8182
}
8283

83-
template <typename E>
84-
constexpr auto toUType(E enumerator)
85-
{
86-
return static_cast<std::underlying_type_t<E>>(enumerator);
87-
}
88-
8984
bool BackgroundImage::MouseClickIsHit(const wxMouseEvent& event, const wxDC& dc) const
9085
{
9186
auto point = event.GetPosition();

src/CCOmniviewCanvas.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#include "CalChartConfiguration.h"
3030
#include "CalChartDoc.h"
3131
#include "CalChartShowMode.h"
32+
#include "CalChartUtils.h"
3233
#include "basic_ui.h"
3334
#include "cc_omniview_constants.h"
3435
#include "draw.h"
35-
#include "math_utils.h"
3636
#include "platconf.h"
3737

3838
#include <wx/dcbuffer.h>
@@ -689,8 +689,8 @@ void CCOmniviewCanvas::OnPaint(wxPaintEvent&)
689689
glViewport(0, 0, ClientSize.x, ClientSize.y);
690690

691691
CalChart::Coord fieldSize = mView ? mView->GetShowMode().FieldSize() : CalChart::Coord(160, 80);
692-
float FieldEW = CoordUnits2Float(fieldSize.y);
693-
float FieldNS = CoordUnits2Float(fieldSize.x);
692+
float FieldEW = CalChart::CoordUnits2Float(fieldSize.y);
693+
float FieldNS = CalChart::CoordUnits2Float(fieldSize.x);
694694

695695
glClear(GL_COLOR_BUFFER_BIT);
696696
// set our view point:

src/CalChartDoc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include "CalChartShapes.h"
2929
#include "CalChartSheet.h"
3030
#include "CalChartShowMode.h"
31+
#include "CalChartUtils.h"
3132
#include "ContinuityEditorPopup.h"
3233
#include "draw.h"
33-
#include "math_utils.h"
3434
#include "platconf.h"
3535
#include "print_ps.h"
3636

src/CalChartDoc.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ class CalChartDoc : public wxDocument {
162162
// Then you push the selection list with the Create_SetSelectionListCommand
163163
auto MakeSelectAll() const { return mShow->MakeSelectAll(); }
164164
auto MakeUnselectAll() const { return mShow->MakeUnselectAll(); }
165-
auto MakeAddToSelection(const SelectionList& sl) const { return mShow->MakeAddToSelection(sl); }
166-
auto MakeRemoveFromSelection(const SelectionList& sl) const { return mShow->MakeRemoveFromSelection(sl); }
167-
auto MakeToggleSelection(const SelectionList& sl) const { return mShow->MakeToggleSelection(sl); }
165+
auto MakeAddToSelection(const CalChart::SelectionList& sl) const { return mShow->MakeAddToSelection(sl); }
166+
auto MakeRemoveFromSelection(const CalChart::SelectionList& sl) const { return mShow->MakeRemoveFromSelection(sl); }
167+
auto MakeToggleSelection(const CalChart::SelectionList& sl) const { return mShow->MakeToggleSelection(sl); }
168168
auto MakeSelectWithinPolygon(CalChart::RawPolygon_t const& polygon) const { return mShow->MakeSelectWithinPolygon(polygon, mCurrentReferencePoint); }
169-
auto MakeSelectBySymbol(SYMBOL_TYPE symbol) const { return mShow->MakeSelectBySymbol(symbol); }
169+
auto MakeSelectBySymbol(CalChart::SYMBOL_TYPE symbol) const { return mShow->MakeSelectBySymbol(symbol); }
170170
auto MakeSelectByInstrument(std::string const& instrument) const { return mShow->MakeSelectByInstrument(instrument); }
171171
auto MakeSelectByLabel(std::string const& label) const { return mShow->MakeSelectByLabel(label); }
172172

173-
void SetSelectionList(SelectionList const& sl);
173+
void SetSelectionList(CalChart::SelectionList const& sl);
174174

175175
auto IsSelected(int i) const { return mShow->IsSelected(i); }
176176
auto GetSelectionList() const { return mShow->GetSelectionList(); }
@@ -201,8 +201,8 @@ class CalChartDoc : public wxDocument {
201201

202202
// create a set of commands to apply to the document. This is the best way to interact with the doc.
203203
std::unique_ptr<wxCommand> Create_SetCurrentSheetCommand(int n);
204-
std::unique_ptr<wxCommand> Create_SetSelectionListCommand(const SelectionList& sl);
205-
std::unique_ptr<wxCommand> Create_SetCurrentSheetAndSelectionCommand(int n, const SelectionList& sl);
204+
std::unique_ptr<wxCommand> Create_SetSelectionListCommand(const CalChart::SelectionList& sl);
205+
std::unique_ptr<wxCommand> Create_SetCurrentSheetAndSelectionCommand(int n, const CalChart::SelectionList& sl);
206206
std::unique_ptr<wxCommand> Create_SetShowModeCommand(CalChart::ShowMode const& newmode);
207207
std::unique_ptr<wxCommand> Create_SetupMarchersCommand(std::vector<std::pair<std::string, std::string>> const& labels, int numColumns);
208208
std::unique_ptr<wxCommand> Create_SetInstrumentsCommand(std::map<int, std::string> const& dotToInstrument);
@@ -218,16 +218,16 @@ class CalChartDoc : public wxDocument {
218218
std::unique_ptr<wxCommand> Create_DeletePointsCommand();
219219
std::unique_ptr<wxCommand> Create_RotatePointPositionsCommand(int rotateAmount);
220220
std::unique_ptr<wxCommand> Create_ResetReferencePointToRef0();
221-
std::unique_ptr<wxCommand> Create_SetSymbolCommand(SYMBOL_TYPE sym);
222-
std::unique_ptr<wxCommand> Create_SetContinuityCommand(SYMBOL_TYPE i, CalChart::Continuity const& new_cont);
221+
std::unique_ptr<wxCommand> Create_SetSymbolCommand(CalChart::SYMBOL_TYPE sym);
222+
std::unique_ptr<wxCommand> Create_SetContinuityCommand(CalChart::SYMBOL_TYPE i, CalChart::Continuity const& new_cont);
223223
std::unique_ptr<wxCommand> Create_SetLabelRightCommand(bool right);
224224
std::unique_ptr<wxCommand> Create_ToggleLabelFlipCommand();
225225
std::unique_ptr<wxCommand> Create_SetLabelVisibleCommand(bool isVisible);
226226
std::unique_ptr<wxCommand> Create_ToggleLabelVisibilityCommand();
227227
std::unique_ptr<wxCommand> Create_AddNewBackgroundImageCommand(int left, int top, int image_width, int image_height, std::vector<unsigned char> const& data, std::vector<unsigned char> const& alpha);
228228
std::unique_ptr<wxCommand> Create_RemoveBackgroundImageCommand(int which);
229229
std::unique_ptr<wxCommand> Create_MoveBackgroundImageCommand(int which, int left, int top, int scaled_width, int scaled_height);
230-
std::unique_ptr<wxCommand> Create_SetTransitionCommand(const std::vector<CalChart::Coord>& finalPositions, const std::map<SYMBOL_TYPE, std::string>& continuities, const std::vector<SYMBOL_TYPE>& marcherDotTypes);
230+
std::unique_ptr<wxCommand> Create_SetTransitionCommand(const std::vector<CalChart::Coord>& finalPositions, const std::map<CalChart::SYMBOL_TYPE, std::string>& continuities, const std::vector<CalChart::SYMBOL_TYPE>& marcherDotTypes);
231231

232232
private:
233233
static CC_doc_command_pair Inject_CalChartDocArg(CalChart::Show_command_pair);

src/CalChartFrame.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ static std::map<int, std::string> kAUIEnumToString = {
8282
{ CALCHART__ViewMarcherToolBar, "Marcher ToolBar" },
8383
};
8484

85-
template <typename E>
86-
constexpr auto toUType(E enumerator)
87-
{
88-
return static_cast<std::underlying_type_t<E>>(enumerator);
89-
}
90-
9185
BEGIN_EVENT_TABLE(CalChartFrame, wxDocChildFrame)
9286
EVT_CHAR(CalChartFrame::OnChar)
9387
EVT_MENU(CALCHART__APPEND_FILE, CalChartFrame::OnCmdAppend)
@@ -876,42 +870,42 @@ void CalChartFrame::OnCmd_label_visibility_toggle(wxCommandEvent&)
876870

877871
void CalChartFrame::OnCmd_setsym0(wxCommandEvent&)
878872
{
879-
GetFieldView()->DoSetPointsSymbol(SYMBOL_PLAIN);
873+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_PLAIN);
880874
}
881875

882876
void CalChartFrame::OnCmd_setsym1(wxCommandEvent&)
883877
{
884-
GetFieldView()->DoSetPointsSymbol(SYMBOL_SOL);
878+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_SOL);
885879
}
886880

887881
void CalChartFrame::OnCmd_setsym2(wxCommandEvent&)
888882
{
889-
GetFieldView()->DoSetPointsSymbol(SYMBOL_BKSL);
883+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_BKSL);
890884
}
891885

892886
void CalChartFrame::OnCmd_setsym3(wxCommandEvent&)
893887
{
894-
GetFieldView()->DoSetPointsSymbol(SYMBOL_SL);
888+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_SL);
895889
}
896890

897891
void CalChartFrame::OnCmd_setsym4(wxCommandEvent&)
898892
{
899-
GetFieldView()->DoSetPointsSymbol(SYMBOL_X);
893+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_X);
900894
}
901895

902896
void CalChartFrame::OnCmd_setsym5(wxCommandEvent&)
903897
{
904-
GetFieldView()->DoSetPointsSymbol(SYMBOL_SOLBKSL);
898+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_SOLBKSL);
905899
}
906900

907901
void CalChartFrame::OnCmd_setsym6(wxCommandEvent&)
908902
{
909-
GetFieldView()->DoSetPointsSymbol(SYMBOL_SOLSL);
903+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_SOLSL);
910904
}
911905

912906
void CalChartFrame::OnCmd_setsym7(wxCommandEvent&)
913907
{
914-
GetFieldView()->DoSetPointsSymbol(SYMBOL_SOLX);
908+
GetFieldView()->DoSetPointsSymbol(CalChart::SYMBOL_SOLX);
915909
}
916910

917911
void CalChartFrame::OnChar(wxKeyEvent& event) { mCanvas->OnChar(event); }

src/CalChartSplash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct CalChartSplashDropTarget : public wxFileDropTarget {
5555
};
5656

5757
CalChartSplash::CalChartSplash(wxDocManager* manager, wxFrame* frame, wxString const& title)
58-
: super(manager, frame, wxID_ANY, title)//, wxDefaultPosition, wxSize(154, 174))
58+
: super(manager, frame, wxID_ANY, title)
5959
{
6060
// Give it an icon
6161
SetBandIcon(this);

0 commit comments

Comments
 (0)