This commit is contained in:
dabreegster 2022-09-01 14:07:05 +00:00
parent 2bfa0b996c
commit 30607cff1d
11 changed files with 113 additions and 55 deletions

View File

@ -13,8 +13,8 @@
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.CityPicker.html" title="map_gui::tools::CityPicker struct">CityPicker</a></div><div class="item-right docblock-short"><p>Lets the player switch maps.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.ColorDiscrete.html" title="map_gui::tools::ColorDiscrete struct">ColorDiscrete</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.ColorNetwork.html" title="map_gui::tools::ColorNetwork struct">ColorNetwork</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DefaultMap.html" title="map_gui::tools::DefaultMap struct">DefaultMap</a></div><div class="item-right docblock-short"><p>Track the last map used, to resume next session.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawRoadLabels.html" title="map_gui::tools::DrawRoadLabels struct">DrawRoadLabels</a></div><div class="item-right docblock-short"><p>Labels roads when unzoomed. Label size and frequency depends on the zoom level.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawSimpleRoadLabels.html" title="map_gui::tools::DrawSimpleRoadLabels struct">DrawSimpleRoadLabels</a></div><div class="item-right docblock-short"><p>Draws labels in map-space that roughly fit on the roads and change screen-space size while
zooming.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawSimpleRoadLabels.html" title="map_gui::tools::DrawSimpleRoadLabels struct">DrawSimpleRoadLabels</a></div><div class="item-right docblock-short"><p>Draws labels in map-space that roughly fit on the roads. Dont change behavior during zooming;
labels are only meant to be legible when zoomed in.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.EditPolygon.html" title="map_gui::tools::EditPolygon struct">EditPolygon</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FilePicker.html" title="map_gui::tools::FilePicker struct">FilePicker</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Grid.html" title="map_gui::tools::Grid struct">Grid</a></div><div class="item-right docblock-short"><p>A 2D grid containing some arbitrary data.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.HeatmapOptions.html" title="map_gui::tools::HeatmapOptions struct">HeatmapOptions</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.InputWaypoints.html" title="map_gui::tools::InputWaypoints struct">InputWaypoints</a></div><div class="item-right docblock-short"><p>Click to add waypoints, drag them, see the list on a panel and delete them. The caller owns the
Panel and the World, since theres probably more stuff there too.</p>

View File

@ -5,10 +5,10 @@
</a><h2 class="location"><a href="#">Module labels</a></h2><div class="sidebar-elems"><section><div class="block"><ul><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div></section></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../map_gui/index.html"><img class="rust-logo" src="../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1">
<a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Module <a href="../../index.html">map_gui</a>::<wbr><a href="../index.html">tools</a>::<wbr><a class="mod" href="#">labels</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../../src/map_gui/tools/labels.rs.html#1-321">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2>
<h1 class="fqn"><span class="in-band">Module <a href="../../index.html">map_gui</a>::<wbr><a href="../index.html">tools</a>::<wbr><a class="mod" href="#">labels</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../../src/map_gui/tools/labels.rs.html#1-350">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawRoadLabels.html" title="map_gui::tools::labels::DrawRoadLabels struct">DrawRoadLabels</a></div><div class="item-right docblock-short"><p>Labels roads when unzoomed. Label size and frequency depends on the zoom level.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawSimpleRoadLabels.html" title="map_gui::tools::labels::DrawSimpleRoadLabels struct">DrawSimpleRoadLabels</a></div><div class="item-right docblock-short"><p>Draws labels in map-space that roughly fit on the roads and change screen-space size while
zooming.</p>
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawSimpleRoadLabels.html" title="map_gui::tools::labels::DrawSimpleRoadLabels struct">DrawSimpleRoadLabels</a></div><div class="item-right docblock-short"><p>Draws labels in map-space that roughly fit on the roads. Dont change behavior during zooming;
labels are only meant to be legible when zoomed in.</p>
</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2>
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.cheaply_overestimate_bounds.html" title="map_gui::tools::labels::cheaply_overestimate_bounds fn">cheaply_overestimate_bounds</a><span title="Restricted Visibility">&nbsp;🔒</span> </div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.simplify_name.html" title="map_gui::tools::labels::simplify_name fn">simplify_name</a><span title="Restricted Visibility">&nbsp;🔒</span> </div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.simplify_patterns.html" title="map_gui::tools::labels::simplify_patterns fn">simplify_patterns</a><span title="Restricted Visibility">&nbsp;🔒</span> </div><div class="item-right docblock-short"></div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="map_gui" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div>
</body></html>

