/// <summary> /// Linearly interpolates between two <see cref="WorldCoordinate"/>s. /// </summary> /// <param name="a">The interpolation start point.</param> /// <param name="b">The interpolation end point.</param> /// <param name="t">A 0-1 fraction, indicating which value between the two points to return.</param> /// <returns>A <see cref="WorldCoordinate"/> value between the start and end point.</returns> public static WorldCoordinate Lerp(WorldCoordinate a, WorldCoordinate b, float t) { WorldCoordinate diff = b - a; float secAdd = diff.Sector * t; float subAdd = diff.Subposition * t; float secRem = secAdd % 1; int sec = a.Sector + HMath.FloorToInt(secAdd); float sub = a.Subposition + subAdd + secRem; return(new WorldCoordinate(sec, sub, false)); }
/// <summary> /// Constructs a new WorldCoordinate at the given position. /// <para>If clampSubposition is false, subposition values not within 0-1 will be added to the /// new <see cref="WorldCoordinate"/>'s sector position.</para> /// For instance, setting the sector to 1 and subposition 1.5 would place the new <see cref="WorldCoordinate"/> /// at sector 2, subposition 0.5. /// </summary> /// <param name="sector">The new <see cref="WorldCoordinate"/>'s sector position.</param> /// <param name="subposition">The new <see cref="WorldCoordinate"/>'s subposition within its sector.</param> /// <param name="clampSubposition">Whether to clamp subposition between 0 and 1, or add excess /// position to the sector value.</param> public WorldCoordinate(int sector, float subposition, bool clampSubposition = true) { if (clampSubposition) { Sector = sector; Subposition = HMath.Clamp(subposition, 0, 1 - float.Epsilon); } else { int diff = HMath.FloorToInt(subposition); Sector = sector + diff; Subposition = subposition - diff; } }
/// <summary> /// Construct a new <see cref="WorldPoint"/> at the given sector and subposition. /// </summary> /// <param name="sector">The new <see cref="WorldPoint"/>'s sector coordinates.</param> /// <param name="subposition">The new <see cref="WorldPoint"/>'s subposition coordinates.</param> public WorldPoint(Vector2 sector, Vector2 subposition) { X = new WorldCoordinate(HMath.FloorToInt(sector.X), subposition.X); Y = new WorldCoordinate(HMath.FloorToInt(sector.Y), subposition.Y); }