From 5fe4007fd5bdf46efee8ea8a99a48396f4785974 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 27 Jul 2024 18:11:41 +0200 Subject: [PATCH] drawing tool:: improved the performance of mouse_snap --- mapeditor.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mapeditor.cpp b/mapeditor.cpp index 884c5d2d..d6162500 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -2218,14 +2218,12 @@ EX namespace mapeditor { EX shiftpoint mouse_snap() { ld xdist = HUGE_VAL; - shiftpoint resh; + shiftpoint resh = mouseh; auto snap_to = [&] (shiftpoint h) { ld dist = hdist(h, mouseh); if(dist < xdist) xdist = dist, resh = h; }; - for(auto& p: gmatrix) { - cell *c = p.first; - auto& T = p.second; + auto snap_to_tile_matrix = [&] (cell *c, const shiftmatrix& T) { snap_to(T * C0); for(int i=0; itype; i++) { hyperpoint h1 = get_corner_position(c, i); @@ -2233,7 +2231,13 @@ EX namespace mapeditor { snap_to(T * h1); snap_to(T * mid(h1, h2)); } - } + }; + auto snap_to_tile = [&] (cell *c) { + auto p = at_or_null(gmatrix, c); + if(!p) return; + snap_to_tile_matrix(c, *p); + }; + snap_to_tile(mouseover); return resh; }