View File

@ -1 +1 @@
window.SIDEBAR_ITEMS = {"fn":[["cheaply_overestimate_bounds",""],["simplify_name",""],["simplify_patterns",""]],"struct":[["DrawRoadLabels","Labels roads when unzoomed. Label size and frequency depends on the zoom level."],["DrawSimpleRoadLabels","Draws labels in map-space that roughly fit on the roads and change screen-space size while zooming."]]};
window.SIDEBAR_ITEMS = {"fn":[["cheaply_overestimate_bounds",""],["simplify_name",""],["simplify_patterns",""]],"struct":[["DrawRoadLabels","Labels roads when unzoomed. Label size and frequency depends on the zoom level."],["DrawSimpleRoadLabels","Draws labels in map-space that roughly fit on the roads. Dont change behavior during zooming; labels are only meant to be legible when zoomed in."]]};

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
window.SIDEBAR_ITEMS = {"constant":[["NEXT_RELEASE",""]],"enum":[["Executable",""]],"fn":[["app_header","A standard way to group a home button back to the title screen, the title of the current app, and a button to change maps. Callers must handle the `change map` and `home` click events."],["change_map_btn","A button to change maps, with default keybindings"],["checkbox_per_mode",""],["cmp_count","Less is better"],["cmp_dist","Shorter is better"],["cmp_duration","Shorter is better"],["color_for_mode",""],["draw_isochrone","Thresholds are Durations, in units of seconds"],["draw_overlapping_paths",""],["find_exe","Returns the path to an executable. Native-only."],["goal_marker","Draw a goal marker pointing at something."],["grey_out_map","Make it clear the map cant be interacted with right now."],["home_btn","A button to return to the title screen"],["intersections_from_roads",""],["loading_tips",""],["make_heatmap",""],["nice_country_name",""],["nice_map_name",""],["percentage_bar",""],["prompt_to_download_missing_data",""],["start_marker","Draw a start marker pointing at something."],["update_url_map_name","Modify the current URL to set the first free parameter to the current map name."],["version","Returns the version of A/B Street to link to. When building for a release, this points to that new release. Otherwise it points to the current dev version."]],"mod":[["camera",""],["city_picker",""],["colors",""],["command",""],["compare_counts",""],["draw_overlapping_paths",""],["heatmap",""],["icons",""],["importer",""],["labels",""],["minimap",""],["navigate",""],["polygon",""],["title_screen",""],["trip_files",""],["turn_explorer",""],["ui","Generic UI tools. Some of this should perhaps be lifted to widgetry."],["updater",""],["waypoints",""]],"struct":[["CameraState","Represents the state of a widgetry Canvas."],["CityPicker","Lets the player switch maps."],["ColorDiscrete",""],["ColorNetwork",""],["DefaultMap","Track the last map used, to resume next session."],["DrawRoadLabels","Labels roads when unzoomed. Label size and frequency depends on the zoom level."],["DrawSimpleRoadLabels","Draws labels in map-space that roughly fit on the roads and change screen-space size while zooming."],["EditPolygon",""],["FilePicker",""],["Grid","A 2D grid containing some arbitrary data."],["HeatmapOptions",""],["InputWaypoints","Click to add waypoints, drag them, see the list on a panel and delete them. The caller owns the Panel and the World, since theres probably more stuff there too."],["Minimap",""],["Navigator",""],["RunCommand","Executes a command and displays STDOUT and STDERR in a loading screen window. Only works on native, of course."],["TitleScreen","A title screen shared among all of the A/B Street apps."],["TripManagement","Save sequences of waypoints as named trips. Basic file management save, load, browse. This is useful to define “test cases,” then edit the bike network and “run the tests” to compare results."],["TurnExplorer","A tool to explore all of the turns from a single lane."],["WaypointID",""]],"trait":[["MinimapControls","Customize the appearance and behavior of a minimap."],["TripManagementState",""]]};
window.SIDEBAR_ITEMS = {"constant":[["NEXT_RELEASE",""]],"enum":[["Executable",""]],"fn":[["app_header","A standard way to group a home button back to the title screen, the title of the current app, and a button to change maps. Callers must handle the `change map` and `home` click events."],["change_map_btn","A button to change maps, with default keybindings"],["checkbox_per_mode",""],["cmp_count","Less is better"],["cmp_dist","Shorter is better"],["cmp_duration","Shorter is better"],["color_for_mode",""],["draw_isochrone","Thresholds are Durations, in units of seconds"],["draw_overlapping_paths",""],["find_exe","Returns the path to an executable. Native-only."],["goal_marker","Draw a goal marker pointing at something."],["grey_out_map","Make it clear the map cant be interacted with right now."],["home_btn","A button to return to the title screen"],["intersections_from_roads",""],["loading_tips",""],["make_heatmap",""],["nice_country_name",""],["nice_map_name",""],["percentage_bar",""],["prompt_to_download_missing_data",""],["start_marker","Draw a start marker pointing at something."],["update_url_map_name","Modify the current URL to set the first free parameter to the current map name."],["version","Returns the version of A/B Street to link to. When building for a release, this points to that new release. Otherwise it points to the current dev version."]],"mod":[["camera",""],["city_picker",""],["colors",""],["command",""],["compare_counts",""],["draw_overlapping_paths",""],["heatmap",""],["icons",""],["importer",""],["labels",""],["minimap",""],["navigate",""],["polygon",""],["title_screen",""],["trip_files",""],["turn_explorer",""],["ui","Generic UI tools. Some of this should perhaps be lifted to widgetry."],["updater",""],["waypoints",""]],"struct":[["CameraState","Represents the state of a widgetry Canvas."],["CityPicker","Lets the player switch maps."],["ColorDiscrete",""],["ColorNetwork",""],["DefaultMap","Track the last map used, to resume next session."],["DrawRoadLabels","Labels roads when unzoomed. Label size and frequency depends on the zoom level."],["DrawSimpleRoadLabels","Draws labels in map-space that roughly fit on the roads. Dont change behavior during zooming; labels are only meant to be legible when zoomed in."],["EditPolygon",""],["FilePicker",""],["Grid","A 2D grid containing some arbitrary data."],["HeatmapOptions",""],["InputWaypoints","Click to add waypoints, drag them, see the list on a panel and delete them. The caller owns the Panel and the World, since theres probably more stuff there too."],["Minimap",""],["Navigator",""],["RunCommand","Executes a command and displays STDOUT and STDERR in a loading screen window. Only works on native, of course."],["TitleScreen","A title screen shared among all of the A/B Street apps."],["TripManagement","Save sequences of waypoints as named trips. Basic file management save, load, browse. This is useful to define “test cases,” then edit the bike network and “run the tests” to compare results."],["TurnExplorer","A tool to explore all of the turns from a single lane."],["WaypointID",""]],"trait":[["MinimapControls","Customize the appearance and behavior of a minimap."],["TripManagementState",""]]};

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,6 @@
</a><div class="sidebar-elems"><h2 class="location"><a href="index.html">In map_gui::tools::title_screen::built_info</a></h2></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../../../../map_gui/index.html"><img class="rust-logo" src="../../../../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><button type="button" id="help-button" title="help">?</button><div id="settings-menu" tabindex="-1">
<a href="../../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../../wheel.svg"></a></div>
</div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
<h1 class="fqn"><span class="in-band">Constant <a href="../../../index.html">map_gui</a>::<wbr><a href="../../index.html">tools</a>::<wbr><a href="../index.html">title_screen</a>::<wbr><a href="index.html">built_info</a>::<wbr><a class="constant" href="#">BUILT_TIME_UTC</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../../../src/map_gui/home/runner/work/abstreet/abstreet/target/debug/build/map_gui-e828072489b7169e/out/built.rs.html#78">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><pre class="rust const"><code>pub const BUILT_TIME_UTC: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> = r&quot;Thu, 01 Sep 2022 10:59:58 +0000&quot;;</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The build time in RFC2822, UTC.</p>
<h1 class="fqn"><span class="in-band">Constant <a href="../../../index.html">map_gui</a>::<wbr><a href="../../index.html">tools</a>::<wbr><a href="../index.html">title_screen</a>::<wbr><a href="index.html">built_info</a>::<wbr><a class="constant" href="#">BUILT_TIME_UTC</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../../../../src/map_gui/home/runner/work/abstreet/abstreet/target/debug/build/map_gui-e828072489b7169e/out/built.rs.html#78">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="docblock item-decl"><pre class="rust const"><code>pub const BUILT_TIME_UTC: &amp;<a class="primitive" href="https://doc.rust-lang.org/1.63.0/std/primitive.str.html">str</a> = r&quot;Thu, 01 Sep 2022 14:03:53 +0000&quot;;</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The build time in RFC2822, UTC.</p>
</div></details></section></div></main><div id="rustdoc-vars" data-root-path="../../../../" data-current-crate="map_gui" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.63.0 (4b91a6ea7 2022-08-08)" ></div>
</body></html>

