From 4df96acf3b42eb117c3b30db38894fb6bb791922 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 19 Feb 2011 16:53:27 +0000 Subject: [PATCH] Connect up diagonal track --- include/Maths.hpp | 4 ++++ src/Editor.cpp | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/Maths.hpp b/include/Maths.hpp index 276768b..1b1f4ed 100644 --- a/include/Maths.hpp +++ b/include/Maths.hpp @@ -244,6 +244,10 @@ struct Point { Point right() const { return Point(x + 1, y); } Point up() const { return Point(x, y + 1); } Point down() const { return Point(x, y - 1); } + Point up_left() const { return Point(x - 1, y + 1); } + Point up_right() const { return Point(x + 1, y + 1); } + Point down_left() const { return Point(x - 1, y - 1); } + Point down_right() const { return Point(x + 1, y - 1); } bool operator==(const Point& a_point) const { diff --git a/src/Editor.cpp b/src/Editor.cpp index 5498cc0..89a4ed2 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -243,6 +243,18 @@ bool Editor::guess_track_dir(const Point& p, track::Direction& d) const else if (can_connect(p.down(), p)) { d = axis::Y; } + else if (can_connect(p.up_left(), p)) { + d = -make_vector(-1, 0, 1); + } + else if (can_connect(p.up_right(), p)) { + d = -make_vector(1, 0, 1); + } + else if (can_connect(p.down_left(), p)) { + d = -make_vector(-1, 0, -1); + } + else if (can_connect(p.down_right(), p)) { + d = -make_vector(1, 0, -1); + } else return false; @@ -442,15 +454,21 @@ void Editor::draw_dragged_track() << " drag_end=" << drag_end; debug() << "start_dir=" << start_dir << " end_dir=" << end_dir; - if (xlen == 1 && ylen == 1) { + const bool simple = + (start_dir.x + start_dir.z == 1) + && (end_dir.x + end_dir.z == 1); + + debug() << "simple=" << simple; + + if (simple && xlen == 1 && ylen == 1) { // A single tile draw_track_tile(drag_begin, start_dir); } - else if (xlen == 1) { + else if (simple && xlen == 1) { draw_dragged_straight(drag_begin.y < drag_end.y ? axis::Y : -axis::Y, ylen); } - else if (ylen == 1) { + else if (simple && ylen == 1) { draw_dragged_straight(drag_begin.x < drag_end.x ? axis::X : -axis::X, xlen); } -- 2.39.2