internal static Movement Create(TouchPoint previous, TouchPoint current) { Movement movement = new Movement(); if (previous == null) { movement.Direction = MovementDirection.New; movement.XMovement = 0; movement.YMovement = 0; movement.InactiveMillis = 0; } else { movement.XMovement = current.FocalPointX - previous.FocalPointX; // Y is flipped because positive needs to be UP movement.YMovement = previous.FocalPointY - current.FocalPointY; // Add last 1 if it didn't break threshold if (previous.Movement != null && previous.Movement.Magnitude < MOVEMENT_THRESHOLD) { movement.XMovement += previous.Movement.XMovement; movement.YMovement += previous.Movement.YMovement; movement.InactiveMillis = previous.Movement.InactiveMillis; } movement.Magnitude = previous.DistanceTo(current); if (movement.Magnitude >= MOVEMENT_THRESHOLD) { movement.Direction = movement.FindDirection(); } else { movement.Direction = MovementDirection.None; movement.InactiveMillis += TouchMouse.SAMPLING_RATE; } } return movement; }
internal void CreateMovement(TouchPoint previousPoint) { if (previousPoint != null) { previousPoint.HasBeenFollowed = true; } if (previousPoint != null && previousPoint.Movements != null) { Movements = previousPoint.Movements; } else { Movements = new List<Movement>(); } Movement = Movement.Create(previousPoint, this); if (Movement.Direction != MovementDirection.None && Movement.Direction != MovementDirection.New) { Movements.Add(Movement); } }
internal double DistanceTo(TouchPoint otherPoint) { return MathHelpers.PythagoreanDistance(FocalPointX - otherPoint.FocalPointX, FocalPointY - otherPoint.FocalPointY); }
internal static TouchPoint Create(int x, int y) { TouchPoint touchPoint = new TouchPoint() { Top = y, Bottom = y, Left = x, Right = x, FocalPointX = x, FocalPointY = y, }; return touchPoint; }