예제 #1
0
        void Generate_ClosestLabel(string key, List <Label_Fitter.LabelPoint> potentialLabelPoints, Dictionary <string, Label_Fitter.TargetPoint> targetPoints, Rectangle controllerImage)
        {
            float min_distance = float.MaxValue;
            float distance     = 0;
            Point absoluteLoc  = new Point(targetPoints[key].x + controllerImage.Location.X, targetPoints[key].y + controllerImage.Location.Y);

            Label_Fitter.LabelPoint shortestLabel = null;

            double x_distance = 0;
            double y_distance = 0;

            foreach (var lbl in potentialLabelPoints.Where((l) => l.key == null))
            {
                x_distance = Math.Pow((float)(absoluteLoc.X - lbl.x), 2);
                y_distance = Math.Pow((float)(absoluteLoc.Y - lbl.y), 2);

                distance = (float)Math.Sqrt((x_distance + y_distance));
                if (distance <= min_distance)
                {
                    min_distance  = distance;
                    shortestLabel = lbl;
                }
            }

            if (shortestLabel != null)
            {
                shortestLabel.key = key;
            }
        }
예제 #2
0
        List <Label_Fitter.LabelPoint> generateLabels(List <Label_Fitter.LabelPoint> potentialLabelPoints, Dictionary <string, Label_Fitter.TargetPoint> targetPoints, Rectangle controllerImage)
        {
            float[] thetas      = calculateThetas(targetPoints.Count, controllerImage);
            int     totalLabels = Math.Max((int)(targetPoints.Count * 1.1f), 6);

            angle         = (thetas[0]) / (totalLabels);
            current_angle = 0f;

            //foreach(var lbl in targetPoints)
            for (int i = 0; i < totalLabels; i++)
            {
                Label_Fitter.LabelPoint labelPoint =
                    new Label_Fitter.LabelPoint()
                {
                    width  = 20,
                    height = 13,
                };

                potentialLabelPoints.Add(labelPoint);

                if (current_angle == 0f)
                {
                    Point p = new Point(controllerImage.Width + controllerImage.Location.X, controllerImage.Height / 2 + controllerImage.Location.Y);
                    labelPoint.x = p.X;
                    labelPoint.y = p.Y;
                }

                if (current_angle <= thetas[1])
                {
                    Func_1(current_angle, controllerImage, labelPoint);
                }

                if (current_angle > thetas[1] && current_angle <= (thetas[1] + 2 * thetas[2]))
                {
                    Func_2(current_angle, controllerImage, labelPoint);
                }

                if (current_angle > (thetas[1] + 2 * thetas[2]) && current_angle <= (3 * thetas[1] + 2 * thetas[2]))
                {
                    Func_3(current_angle, controllerImage, labelPoint);
                }

                if (current_angle > (3 * thetas[1] + 2 * thetas[2]) && current_angle <= (3 * thetas[1] + 4 * thetas[2]))
                {
                    Func_4(current_angle, controllerImage, labelPoint);
                }

                if (current_angle > (3 * thetas[1] + 4 * thetas[2]) && current_angle <= thetas[0])
                {
                    Func_1(current_angle, controllerImage, labelPoint);
                }

                current_angle = (float)Math.Round((current_angle + angle), 3);
            }

            return(potentialLabelPoints);
        }
예제 #3
0
        void Func_4(float angle, Rectangle controllerImage, Label_Fitter.LabelPoint labelPoint)
        {
            double degrees = angle * (Math.PI / 180);
            int    point   = (int)((controllerImage.Height / 2) / (Math.Tan(degrees)));
            Point  p       = new Point(controllerImage.Width / 2 + controllerImage.Location.X - point, controllerImage.Location.Y + controllerImage.Height);

            labelPoint.x = p.X;
            labelPoint.y = p.Y;
        }
예제 #4
0
        //string key, string obtained_key
        //int point_index, int label_index
        void Swap_Labels(Label_Fitter.LabelPoint labelA, Label_Fitter.LabelPoint labelB)
        {
            Point temp_point = new Point(0, 0);

            temp_point.X = labelA.x;
            temp_point.Y = labelA.y;

            labelA.x = labelB.x;
            labelA.y = labelB.y;

            labelB.x = temp_point.X;
            labelB.y = temp_point.Y;
        }
예제 #5
0
        void Func_2(float angle, Rectangle controllerImage, Label_Fitter.LabelPoint labelPoint)
        {
            double degrees = angle * (Math.PI / 180);
            int    point   = 0;

            if (angle == 90)
            {
                point = 0;
            }
            else
            {
                point = (int)((controllerImage.Height / 2) / (Math.Tan(degrees)));
            }
            Point p = new Point(controllerImage.Width / 2 + controllerImage.Location.X + point, controllerImage.Location.Y);

            labelPoint.x = p.X;
            labelPoint.y = p.Y;
        }