private List <Models.Game.Path> StrokesSort(List <Models.Game.Path> strokes, CENTER_DRAWING_DIRECTION op) { switch (op) { case CENTER_DRAWING_DIRECTION.INSIDE_TO_OUTSIDE: { strokes.Sort((strokeOne, strokeTwo) => { return(SortPredicatCenterDirection(strokes, strokeOne, strokeTwo, CENTER_DRAWING_DIRECTION.INSIDE_TO_OUTSIDE)); }); return(strokes); } case CENTER_DRAWING_DIRECTION.OUTSIDE_TO_INSIDE: { strokes.Sort((strokeOne, strokeTwo) => { return(SortPredicatCenterDirection(strokes, strokeOne, strokeTwo, CENTER_DRAWING_DIRECTION.OUTSIDE_TO_INSIDE)); }); return(strokes); } default: return(null); } }
private int SortPredicatCenterDirection(List <Models.Game.Path> strokes, Models.Game.Path pathOne, Models.Game.Path pathTwo, CENTER_DRAWING_DIRECTION direction) { //find the center point of coordinates double totalX = 0, totalY = 0, countCoordinate = 0; foreach (var stroke in strokes) { foreach (var coodinate in stroke.Coordinates) { totalX += coodinate.X; totalY += coodinate.Y; countCoordinate++; } } double centerX = totalX / countCoordinate; double centerY = totalY / countCoordinate; var originineOne = pathOne.Coordinates[0]; var originineTwo = pathTwo.Coordinates[0]; double distanceStrokeOne = Math.Sqrt(Math.Pow(originineOne.X - centerX, 2) + Math.Pow(originineOne.Y - centerY, 2)); double distanceStrokeTwo = Math.Sqrt(Math.Pow(originineTwo.X - centerX, 2) + Math.Pow(originineTwo.Y - centerY, 2)); switch (direction) { case CENTER_DRAWING_DIRECTION.INSIDE_TO_OUTSIDE: return(distanceStrokeOne.CompareTo(distanceStrokeTwo)); case CENTER_DRAWING_DIRECTION.OUTSIDE_TO_INSIDE: return(distanceStrokeTwo.CompareTo(distanceStrokeOne)); default: return(0); } }