OpenRailwayMap / OpenRailwayMap-CartoCSS

CartoCSS port of the OpenRailwayMap styles, originally written in MapCSS
GNU General Public License v3.0
15 stars 20 forks source link

electrification: fix impossible conditions #82

Closed DerDakon closed 2 years ago

DerDakon commented 2 years ago

Fixes #42

epimorphic commented 2 years ago

As touched upon in the PR in limbo, this approach defeats the selectors for the specific voltage-frequency combinations that are widespread enough to have received special colors, turning the 15 kV lines in German-speaking countries and Scandinavia yellow and 25 kV lines orange. This is due to CSS specificity. The selector [frequency!=null][frequency!=0][voltage>=15000][voltage<25000] for example is a heavier, more "specific" match than [frequency=*][voltage=15000] because the former consists of two more individual attribute selectors than the latter. So for 15 kV lines the engine will always apply the former rule, not the latter.

The simple solution is to modify the first changed line to [frequency>0][voltage>=15000], and the second line to [frequency>0][voltage>=25000]. The first line in particular might seem sketchy since it appears to have lost the upper bound on voltage. But in fact this takes advantage of another behavior of CSS, where if multiple matching selectors tie in weight, the declarations for a selector later in position will overrule earlier ones. For example, a 25 kV 50 Hz line would match [frequency>0][voltage>=15000], [frequency>0][voltage>=25000], and [frequency=50][voltage=25000], all with weight 2, and the engine would apply the color specified by the last selector. This avoids needing long selector lists like [frequency>0][frequency!=16.67][frequency!=16.7][voltage=15000], [frequency>0][voltage>15000][voltage<25000] to eliminate selector intersection.

DerDakon commented 2 years ago

I just wonder if CartoCSS (engines) actually behave like "normal" CSS, or if the syntax just looks similar.

Changing the selection to >0 sounds like a good idea regardless.

epimorphic commented 2 years ago

Don't know about always consistent, but it seems to in this case. Renders for the Chūbu region in Japan:

With [frequency!=null][frequency!=0][voltage>=15000][voltage<25000] and [frequency!=null][frequency!=0][voltage>=25000] Screenshot 2022-09-24 at 21-19-39 OpenRailwayMap Electrification — Kosmtik Note how the Shinkansen lines (25 kV, split between 50 Hz sections and 60 Hz sections) are in generic orange.

With [frequency>0][voltage>=15000] and [frequency>0][voltage>=25000] Screenshot 2022-09-24 at 21-18-32 OpenRailwayMap Electrification — Kosmtik The Shinkansen lines now have the correct red colors.

DerDakon commented 2 years ago

Obsoleted by #57, which already fixed them.