public List <Vector2> ScaleKeepRatio(float size) { Rect boundingBox = Gesture.GetBoundingBox(this.Points); List <Vector2> scaledPoints = new List <Vector2>(); float scaleValue; if (boundingBox.width > boundingBox.height) { //wide rectangle will be scaled following the width scaleValue = size / boundingBox.width; } else { scaleValue = size / boundingBox.height; } for (int i = 0; i < this.Points.Count; i++) { float x = this.Points[i].x * scaleValue; float y = this.Points[i].y * scaleValue; scaledPoints.Add(new Vector2(x, y)); } return(scaledPoints); }
/// <summary> /// Scale the gesture so that it can fit into predefined bounding box /// (which is a square originated on ORIGIN with the size of SQUARE_SIZE). /// </summary> /// <param name="size">Size of the bounding box to scale to</param> /// <returns>List of points which now fits in the predefined bounding box.</returns> public List <Vector2> ScaleTo(float size) { Rect boundingBox = Gesture.GetBoundingBox(this.Points); List <Vector2> scaledPoints = new List <Vector2>(); for (int i = 0; i < this.Points.Count; i++) { float x = this.Points[i].x * (size / boundingBox.width); float y = this.Points[i].y * (size / boundingBox.height); scaledPoints.Add(new Vector2(x, y)); } return(scaledPoints); }
/// <summary> /// Scale the gesture so that it can fit into predefined bounding box /// (which is a square originated on ORIGIN with the size of SQUARE_SIZE). /// </summary> /// <param name="size">Size of the bounding box to scale to</param> /// <returns>List of points which now fits in the predefined bounding box.</returns> public List <Vector2> ScaleTo(float size) { Rect boundingBox = Gesture.GetBoundingBox(this.Points); List <Vector2> scaledPoints = new List <Vector2>(); for (int i = 0; i < this.Points.Count; i++) { float x = this.Points[i].x * (size / boundingBox.width); float boundingBoxHeight = boundingBox.height; if (boundingBoxHeight < 0.00001f) { Debug.LogWarning("bounding box height is too small, clamped to 0.00001"); boundingBoxHeight = 0.00001f; } float y = this.Points[i].y * (size / boundingBoxHeight); scaledPoints.Add(new Vector2(x, y)); } return(scaledPoints); }