public static float GetIntersectDistance(Spell spell, Vector2 start, Vector2 end) { if (spell == null) { return(float.MaxValue); } switch (spell.SpellType) { case SpellType.Line: var hasIntersection = spell.LineIntersectLinearSpellEx(start, end, out var intersection); if (hasIntersection) { return(start.Distance(intersection)); } break; case SpellType.Circular: if (end.InSkillShot(spell, ObjectCache.MyHeroCache.BoundingRadius) == false) { MathUtils.FindLineCircleIntersections(spell.EndPos, spell.Radius, start, end, out var intersection1, out var intersection2); if (intersection1.X != float.NaN && MathUtils.isPointOnLineSegment(intersection1, start, end)) { return(start.Distance(intersection1)); } if (intersection2.X != float.NaN && MathUtils.isPointOnLineSegment(intersection2, start, end)) { return(start.Distance(intersection2)); } } break; } return(float.MaxValue); }