// Another solution for DetermineMainGroup (taking 2 groups), but it is not used in this program. // It is not applied becuase it may cause a lot of overlap, and solving the overlap is expensive. // Compared with the benefits it brings (less loss of information), we decided to abandon this solution. #region another solution private List <AggregatedDot> DetermineMainGroupSolution2(List <Dot> dots) { List <AggregatedDot> result = new List <AggregatedDot>(); List <Dot> westDots = new List <Dot>(); List <Dot> northDots = new List <Dot>(); List <Dot> southDots = new List <Dot>(); List <Dot> eastDots = new List <Dot>(); List <Dot> nonEuDots = new List <Dot>(); Region mainGroupRegion = Region.Error; Region secondaryGroupRegion = Region.Error; int west = 0; int east = 0; int south = 0; int north = 0; int noneu = 0; foreach (Dot dot in dots) { if (dot.Region == Region.West) { west++; westDots.Add(dot); } else if (dot.Region == Region.East) { east++; eastDots.Add(dot); } else if (dot.Region == Region.North) { north++; northDots.Add(dot); } else if (dot.Region == Region.South) { south++; southDots.Add(dot); } else if (dot.Region == Region.NonEU) { noneu++; nonEuDots.Add(dot); } } var numbers = new List <double>(); numbers.Add(west); numbers.Add(east); numbers.Add(north); numbers.Add(south); numbers.Add(noneu); var maxNumber = numbers.Max(); List <Dot> mainGroupDots = new List <Dot>(); if (maxNumber == west) { mainGroupRegion = Region.West; mainGroupDots = westDots; } else if (maxNumber == east) { mainGroupRegion = Region.East; mainGroupDots = eastDots; } else if (maxNumber == north) { mainGroupRegion = Region.North; mainGroupDots = northDots; } else if (maxNumber == south) { mainGroupRegion = Region.South; mainGroupDots = southDots; } else if (maxNumber == noneu) { mainGroupRegion = Region.NonEU; mainGroupDots = nonEuDots; } numbers.Remove(maxNumber); maxNumber = numbers.Max(); List <Dot> secondaryGroupDots = new List <Dot>(); if (maxNumber == west) { secondaryGroupRegion = Region.West; secondaryGroupDots = westDots; } else if (maxNumber == east) { secondaryGroupRegion = Region.East; secondaryGroupDots = eastDots; } else if (maxNumber == north) { secondaryGroupRegion = Region.North; secondaryGroupDots = northDots; } else if (maxNumber == south) { secondaryGroupRegion = Region.South; secondaryGroupDots = southDots; } else if (maxNumber == noneu) { secondaryGroupRegion = Region.NonEU; secondaryGroupDots = nonEuDots; } Circle circle = MinimumCoverCircle.GetMinimumCoverCircle(dots); result.Add(new AggregatedDot(new Dot(mainGroupRegion, new PointF((float)circle.c.x, (float)circle.c.y)), Math.Max((int)(circle.r * _ratio * Math.Min(_width, _height)), Setting.MinimumAggregationDotRadius))); circle = MinimumCoverCircle.GetMinimumCoverCircle(dots); result.Add(new AggregatedDot(new Dot(secondaryGroupRegion, new PointF((float)circle.c.x, (float)circle.c.y)), Math.Max((int)(circle.r * _ratio * Math.Min(_width, _height)), Setting.MinimumAggregationDotRadius))); return(result); }
// this determines the main region of people inside a group. // in other words, this decides the color of this group. // The return list is design for alternative solutions. // For this solution, the return list always contains exactly 1 aggregated Dot. private List <AggregatedDot> DetermineMainGroupSolution1(List <Dot> dots) { List <AggregatedDot> result = new List <AggregatedDot>(); Region mainGroup = Region.Error; int west = 0; int east = 0; int south = 0; int north = 0; int noneu = 0; foreach (Dot dot in dots) { if (dot.Region == Region.West) { west++; } else if (dot.Region == Region.East) { east++; } else if (dot.Region == Region.North) { north++; } else if (dot.Region == Region.South) { south++; } else if (dot.Region == Region.NonEU) { noneu++; } } double westpercentage = Convert.ToDouble(west) / dots.Count / Math.Sqrt(Setting.WestPecrentage); double eastpercentage = Convert.ToDouble(east) / dots.Count / Math.Sqrt(Setting.EastPercentage); double southpercentage = Convert.ToDouble(south) / dots.Count / Math.Sqrt(Setting.SouthPercentage); double northpercentage = Convert.ToDouble(north) / dots.Count / Math.Sqrt(Setting.NorthPercentage); double noneupercentage = Convert.ToDouble(noneu) / dots.Count / Math.Sqrt(Setting.NonEuPercentage); var numbers = new List <double>(); numbers.Add(westpercentage); numbers.Add(eastpercentage); numbers.Add(southpercentage); numbers.Add(northpercentage); numbers.Add(noneupercentage); var maxNumber = numbers.Max(); if (maxNumber == westpercentage) { mainGroup = Region.West; } else if (maxNumber == eastpercentage) { mainGroup = Region.East; } else if (maxNumber == southpercentage) { mainGroup = Region.South; } else if (maxNumber == northpercentage) { mainGroup = Region.North; } else if (maxNumber == noneupercentage) { mainGroup = Region.NonEU; } Circle circle = MinimumCoverCircle.GetMinimumCoverCircle(dots); result.Add(new AggregatedDot(new Dot(mainGroup, new PointF((float)circle.c.x, (float)circle.c.y)), Math.Max((int)(circle.r * _ratio * Math.Min(_width, _height)), Setting.MinimumAggregationDotRadius))); return(result); }