File diff suppressed because one or more lines are too long

View File

@ -180,7 +180,7 @@
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">RUSTDOC_VERSION</span>: <span class="kw-2">&amp;</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r&quot;rustdoc 1.63.0 (4b91a6ea7 2022-08-08)&quot;</span>;
<span class="attribute">#[<span class="ident">doc</span><span class="op">=</span><span class="string">r#&quot;The build time in RFC2822, UTC.&quot;#</span>]</span>
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">dead_code</span>)]</span>
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">BUILT_TIME_UTC</span>: <span class="kw-2">&amp;</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r&quot;Thu, 01 Sep 2022 10:59:58 +0000&quot;</span>;
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">BUILT_TIME_UTC</span>: <span class="kw-2">&amp;</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r&quot;Thu, 01 Sep 2022 14:03:53 +0000&quot;</span>;
<span class="attribute">#[<span class="ident">doc</span><span class="op">=</span><span class="string">r#&quot;The target architecture, given by `CARGO_CFG_TARGET_ARCH`.&quot;#</span>]</span>
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">dead_code</span>)]</span>
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">CFG_TARGET_ARCH</span>: <span class="kw-2">&amp;</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r&quot;x86_64&quot;</span>;

View File

@ -325,6 +325,35 @@
<span id="319">319</span>
<span id="320">320</span>
<span id="321">321</span>
<span id="322">322</span>
<span id="323">323</span>
<span id="324">324</span>
<span id="325">325</span>
<span id="326">326</span>
<span id="327">327</span>
<span id="328">328</span>
<span id="329">329</span>
<span id="330">330</span>
<span id="331">331</span>
<span id="332">332</span>
<span id="333">333</span>
<span id="334">334</span>
<span id="335">335</span>
<span id="336">336</span>
<span id="337">337</span>
<span id="338">338</span>
<span id="339">339</span>
<span id="340">340</span>
<span id="341">341</span>
<span id="342">342</span>
<span id="343">343</span>
<span id="344">344</span>
<span id="345">345</span>
<span id="346">346</span>
<span id="347">347</span>
<span id="348">348</span>
<span id="349">349</span>
<span id="350">350</span>
</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">std::cell::RefCell</span>;
<span class="kw">use</span> <span class="ident">aabb_quadtree::QuadTree</span>;
@ -533,8 +562,8 @@
.<span class="ident">get_bounds</span>()
}
<span class="doccomment">/// Draws labels in map-space that roughly fit on the roads and change screen-space size while</span>
<span class="doccomment">/// zooming.</span>
<span class="doccomment">/// Draws labels in map-space that roughly fit on the roads. Don&#39;t change behavior during zooming;</span>
<span class="doccomment">/// labels are only meant to be legible when zoomed in.</span>
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">DrawSimpleRoadLabels</span> {
<span class="ident">draw</span>: <span class="ident">Drawable</span>,
<span class="ident">include_roads</span>: <span class="ident">Box</span><span class="op">&lt;</span><span class="kw">dyn</span> <span class="ident">Fn</span>(<span class="kw-2">&amp;</span><span class="ident">Road</span>) -&gt; <span class="ident">bool</span><span class="op">&gt;</span>,
@ -590,12 +619,11 @@
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">batch</span> <span class="op">=</span> <span class="ident">GeomBatch::new</span>();
<span class="kw">let</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">app</span>.<span class="ident">map</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">hitboxes</span> <span class="op">=</span> <span class="ident">Vec::new</span>();
<span class="ident">timer</span>.<span class="ident">start_iter</span>(<span class="string">&quot;render roads&quot;</span>, <span class="ident">map</span>.<span class="ident">all_roads</span>().<span class="ident">len</span>());
<span class="lifetime">&#39;ROAD</span>: <span class="kw">for</span> <span class="ident">r</span> <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">all_roads</span>() {
<span class="kw">for</span> <span class="ident">r</span> <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">all_roads</span>() {
<span class="ident">timer</span>.<span class="ident">next</span>();
<span class="kw">if</span> <span class="op">!</span>(<span class="self">self</span>.<span class="ident">include_roads</span>)(<span class="ident">r</span>) <span class="op">|</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">length</span>() <span class="op">&lt;</span> <span class="ident">Distance::meters</span>(<span class="number">30.0</span>) {
<span class="comment">// Skip very short roads and tunnels</span>
<span class="kw">if</span> <span class="op">!</span>(<span class="self">self</span>.<span class="ident">include_roads</span>)(<span class="ident">r</span>) <span class="op">|</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">length</span>() <span class="op">&lt;</span> <span class="ident">Distance::meters</span>(<span class="number">30.0</span>) <span class="op">|</span><span class="op">|</span> <span class="ident">r</span>.<span class="ident">zorder</span> <span class="op">&lt;</span> <span class="number">0</span> {
<span class="kw">continue</span>;
}
@ -604,42 +632,72 @@
} <span class="kw">else</span> {
<span class="kw">continue</span>;
};
<span class="kw">let</span> (<span class="ident">pt</span>, <span class="ident">angle</span>) <span class="op">=</span> <span class="ident">r</span>.<span class="ident">center_pts</span>.<span class="ident">must_dist_along</span>(<span class="ident">r</span>.<span class="ident">length</span>() <span class="op">/</span> <span class="number">2.0</span>);
<span class="comment">// TODO Ideally we make the text height always be a bit less than the road width. I&#39;m</span>
<span class="comment">// having lots of trouble relating the two, so do something manually tuned for the</span>
<span class="comment">// moment.</span>
<span class="kw">let</span> <span class="ident">width</span> <span class="op">=</span> <span class="ident">r</span>.<span class="ident">get_width</span>();
<span class="kw">let</span> <span class="ident">scale</span> <span class="op">=</span> <span class="kw">if</span> <span class="ident">width</span> <span class="op">&lt;</span> <span class="ident">Distance::meters</span>(<span class="number">8.0</span>) {
<span class="number">0.3</span>
} <span class="kw">else</span> <span class="kw">if</span> <span class="ident">width</span> <span class="op">&lt;</span> <span class="ident">Distance::meters</span>(<span class="number">6.0</span>) {
<span class="number">0.2</span>
} <span class="kw">else</span> {
<span class="number">0.5</span>
};
<span class="kw">let</span> <span class="ident">txt</span> <span class="op">=</span> <span class="ident">Text::from</span>(<span class="ident">Line</span>(<span class="kw-2">&amp;</span><span class="ident">name</span>).<span class="ident">fg</span>(<span class="self">self</span>.<span class="ident">fg_color</span>));
<span class="kw">let</span> <span class="ident">txt_batch</span> <span class="op">=</span> <span class="ident">txt</span>.<span class="ident">render_autocropped</span>(<span class="ident">ctx</span>).<span class="ident">scale</span>(<span class="ident">scale</span>);
<span class="kw">let</span> <span class="ident">txt_batch</span> <span class="op">=</span> <span class="ident">Text::from</span>(<span class="ident">Line</span>(<span class="kw-2">&amp;</span><span class="ident">name</span>)).<span class="ident">render_autocropped</span>(<span class="ident">ctx</span>);
<span class="kw">if</span> <span class="ident">txt_batch</span>.<span class="ident">is_empty</span>() {
<span class="comment">// This happens when we don&#39;t have a font loaded with the right characters</span>
<span class="kw">continue</span>;
}
<span class="kw">let</span> <span class="ident">rect</span> <span class="op">=</span> <span class="ident">txt_batch</span>
.<span class="ident">get_bounds</span>()
.<span class="ident">get_rectangle</span>()
.<span class="ident">centered_on</span>(<span class="ident">pt</span>)
.<span class="ident">rotate_around</span>(<span class="ident">angle</span>.<span class="ident">reorient</span>(), <span class="ident">pt</span>);
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">hitboxes</span> {
<span class="kw">if</span> <span class="ident">rect</span>.<span class="ident">intersects</span>(<span class="ident">x</span>) {
<span class="kw">continue</span> <span class="lifetime">&#39;ROAD</span>;
}
<span class="kw">let</span> <span class="ident">txt_bounds</span> <span class="op">=</span> <span class="ident">txt_batch</span>.<span class="ident">get_bounds</span>();
<span class="comment">// The approach, part 1:</span>
<span class="comment">//</span>
<span class="comment">// We need to make the text fit in the road polygon. road_width gives us the height of</span>
<span class="comment">// the text, accounting for the outline around the road polygon and a buffer. If the</span>
<span class="comment">// road&#39;s length is short, the text could overflow into the intersections, so scale it</span>
<span class="comment">// down further.</span>
<span class="comment">//</span>
<span class="comment">// Since the text fits inside the road polygon, we don&#39;t need to do any kind of hitbox</span>
<span class="comment">// testing and make sure multiple labels don&#39;t overlap!</span>
<span class="comment">// The road has an outline of 1m, but also leave a slight buffer</span>
<span class="kw">let</span> <span class="ident">outline_thickness</span> <span class="op">=</span> <span class="ident">Distance::meters</span>(<span class="number">2.0</span>);
<span class="kw">let</span> <span class="ident">road_width</span> <span class="op">=</span> (<span class="ident">r</span>.<span class="ident">get_width</span>() <span class="op">-</span> <span class="number">2.0</span> <span class="op">*</span> <span class="ident">outline_thickness</span>).<span class="ident">inner_meters</span>();
<span class="comment">// Also a buffer from both ends of the road</span>
<span class="kw">let</span> <span class="ident">road_length</span> <span class="op">=</span> (<span class="number">0.9</span> <span class="op">*</span> <span class="ident">r</span>.<span class="ident">length</span>()).<span class="ident">inner_meters</span>();
<span class="comment">// Fit the text height in the road width perfectly</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">scale</span> <span class="op">=</span> <span class="ident">road_width</span> <span class="op">/</span> <span class="ident">txt_bounds</span>.<span class="ident">height</span>();
<span class="comment">// If the road is short and we&#39;ll overflow, then scale down even more.</span>
<span class="kw">if</span> <span class="ident">txt_bounds</span>.<span class="ident">width</span>() <span class="op">*</span> <span class="ident">scale</span> <span class="op">&gt;</span> <span class="ident">road_length</span> {
<span class="ident">scale</span> <span class="op">=</span> <span class="ident">road_length</span> <span class="op">/</span> <span class="ident">txt_bounds</span>.<span class="ident">width</span>();
<span class="comment">// TODO In this case, the vertical centering in the road polygon is wrong</span>
}
<span class="comment">// The approach, part 2:</span>
<span class="comment">//</span>
<span class="comment">// But many roads are curved. We can use the SVG renderer to make text follow a curve.</span>
<span class="comment">// But use the scale / text size calculated assuming rectangles.</span>
<span class="comment">//</span>
<span class="comment">// Note we render the text twice here, and once again in render_curvey. This seems</span>
<span class="comment">// cheap enough so far. There&#39;s internal SVG caching in widgetry, but we could also</span>
<span class="comment">// consider caching a &quot;road name -&gt; txt_bounds&quot; mapping through the whole app.</span>
<span class="comment">// The orientation of the text and the direction we vertically center depends on the</span>
<span class="comment">// direction the road points</span>
<span class="kw">let</span> <span class="ident">quadrant</span> <span class="op">=</span> <span class="ident">r</span>.<span class="ident">center_pts</span>.<span class="ident">quadrant</span>();
<span class="kw">let</span> <span class="ident">shift_dir</span> <span class="op">=</span> <span class="kw">if</span> <span class="ident">quadrant</span> <span class="op">==</span> <span class="number">2</span> <span class="op">|</span><span class="op">|</span> <span class="ident">quadrant</span> <span class="op">==</span> <span class="number">3</span> {
<span class="op">-</span><span class="number">1.0</span>
} <span class="kw">else</span> {
<span class="number">1.0</span>
};
<span class="comment">// The polyline passed to render_curvey will be used as the bottom of the text</span>
<span class="comment">// (glossing over whether or not this is a &quot;baseline&quot; or something else). We want to</span>
<span class="comment">// vertically center. SVG 1.1 has alignment-baseline, but usvg doesn&#39;t support this. So</span>
<span class="comment">// shift the road polyline.</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">curve</span> <span class="op">=</span> <span class="ident">r</span>
.<span class="ident">center_pts</span>
.<span class="ident">shift_either_direction</span>(<span class="ident">Distance::meters</span>(<span class="ident">shift_dir</span> <span class="op">*</span> <span class="ident">road_width</span> <span class="op">/</span> <span class="number">2.0</span>))
.<span class="ident">unwrap</span>();
<span class="kw">if</span> <span class="ident">quadrant</span> <span class="op">==</span> <span class="number">2</span> <span class="op">|</span><span class="op">|</span> <span class="ident">quadrant</span> <span class="op">==</span> <span class="number">3</span> {
<span class="ident">curve</span> <span class="op">=</span> <span class="ident">curve</span>.<span class="ident">reversed</span>();
}
<span class="ident">hitboxes</span>.<span class="ident">push</span>(<span class="ident">rect</span>);
<span class="ident">batch</span>.<span class="ident">append</span>(
<span class="ident">txt_batch</span>
.<span class="ident">centered_on</span>(<span class="ident">pt</span>)
.<span class="ident">rotate_around_batch_center</span>(<span class="ident">angle</span>.<span class="ident">reorient</span>()),
<span class="ident">Line</span>(<span class="kw-2">&amp;</span><span class="ident">name</span>)
.<span class="ident">fg</span>(<span class="self">self</span>.<span class="ident">fg_color</span>)
.<span class="ident">render_curvey</span>(<span class="ident">ctx</span>, <span class="kw-2">&amp;</span><span class="ident">curve</span>, <span class="ident">scale</span>),
);
}

View File

@ -1225,7 +1225,7 @@
<span class="macro">write!</span>(
<span class="kw-2">&amp;mut</span> <span class="ident">svg</span>,
<span class="string">r##&quot;&lt;textPath href=&quot;#txtpath&quot;&gt;{}&lt;/textPath&gt;&lt;/text&gt;&lt;/svg&gt;&quot;##</span>,
<span class="self">self</span>.<span class="ident">text</span>
<span class="ident">htmlescape::encode_minimal</span>(<span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">text</span>)
)
.<span class="ident">unwrap</span>();