Skip to content

Commit

Permalink
Merge pull request #6333 from leonardehrenfried/bogus-name
Browse files Browse the repository at this point in the history
Rename 'bogusName' to 'nameIsDerived'
  • Loading branch information
leonardehrenfried authored Dec 17, 2024
2 parents 65e976a + 4c6db7f commit e9f5941
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ApiWalkStep mapWalkStep(WalkStep domain) {
api.exit = domain.getExit();
api.stayOn = domain.isStayOn();
api.area = domain.getArea();
api.bogusName = domain.getBogusName();
api.bogusName = domain.nameIsDerived();
if (domain.getStartLocation() != null) {
api.lon = domain.getStartLocation().longitude();
api.lat = domain.getStartLocation().latitude();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public DataFetcher<Boolean> area() {

@Override
public DataFetcher<Boolean> bogusName() {
return environment -> getSource(environment).getBogusName();
return environment -> getSource(environment).nameIsDerived();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static GraphQLObjectType create(GraphQLObjectType elevationStepType) {
"The name of this street was generated by the system, so we should only display it once, and generally just display right/left directions"
)
.type(Scalars.GraphQLBoolean)
.dataFetcher(environment -> ((WalkStep) environment.getSource()).getBogusName())
.dataFetcher(environment -> ((WalkStep) environment.getSource()).nameIsDerived())
.build()
)
.field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void recordEdges(OsmWithTags way, StreetEdgePair edgePair) {
edgePair
.asIterable()
.forEach(edge -> {
if (!edge.hasBogusName()) {
if (!edge.nameIsDerived()) {
return; // this edge already has a real name so there is nothing to do
}
if (isHighwayLink) {
Expand Down Expand Up @@ -149,7 +149,7 @@ private static String nameAccordingToDestination(StreetEdge e, int maxDepth) {
return null;
}
for (StreetEdge out : e.getToVertex().getOutgoingStreetEdges()) {
if (out.hasBogusName()) {
if (out.nameIsDerived()) {
String name = nameAccordingToDestination(out, maxDepth - 1);
if (name == null) {
continue;
Expand All @@ -170,7 +170,7 @@ private static String nameAccordingToOrigin(StreetEdge e, int maxDepth) {
return null;
}
for (StreetEdge in : e.getFromVertex().getIncomingStreetEdges()) {
if (in.hasBogusName()) {
if (in.nameIsDerived()) {
String name = nameAccordingToOrigin(in, maxDepth - 1);
if (name == null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Optional<EdgeVisualAttributes> renderEdge(Edge e) {

StringBuilder sb = new StringBuilder();

if (!pwe.hasBogusName()) {
if (!pwe.nameIsDerived()) {
sb.append("name=").append(pwe.getName()).append(", ");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static List<KeyValue> mapStreetEdge(StreetEdge se) {
kv("noThruTraffic", noThruTrafficAsString(se)),
kv("wheelchairAccessible", se.isWheelchairAccessible())
);
if (se.hasBogusName()) {
if (se.nameIsDerived()) {
props.addFirst(kv("name", "%s (generated)".formatted(se.getName().toString())));
} else {
props.addFirst(kv("name", se.getName().toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class WalkStep {
private final Set<StreetNote> streetNotes;

private final boolean area;
private final boolean bogusName;
private final boolean nameIsDerived;
private final double angle;
private final boolean walkingBike;

Expand All @@ -57,7 +57,7 @@ public final class WalkStep {
Set<StreetNote> streetNotes,
String exit,
ElevationProfile elevationProfile,
boolean bogusName,
boolean nameIsDerived,
boolean walkingBike,
boolean area,
boolean stayOn,
Expand All @@ -71,7 +71,7 @@ public final class WalkStep {
this.directionText = directionText;
this.streetNotes = Set.copyOf(Objects.requireNonNull(streetNotes));
this.startLocation = Objects.requireNonNull(startLocation);
this.bogusName = bogusName;
this.nameIsDerived = nameIsDerived;
this.angle = DoubleUtils.roundTo2Decimals(angle);
this.walkingBike = walkingBike;
this.area = area;
Expand Down Expand Up @@ -148,9 +148,10 @@ public boolean getArea() {
/**
* The name of this street was generated by the system, so we should only display it once, and
* generally just display right/left directions
* @see Edge#nameIsDerived()
*/
public boolean getBogusName() {
return bogusName;
public boolean nameIsDerived() {
return nameIsDerived;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WalkStepBuilder {
private final Set<StreetNote> streetNotes = new HashSet<>();
private I18NString directionText;
private WgsCoordinate startLocation;
private boolean bogusName = false;
private boolean nameIsDerived = false;
private double angle;
private boolean walkingBike = false;
private boolean area = false;
Expand All @@ -44,8 +44,8 @@ public WalkStepBuilder withStartLocation(WgsCoordinate startLocation) {
return this;
}

public WalkStepBuilder withBogusName(boolean bogusName) {
this.bogusName = bogusName;
public WalkStepBuilder withNameIsDerived(boolean nameIsDerived) {
this.nameIsDerived = nameIsDerived;
return this;
}

Expand Down Expand Up @@ -140,8 +140,11 @@ public I18NString directionText() {
return directionText;
}

public boolean bogusName() {
return bogusName;
/**
* @see Edge#nameIsDerived()
*/
public boolean nameIsDerived() {
return nameIsDerived;
}

public RelativeDirection relativeDirection() {
Expand All @@ -157,7 +160,7 @@ public WalkStep build() {
streetNotes,
exit,
elevationProfile,
bogusName,
nameIsDerived,
walkingBike,
area,
stayOn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private boolean continueOnSameStreet(Edge edge, String streetNameNoParens) {
return !(
current.directionText().toString() != null &&
!(java.util.Objects.equals(current.directionTextNoParens(), streetNameNoParens)) &&
(!current.bogusName() || !edge.hasBogusName())
(!current.nameIsDerived() || !edge.nameIsDerived())
);
}

Expand Down Expand Up @@ -525,7 +525,7 @@ private void createAndSaveStep(
addStep(
createWalkStep(forwardState, backState)
.withDirectionText(name)
.withBogusName(false)
.withNameIsDerived(false)
.withDirections(lastAngle, DirectionUtils.getFirstAngle(edge.getGeometry()), false)
.withRelativeDirection(direction)
.addDistance(edge.getDistanceMeters())
Expand All @@ -543,7 +543,7 @@ private WalkStepBuilder createWalkStep(State forwardState, State backState) {
.builder()
.withDirectionText(en.getName())
.withStartLocation(new WgsCoordinate(backState.getVertex().getCoordinate()))
.withBogusName(en.hasBogusName())
.withNameIsDerived(en.nameIsDerived())
.withAngle(DirectionUtils.getFirstAngle(forwardState.getBackEdge().getGeometry()))
.withWalkingBike(forwardState.isBackWalkingBike())
.withArea(forwardState.getBackEdge() instanceof AreaEdge)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public String getDefaultName() {
* Returns false if the field reflects the real world name, like "Fifth Avenue",
* "Hauptstraße" or "Øvre Holmegate".
*/
public boolean hasBogusName() {
public boolean nameIsDerived() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public I18NString getName() {
* @author mattwigway
*/
@Override
public boolean hasBogusName() {
public boolean nameIsDerived() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public I18NString getName() {
* never included in plans.
*/
@Override
public boolean hasBogusName() {
public boolean nameIsDerived() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public I18NString getName() {
}

@Override
public boolean hasBogusName() {
public boolean nameIsDerived() {
return signpostedAs == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public class StreetEdge
/** If you have more than 16 flags, increase flags to short or int */
static final int BACK_FLAG_INDEX = 0;
static final int ROUNDABOUT_FLAG_INDEX = 1;
static final int HASBOGUSNAME_FLAG_INDEX = 2;
/**
* @see Edge#nameIsDerived()
*/
static final int NAME_IS_DERIVED_FLAG_INDEX = 2;
static final int MOTOR_VEHICLE_NOTHRUTRAFFIC = 3;
static final int STAIRS_FLAG_INDEX = 4;
static final int SLOPEOVERRIDE_FLAG_INDEX = 5;
Expand Down Expand Up @@ -444,20 +447,22 @@ public I18NString getName() {
}

/**
* Update the name of the edge after it has been constructed. This method also sets the bogusName
* Update the name of the edge after it has been constructed. This method also sets the nameIsDerived
* property to false, indicating to the code that maps from edges to steps that this is a real
* street name.
* @see Edge#hasBogusName()
* @see Edge#nameIsDerived()
*/
public void setName(I18NString name) {
this.name = name;
this.flags = BitSetUtils.set(flags, HASBOGUSNAME_FLAG_INDEX, false);
this.flags = BitSetUtils.set(flags, NAME_IS_DERIVED_FLAG_INDEX, false);
}

public boolean hasBogusName() {
return BitSetUtils.get(flags, HASBOGUSNAME_FLAG_INDEX);
@Override
public boolean nameIsDerived() {
return BitSetUtils.get(flags, NAME_IS_DERIVED_FLAG_INDEX);
}

@Override
public LineString getGeometry() {
return CompactLineStringUtils.uncompactLineString(
fromv.getLon(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.opentripplanner.street.model.edge.StreetEdge.BACK_FLAG_INDEX;
import static org.opentripplanner.street.model.edge.StreetEdge.BICYCLE_NOTHRUTRAFFIC;
import static org.opentripplanner.street.model.edge.StreetEdge.CLASS_LINK;
import static org.opentripplanner.street.model.edge.StreetEdge.HASBOGUSNAME_FLAG_INDEX;
import static org.opentripplanner.street.model.edge.StreetEdge.MOTOR_VEHICLE_NOTHRUTRAFFIC;
import static org.opentripplanner.street.model.edge.StreetEdge.NAME_IS_DERIVED_FLAG_INDEX;
import static org.opentripplanner.street.model.edge.StreetEdge.ROUNDABOUT_FLAG_INDEX;
import static org.opentripplanner.street.model.edge.StreetEdge.SLOPEOVERRIDE_FLAG_INDEX;
import static org.opentripplanner.street.model.edge.StreetEdge.STAIRS_FLAG_INDEX;
Expand Down Expand Up @@ -175,7 +175,7 @@ public B withLink(boolean link) {
}

public B withBogusName(boolean hasBogusName) {
flags = BitSetUtils.set(flags, HASBOGUSNAME_FLAG_INDEX, hasBogusName);
flags = BitSetUtils.set(flags, NAME_IS_DERIVED_FLAG_INDEX, hasBogusName);
return instance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void postprocess() {
assertNotEquals(sidewalk.edge.getName(), pryorStreet.edge.getName());
builder.postProcess(new SidewalkNamer());
assertEquals(sidewalk.edge.getName(), pryorStreet.edge.getName());
assertFalse(sidewalk.edge.hasBogusName());
assertFalse(sidewalk.edge.nameIsDerived());
}

private static class ModelBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void testRelativeDirection() {
WalkStepBuilder builder = new WalkStepBuilder()
.withDirectionText(new NonLocalizedString("Any"))
.withStartLocation(new WgsCoordinate(3.0, 4.0))
.withBogusName(false)
.withNameIsDerived(false)
.withAngle(0.0)
.withWalkingBike(false)
.withArea(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StreetEdgeBuilderTest {
private static final float WALK_SAFETY_FACTOR = 0.5f;
private static final float BICYCLE_SAFETY_FACTOR = 0.4f;
private static final boolean SLOPE_OVERRIDE = false;
private static final boolean BOGUS_NAME = true;
private static final boolean NAME_IS_DERIVED = true;
private static final boolean BICYCLE_NO_THRU_TRAFFIC = true;
private static final boolean MOTOR_VEHICLE_NO_THRU_TRAFFIC = true;
private static final boolean WALK_NO_THRU_TRAFFIC = true;
Expand Down Expand Up @@ -82,7 +82,7 @@ private static StreetEdge buildStreetEdge() {
.withBack(BACK)
.withStairs(STAIRS)
.withSlopeOverride(SLOPE_OVERRIDE)
.withBogusName(BOGUS_NAME)
.withBogusName(NAME_IS_DERIVED)
.withWalkNoThruTraffic(WALK_NO_THRU_TRAFFIC)
.withBicycleNoThruTraffic(BICYCLE_NO_THRU_TRAFFIC)
.withMotorVehicleNoThruTraffic(MOTOR_VEHICLE_NO_THRU_TRAFFIC)
Expand All @@ -100,7 +100,7 @@ private static void assertAllProperties(StreetEdge streetEdge) {
assertEquals(WALK_SAFETY_FACTOR, streetEdge.getWalkSafetyFactor());
assertEquals(BICYCLE_SAFETY_FACTOR, streetEdge.getBicycleSafetyFactor());
assertEquals(SLOPE_OVERRIDE, streetEdge.isSlopeOverride());
assertEquals(BOGUS_NAME, streetEdge.hasBogusName());
assertEquals(NAME_IS_DERIVED, streetEdge.nameIsDerived());
assertEquals(WALK_NO_THRU_TRAFFIC, streetEdge.isWalkNoThruTraffic());
assertEquals(BICYCLE_NO_THRU_TRAFFIC, streetEdge.isBicycleNoThruTraffic());
assertEquals(MOTOR_VEHICLE_NO_THRU_TRAFFIC, streetEdge.isMotorVehicleNoThruTraffic());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ void setName() {
.buildAndConnect();

assertEquals(path, edge.getName());
assertTrue(edge.hasBogusName());
assertTrue(edge.nameIsDerived());

var mainStreet = I18NString.of("Main Street");
edge.setName(mainStreet);
assertEquals(mainStreet, edge.getName());
assertFalse(edge.hasBogusName());
assertFalse(edge.nameIsDerived());
}
}

0 comments on commit e9f5941

Please sign in to comment.