| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | |
|
| | 4 | | namespace ReFlex.Core.Common.Components |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Data class containing a List of <see cref="Interaction"/> associated with a specific <see cref="TouchId"/> |
| | 8 | | /// </summary> |
| | 9 | | public class InteractionHistory |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// The TouchId associated with the Interactions of past <see cref="InteractionFrame"/>s |
| | 13 | | /// </summary> |
| 13 | 14 | | public int TouchId { get; } |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// A List of past Interactions associated with the provided <see cref="TouchId"/> |
| | 18 | | /// Contains one Element for each frame in which a touch with the associated <see cref="TouchId"/> was registere |
| | 19 | | /// </summary> |
| 42 | 20 | | public List<InteractionHistoryElement> Items { get; } |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Initializes the data class. |
| | 24 | | /// </summary> |
| | 25 | | /// <param name="touchId">The TouchId associated with the Interactions of past <see cref="InteractionFrame"/>s < |
| | 26 | | /// <param name="items">List of past Interactions associated with the provided touchId</param> |
| 7 | 27 | | public InteractionHistory(int touchId, List<InteractionHistoryElement> items) |
| 7 | 28 | | { |
| 7 | 29 | | Items = items; |
| 7 | 30 | | TouchId = touchId; |
| 7 | 31 | | } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Converts Interaction Data mapped by <see cref="InteractionFrame"/>(and associated <see cref="InteractionFram |
| | 35 | | /// </summary> |
| | 36 | | /// <param name="frames">List of <see cref="InteractionFrame"/> with (calibrated) interaction data</param> |
| | 37 | | /// <returns>History for each identified touch id.</returns> |
| | 38 | | public static IOrderedEnumerable<InteractionHistory> RetrieveHistoryFromInteractionFrames( |
| | 39 | | IEnumerable<InteractionFrame> frames) |
| 1 | 40 | | { |
| 1 | 41 | | var interactionFrames = frames.ToList(); |
| 1 | 42 | | var ids = interactionFrames |
| 20 | 43 | | .SelectMany(frame => frame.Interactions.Select(interaction => interaction.TouchId)).Distinct().ToList(); |
| | 44 | |
|
| 1 | 45 | | var result = new List<InteractionHistory>(); |
| | 46 | |
|
| 1 | 47 | | ids.ForEach(id => |
| 6 | 48 | | { |
| 42 | 49 | | var elements = interactionFrames.OrderByDescending(frame => frame.FrameId) |
| 36 | 50 | | .Select(frame => new InteractionHistoryElement(frame.FrameId, |
| 105 | 51 | | frame.Interactions.FirstOrDefault(interaction => Equals(interaction.TouchId, id)))) |
| 42 | 52 | | .Where(elem => elem.Interaction != null).ToList(); |
| 6 | 53 | | if (elements.Count > 0) |
| 6 | 54 | | { |
| 6 | 55 | | result.Add(new InteractionHistory(id, elements)); |
| 6 | 56 | | } |
| 7 | 57 | | }); |
| | 58 | |
|
| 7 | 59 | | return result.OrderBy(history => history.TouchId); |
| 1 | 60 | | } |
| | 61 | | } |
| | 62 | | } |