/// <summary>
 /// Calculates a rectangle around a screen location that depicts the touchable area which will count a path point as
 /// hit if the user taps it
 /// </summary>
 /// <returns>The validation rect.</returns>
 /// <param name="screenPoint">Screen point.</param>
 /// <param name="validationRectSize">Validation rect size.</param>
 internal static KSPictureLoginValidationRect GetValidationRect(this PointF screenPoint, SizeF validationRectSize)
 {
     float halfWidth = validationRectSize.Width / 2f;
     float halfHeight = validationRectSize.Height / 2f;
     var rect = new KSPictureLoginValidationRect(screenPoint.X - halfWidth, screenPoint.Y - halfHeight, validationRectSize.Width, validationRectSize.Height);
     return rect;
 }
 public bool IntersectsWith(KSPictureLoginValidationRect otherRect)
 {
     return this.rect.IntersectsWith(otherRect.rect);
 }
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved (touches, evt);

            // If there isn't an active path gesture, create one now.
            if(this.currentPathGesture == null)
            {
                this.currentPathGesture = this.Factory.CreateGesture<KSPictureLoginPathGesture> ();
                this.currentPathGesture.Path.Add (this.touchStartLocation.NormalizePoint(this.PictureLoginView.DrawingAreaView.Bounds.Size));
            }

            UITouch touch = touches.AnyObject as UITouch;

            var viewLocation = touch.LocationInView (this.PictureLoginView.DrawingAreaView);
            // Don't allow drawing outside of the image.
            viewLocation = viewLocation.LimitValues (this.PictureLoginView.DrawingAreaView.Bounds);

            this.PictureLoginView.DrawingAreaView.SetGestureVisualizationLayerPosition (viewLocation);
            this.PictureLoginView.DrawingAreaView.EnableGestureVisualizationLayer = true;

            // We only store the point if it does not collide with the previous validation rectangle.
            // This reduces the amount of points being stored.
            var currentRasterizationRect = viewLocation.GetValidationRect (KSPictureLoginController.GridRectSize);
            if (previousRasterizationRect == null || !currentRasterizationRect.IntersectsWith (this.previousRasterizationRect))
            {
                // The current rect is different from the previous validation rect. Store the center of the rect as a new location.
                var normalizedPoint = currentRasterizationRect.Center.NormalizePoint (this.PictureLoginView.DrawingAreaView.Bounds.Size);
                this.currentPathGesture.Path.Add (normalizedPoint);
                this.PictureLoginView.DrawingAreaView.ContinuePathGesture (currentRasterizationRect.Center);

                // Remember the current validation rect for the next iteration.
                this.previousRasterizationRect = currentRasterizationRect;

                // Update the view.
                this.PictureLoginView.DrawingAreaView.SetNeedsDisplay();
            }
        }