test_class.file: brouter-core/src/test/java/btools/router/OsmNodeNamedTest.java
test_class.identifier: OsmNodeNamedTest
test_case.body: @Test
    public void testDistanceWithinRadius() {
      // Segment ends
      int lon1, lat1, lon2, lat2;
      // Circle definition
      OsmNodeNamed node = new OsmNodeNamed();
      // Center
      node.ilon = toOsmLon(2.334243);
      node.ilat = toOsmLat(48.824017);
      // Radius
      node.radius = 30;
  
      // Check distance within radius is correctly computed if the segment passes through the center
      lon1 = toOsmLon(2.332559);
      lat1 = toOsmLat(48.823822);
      lon2 = toOsmLon(2.335018);
      lat2 = toOsmLat(48.824105);
      double totalSegmentLength = CheapRuler.distance(lon1, lat1, lon2, lat2);
      assertEquals(
        "Works for segment aligned with the nogo center",
        2 * node.radius,
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.01 * (2 * node.radius)
      );
  
      // Check distance within radius is correctly computed for a given circle
      node.ilon = toOsmLon(2.33438);
      node.ilat = toOsmLat(48.824275);
      assertEquals(
        "Works for a segment with no particular properties",
        27.5,
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.1 * 27.5
      );
  
      // Check distance within radius is the same if we reverse start and end point
      assertEquals(
        "Works if we switch firs and last point",
        node.distanceWithinRadius(lon2, lat2, lon1, lat1, totalSegmentLength),
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.01
      );
  
      // Check distance within radius is correctly computed if a point is inside the circle
      lon2 = toOsmLon(2.334495);
      lat2 = toOsmLat(48.824045);
      totalSegmentLength = CheapRuler.distance(lon1, lat1, lon2, lat2);
      assertEquals(
        "Works if last point is within the circle",
        17,
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.1 * 17
      );
  
      lon1 = toOsmLon(2.334495);
      lat1 = toOsmLat(48.824045);
      lon2 = toOsmLon(2.335018);
      lat2 = toOsmLat(48.824105);
      totalSegmentLength = CheapRuler.distance(lon1, lat1, lon2, lat2);
      assertEquals(
        "Works if first point is within the circle",
        9,
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.1 * 9
      );
  
      lon1 = toOsmLon(2.33427);
      lat1 = toOsmLat(48.82402);
      lon2 = toOsmLon(2.334587);
      lat2 = toOsmLat(48.824061);
      totalSegmentLength = CheapRuler.distance(lon1, lat1, lon2, lat2);
      assertEquals(
        "Works if both points are within the circle",
        25,
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.1 * 25
      );
  
      // Check distance within radius is correctly computed if both points are on
      // the same side of the center.
      // Note: the only such case possible is with one point outside and one
      // point within the circle, as we expect the segment to have a non-empty
      // intersection with the circle.
      lon1 = toOsmLon(2.332559);
      lat1 = toOsmLat(48.823822);
      lon2 = toOsmLon(2.33431);
      lat2 = toOsmLat(48.824027);
      totalSegmentLength = CheapRuler.distance(lon1, lat1, lon2, lat2);
      assertEquals(
        "Works if both points are on the same side of the circle center",
        5,
        node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
        0.1 * 5
      );
    }
