/// <summary> /// Tests getting factor and speed. /// </summary> protected void TestFactorAndSpeed(Itinero.Profiles.Profile profile, short?direction, float?factor, float?speed, params string[] tags) { var attributesCollection = new AttributeCollection(); for (int idx = 0; idx < tags.Length; idx = idx + 2) { attributesCollection.AddOrReplace(tags[idx], tags[idx + 1]); } var factorAndSpeed = profile.FactorAndSpeed(attributesCollection); if (direction != null) { Assert.AreEqual(direction.Value, factorAndSpeed.Direction); } if (factor != null) { Assert.AreEqual(factor.Value, factorAndSpeed.Value); } if (speed != null) { if (speed == 0) { Assert.AreEqual(0, factorAndSpeed.SpeedFactor, 0.0001); } else { Assert.AreEqual(1.0f / (speed.Value / 3.6), factorAndSpeed.SpeedFactor, 0.0001); } } }
/// <summary> /// Gets a get factor function based on the given routerdb. /// </summary> public static Func <ushort, FactorAndSpeed> GetGetFactorAndSpeed(this Profile profile, RouterDb routerDb) { return((profileId) => { var edgeProfile = routerDb.EdgeProfiles.Get(profileId); return profile.FactorAndSpeed(edgeProfile); }); }
/// <summary> /// Gets the factor for the given profile on the link defined by the given attributes. /// </summary> public static Factor Factor(this Profile profile, IAttributeCollection attributes) { return(profile.FactorAndSpeed(attributes).ToFactor()); }
/// <summary> /// Returns true if the link defined by the given attributes can be stopped on. /// </summary> public static bool CanStopOn(this Profile profile, IAttributeCollection attributes) { return(profile.FactorAndSpeed(attributes).Direction < 3); }