private static void Step() { //push input state Input.PushState(); //process all SDL.SDL_events SDL.SDL_Event e; while (SDL.SDL_PollEvent(out e) == 1) { switch (e.type) { //let Input handle input related events case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: case SDL.SDL_EventType.SDL_MOUSEWHEEL: case SDL.SDL_EventType.SDL_MOUSEMOTION: case SDL.SDL_EventType.SDL_KEYDOWN: case SDL.SDL_EventType.SDL_KEYUP: case SDL.SDL_EventType.SDL_TEXTINPUT: case SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED: case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: case SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN: case SDL.SDL_EventType.SDL_CONTROLLERBUTTONUP: case SDL.SDL_EventType.SDL_CONTROLLERAXISMOTION: Input.InputEvent(e); break; //let Window handle window related events case SDL.SDL_EventType.SDL_WINDOWEVENT: Window.WindowEvent(e); break; //global quit, not only the window's exit button case SDL.SDL_EventType.SDL_QUIT: Exit(); break; } } Input.UpdateMousePosition(); Input.ApplyButtonMaps(); foreach (GameObject obj in Resources.Objects) { if (!obj.Destroyed) obj.Step(); } //collision time! Profiler.Start("collision"); float minX = float.PositiveInfinity; float minY = float.PositiveInfinity; float maxX = float.NegativeInfinity; float maxY = float.NegativeInfinity; foreach(PhysicalObject obj in Resources.PhysicalObjects) { obj.UpdateCoverableArea(); if (obj.CoverableArea.Position.X < minX) minX = obj.CoverableArea.Position.X; if (obj.CoverableArea.Position2.X > maxX) maxX = obj.CoverableArea.Position2.X; if (obj.CoverableArea.Position.Y < minY) minY = obj.CoverableArea.Position.Y; if (obj.CoverableArea.Position2.Y > maxY) maxY = obj.CoverableArea.Position2.Y; //set before the actual collision check phase obj.SpeedLeft = 1f; obj.CollisionCandidates = null; } //create and fill quadtree for this step QuadTree = new QuadTree(new Rectangle(minX, minY, maxX - minX, maxY - minY)); //create list of objects to process and calculate all first collision speedfractions for those objects List<PhysicalObject> processingObjects = new List<PhysicalObject>(Resources.PhysicalObjects); foreach (PhysicalObject obj in Resources.PhysicalObjects) { if (obj.Speed == Point.Zero) continue; processingObjects.Add(obj); obj.CalculateClosestCollision(); } while (processingObjects.Count > 0) { //get closest collision, process it/the pair of objects PhysicalObject obj = processingObjects.MinBy(o => o.ClosestCollisionSpeedFraction + 1 - o.SpeedLeft); obj.PerformClosestCollision(); //remove/recalculate collisions if (obj.SpeedLeft == 0f) processingObjects.Remove(obj); else obj.CalculateClosestCollision(); //recalculate for all possibly influenced objects (if needed) if (obj.CollisionCandidates != null) { foreach (PhysicalObject influencedObj in obj.CollisionCandidates) influencedObj.CalculateClosestCollision(); } } Profiler.Stop(); Resources.ObjectAdditionAndRemoval(); Resources.CleanupFontTextures(); }
public ForceDataPoint MomentMin() { List<ForceDataPoint> Moments = new List<ForceDataPoint>() { new ForceDataPoint(0.0,M1), MMid, new ForceDataPoint(FindZeroPointLocation(),0.0), new ForceDataPoint(L,M2) }; var MinMoment = Moments.MinBy(m => m.Value); AddMaxMomentEntry(MinMoment.Value, false, true); return MinMoment; }
public SessionSummaryDto CalculateWorkoutSummary(SessionDto session, List<DetectedInterval> detectedIntervals, int unit) { var sessionSummaryDtoList = new List<SessionSummaryDto>(); for (var w = 0; w < detectedIntervals.Count; w++) { var sessionDataSubsetDto = new SessionDataSubsetDto() { MinimumSecond = (double)detectedIntervals[w].StartTime, MaximumSecond = (double)detectedIntervals[w].FinishTime, SessionId = session.Id, Unit = unit }; var sessionSummaryDto = GetSessionDataSubset(sessionDataSubsetDto); sessionSummaryDtoList.Add(sessionSummaryDto); } var totalCount = sessionSummaryDtoList.Count(); // calculate speed var averageSpeed = Math.Round(sessionSummaryDtoList.Sum(x => x.AverageSpeed) / totalCount, 2, MidpointRounding.AwayFromZero); var maximumSpeed = sessionSummaryDtoList.MaxBy(s => s.MaximumSpeed).MaximumSpeed; // calculate distance var totalDistance = Math.Round(sessionSummaryDtoList.Sum(x => x.TotalDistance), 2, MidpointRounding.AwayFromZero); // calculate altitiude var averageAltitude = Math.Round(sessionSummaryDtoList.Sum(x => x.AverageAltitude) / totalCount, 2, MidpointRounding.AwayFromZero); var maximumAltitude = sessionSummaryDtoList.MaxBy(s => s.MaximumAltitude).MaximumAltitude; // calculate heart rate var averageHeartRate = Math.Round(sessionSummaryDtoList.Sum(x => x.AverageHeartRate / totalCount), 2, MidpointRounding.AwayFromZero); var minimumHeartRate = sessionSummaryDtoList.MinBy(s => s.MinimumHeartRate).MinimumHeartRate; var maximumHeartRate = sessionSummaryDtoList.MinBy(s => s.MaximumHeartRate).MaximumHeartRate; // calculate power var averagePower = Math.Round(sessionSummaryDtoList.Sum(x => x.AveragePower) / totalCount, 2, MidpointRounding.AwayFromZero); var maximumPower = sessionSummaryDtoList.MaxBy(s => s.MaximumPower).MaximumPower; // calculate cadence var averageCadence = Math.Round(sessionSummaryDtoList.Sum(x => x.AverageCadence) / totalCount, 2, MidpointRounding.AwayFromZero); var maximumCadence = sessionSummaryDtoList.MaxBy(s => s.MaximumCadence).MaximumCadence; var workoutSummary = new SessionSummaryDto() { AverageAltitude = averageAltitude, MaximumAltitude = maximumAltitude, AverageHeartRate = averageHeartRate, MinimumHeartRate = minimumHeartRate, MaximumHeartRate = maximumHeartRate, AveragePower = averagePower, MaximumPower = maximumPower, AverageCadence = averageCadence, MaximumCadence = maximumCadence, AverageSpeed = averageSpeed, MaximumSpeed = maximumSpeed, TotalDistance = totalDistance, Date = session.Date, SessionId = session.Id }; return workoutSummary; }
public ForceDataPoint MomentMin() { if (MomentsWereCalculated == false) { CalculateMomentsAtPointOfApplication(); } List<ForceDataPoint> Moments = new List<ForceDataPoint>() { new ForceDataPoint(0.0,0.0), new ForceDataPoint(a, MmaxRight), new ForceDataPoint(a,MmaxLeft), }; var MinMoment = Moments.MinBy(m => m.Value); AddGoverningMomentEntry(MinMoment.Value, false, true); return MinMoment; }
//------------------------------------------------------------------ public Car FindClosestPolice(Car punisher) { List <Car> polices = new List <Car>(); // ToDo: Convert to LINQ manually // Find all Polices foreach (var lane in lanes) foreach (var car in lane.Cars) if (car is Police) polices.Add (car); // Find nearest Police var closestPolice = polices.MinBy (police => { var distance = police.Position - punisher.Position; return distance.Length(); }); return closestPolice; }
List<CPos> UpdateEdgeCells() { var edgeCells = new List<CPos>(); var unProjected = new List<MPos>(); var bottom = Bounds.Bottom - 1; for (var u = Bounds.Left; u < Bounds.Right; u++) { unProjected = Unproject(new PPos(u, Bounds.Top)); if (unProjected.Any()) edgeCells.Add(unProjected.MinBy(x => x.V).ToCPos(Grid.Type)); unProjected = Unproject(new PPos(u, bottom)); if (unProjected.Any()) edgeCells.Add(unProjected.MaxBy(x => x.V).ToCPos(Grid.Type)); } for (var v = Bounds.Top; v < Bounds.Bottom; v++) { unProjected = Unproject(new PPos(Bounds.Left, v)); if (unProjected.Any()) edgeCells.Add((v == bottom ? unProjected.MaxBy(x => x.V) : unProjected.MinBy(x => x.V)).ToCPos(Grid.Type)); unProjected = Unproject(new PPos(Bounds.Right - 1, v)); if (unProjected.Any()) edgeCells.Add((v == bottom ? unProjected.MaxBy(x => x.V) : unProjected.MinBy(x => x.V)).ToCPos(Grid.Type)); } return edgeCells; }
/// <summary> /// Finds humps in contour. Hump scale is determined by <paramref name="scale"/>. /// <para>For each peak a closest valley is found. Next for that valley a closet point is found. Those three point make hump.</para> /// <para>Hump searching will be successful even when only one peak and one valley are found; it can be successful where peak and valley search against convex hull does not give good results.</para> /// <para></para>Peaks and valleys can be obtained by using <see cref="FindExtremaIndices"/>. /// </summary> /// <param name="contour">Contour.</param> /// <param name="peaks">Peaks.</param> /// <param name="valeys">Valleys.</param> /// <param name="scale">Used for <see cref="GetClosestPoint"/>. A good value is ~20. A specified region will be searched every time to avoid local minimum.</param> /// <param name="humpPeaks">Found hump peaks.</param> /// <returns>Humps contour indexes.</returns> public static List<Range> GetHumps(this IList<Point> contour, List<int> peaks, List<int> valeys, int scale, out List<int> humpPeaks) { List<Range> humps = new List<Range>(); humpPeaks = new List<int>(); if (valeys.Count == 0) return humps; foreach (var peak in peaks) { var closestValey = valeys.MinBy(valey => System.Math.Abs(valey - peak)); var searchDirection = ((peak - closestValey) > 0) ? 1 : -1; int closestPtToValey = contour.GetClosestPoint(closestValey, peak, searchDirection, scale); if (closestPtToValey == closestValey) //skip "humps" with zero elements continue; Range hump; if (searchDirection < 0) hump = new Range(closestPtToValey, closestValey); else hump = new Range(closestValey, closestPtToValey); //check if a hump contain some other peaks and valey; classify it as a bad hump if (hump.IsInside(peaks).Count(x => x == true) > 1 ||/*discard the current peak*/ hump.IsInside(valeys).Count(x => x == true) > 1) { } else { humps.Add(hump); humpPeaks.Add(peak); } } return humps; }
public ForceDataPoint MomentMin() { if (ReactionsWereCalculated == false) CalulateReactions(); if (MomentsWereCalculated == false) CalculateMoments(); List<ForceDataPoint> Moments = new List<ForceDataPoint> { M1,M2,Mmid }; ForceDataPoint Mminimum = Moments.MinBy(m => m.Value); this.AddMomentEntry(Mminimum, false, true); return Mminimum; }
public ForceDataPoint MomentMin() { List<ForceDataPoint> Moments = new List<ForceDataPoint>() { new ForceDataPoint(0.0,M1), Mx, new ForceDataPoint(L,M2) }; var MinMoment = Moments.MinBy(m => m.Value); AddGoverningMomentEntry(MinMoment.Value, false, true); return MinMoment; }
public ForceDataPoint MomentMin() { if (MomentsWereCalculated == false) CalculateMoments(); List<ForceDataPoint> Moments = new List<ForceDataPoint>() { M1, MPointLeft, MPointRight, M2 }; ForceDataPoint MinMoment = Moments.MinBy(m => m.Value); AddMomentEntry(MinMoment, false, true); return MinMoment; }
public static GeoLocation GetNearestGeoLocation(List<GeoLocation> geoLocations, location location) { foreach (var district in geoLocations) { district.Distance = district.GeoCoordinate.GetDistanceTo(location?.point?.GetGeoCoordinate()); } var nearestGeoLocation = geoLocations.MinBy(o => o.Distance); return nearestGeoLocation; }