test_case.class_method_signature: OsmNodeNamedTest.testDistanceWithinRadius()
test_case.full_signature: @Test public void testDistanceWithinRadius()
test_case.identifier: testDistanceWithinRadius
test_case.invocations: toOsmLon toOsmLat toOsmLon toOsmLat toOsmLon toOsmLat distance assertEquals distanceWithinRadius toOsmLon toOsmLat assertEquals distanceWithinRadius assertEquals distanceWithinRadius distanceWithinRadius toOsmLon toOsmLat distance assertEquals distanceWithinRadius toOsmLon toOsmLat toOsmLon toOsmLat distance assertEquals distanceWithinRadius toOsmLon toOsmLat toOsmLon toOsmLat distance assertEquals distanceWithinRadius toOsmLon toOsmLat toOsmLon toOsmLat distance assertEquals distanceWithinRadius
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDistanceWithinRadius()
focal_class.declarator: name
focal_class.modifier: public
focal_class.original_string: public String name;
focal_class.type: String
focal_class.var_name: name
focal_class.declarator: radius
focal_class.modifier: public
focal_class.original_string: public double radius;
focal_class.type: double
focal_class.var_name: radius
focal_class.declarator: nogoWeight
focal_class.modifier: public
focal_class.original_string: public double nogoWeight;
focal_class.type: double
focal_class.var_name: nogoWeight
focal_class.declarator: isNogo = false
focal_class.modifier: public
focal_class.original_string: public boolean isNogo = false;
focal_class.type: boolean
focal_class.var_name: isNogo
focal_class.file: brouter-core/src/main/java/btools/router/OsmNodeNamed.java
focal_class.identifier: OsmNodeNamed
focal_class.class_method_signature: OsmNodeNamed.OsmNodeNamed()
focal_class.full_signature: public  OsmNodeNamed()
focal_class.identifier: OsmNodeNamed
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  OsmNodeNamed()
focal_class.class_method_signature: OsmNodeNamed.OsmNodeNamed( OsmNode n)
focal_class.full_signature: public  OsmNodeNamed( OsmNode n)
focal_class.identifier: OsmNodeNamed
focal_class.modifiers: public
focal_class.parameters: ( OsmNode n)
focal_class.signature:  OsmNodeNamed( OsmNode n)
focal_class.class_method_signature: OsmNodeNamed.toString()
focal_class.full_signature: @Override public String toString()
focal_class.identifier: toString
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String toString()
focal_class.class_method_signature: OsmNodeNamed.distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_class.full_signature: public double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_class.identifier: distanceWithinRadius
focal_class.modifiers: public
focal_class.parameters: (int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_class.return: double
focal_class.signature: double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_class.class_method_signature: OsmNodeNamed.decodeNogo( String s )
focal_class.full_signature: public static OsmNodeNamed decodeNogo( String s )
focal_class.identifier: decodeNogo
focal_class.modifiers: public static
focal_class.parameters: ( String s )
focal_class.return: OsmNodeNamed
focal_class.signature: OsmNodeNamed decodeNogo( String s )
focal_class.superclass: extends OsmNode
focal_method.body: public double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength) {
      double[] lonlat2m = CheapRuler.getLonLatToMeterScales( (lat1 + lat2) >> 1 );
  
      boolean isFirstPointWithinCircle = CheapRuler.distance(lon1, lat1, ilon, ilat) < radius;
      boolean isLastPointWithinCircle = CheapRuler.distance(lon2, lat2, ilon, ilat) < radius;
      // First point is within the circle
      if (isFirstPointWithinCircle) {
        // Last point is within the circle
        if (isLastPointWithinCircle) {
          return totalSegmentLength;
        }
        // Last point is not within the circle
        // Just swap points and go on with first first point not within the
        // circle now.
        // Swap longitudes
        int tmp = lon2;
        lon2 = lon1;
        lon1 = tmp;
        // Swap latitudes
        tmp = lat2;
        lat2 = lat1;
        lat1 = tmp;
        // Fix boolean values
        isLastPointWithinCircle = isFirstPointWithinCircle;
        isFirstPointWithinCircle = false;
      }
      // Distance between the initial point and projection of center of
      // the circle on the current segment.
      double initialToProject = (
        (lon2 - lon1) * (ilon - lon1) * lonlat2m[0] * lonlat2m[0]
        + (lat2 - lat1) * (ilat - lat1) * lonlat2m[1] * lonlat2m[1]
      ) / totalSegmentLength;
      // Distance between the initial point and the center of the circle.
      double initialToCenter = CheapRuler.distance(ilon, ilat, lon1, lat1);
      // Half length of the segment within the circle
      double halfDistanceWithin = Math.sqrt(
        radius*radius - (
          initialToCenter*initialToCenter -
          initialToProject*initialToProject
        )
      );
      // Last point is within the circle
      if (isLastPointWithinCircle) {
        return halfDistanceWithin + (totalSegmentLength - initialToProject);
      }
      return 2 * halfDistanceWithin;
    }
focal_method.class_method_signature: OsmNodeNamed.distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_method.full_signature: public double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_method.identifier: distanceWithinRadius
focal_method.invocations: getLonLatToMeterScales distance distance distance sqrt
focal_method.modifiers: public
focal_method.parameters: (int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)
focal_method.return: double
focal_method.signature: double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength)