Ejemplo n.º 1
0
        public VisualizedWord CalculateWordAppearence(IWeightedWord word, int itemIndex)
        {
            var fontSize = CalculateRelativeValue(Arguments.FontSizeRange, word.Weight);
            var opacity  = CalculateRelativeValue(Arguments.OpacityRange, word.Weight);
            var size     = Arguments.WordSizeCalculator(word.Text, fontSize);
            var visWord  = new VisualizedWord(word)
            {
                FontSize = fontSize,
                Opacity  = opacity,
                Size     = size
            };

            //Startpunkt in der Mitte ermitteln
            var basePoint = new Point
            {
                X = Arguments.PanelSize.Width / 2 - size.Width / 2,
                Y = Arguments.PanelSize.Height / 2 - size.Height / 2
            };
            Rect  rect;
            Point desiredPoint;

            do
            {
                desiredPoint = CalculateSpiralPoint(Radius, Phi, basePoint);
                rect         = new Rect(desiredPoint, size);
                Phi         += Rad(PhiIncreaseDegree * DegreeIncreaseCorrection);
            } while (!IsRadiusOutOfBounds && (IsRectOutOfBounds(rect) || Taken.Any(rect1 => rect.IntersectsWith(rect1))));
            // Radius Out Of Bounds is kill criterial

            Taken.Add(rect);

            visWord.Position = desiredPoint;

            if (!IsRadiusOutOfBounds)
            {
                return(visWord);
            }
            CanAddWords = false;
            return(null);
        }
Ejemplo n.º 2
0
        public VisualizedWord CalculateWordAppearence(IWeightedWord word, int itemIndex /*, VisualizedWord preDecessors*/)
        {
            //Ausdehnung
            var size = Arguments.WordSizeCalculator(word.Text, CalculateRelativeValue(Arguments.FontSizeRange, word.Weight));



            //Startpunkt ermitteln
            var p = new Point();

            if (itemIndex == 0)   //vll auch (0,0), später!
            {
                p.X = 0;
                p.Y = 0;
                pos = 0;
            }
            else
            {
                p = GetSpiralPoint(pos /*, radius = 2*/);
            }


            //mach' ein Rechteck d'raus
            var rectangle = new System.Windows.Rect()
            {
                Location = p,
                Size     = size
            };
            var rectgeom = rectangle;//geometrisch

            //bis Platz gefunden
            var found   = false;
            var nofound = false;

            var offsetvector = new System.Windows.Vector(
                Arguments.PanelSize.Width / 2,
                Arguments.PanelSize.Height / 2
                );

            //Kollisionserkennung: über Vorgänger iterieren
            //Teste Position (x,y) ist frei für Wort mit Größe size
            var intersect = new Rect();
            var tau       = 2 * Math.PI;
            var itemCnt   = 0;

            rectgeom.Offset(offsetvector);
            while (!((itemIndex <= 0) || found))
            {
                nofound = false;
                foreach (Rect r in Taken)
                {
                    var f = this.RectIntersectsRect(rectangle, r);
                    if (f)   // darf ich benutzen, anliegende kanten werden als intersected bewertet
                    {
                        nofound = true;
                    }
                }
                if (nofound ||
                    rectgeom.Left < 0 || rectgeom.Left >= Arguments.PanelSize.Width ||
                    rectgeom.Top < 0 || rectgeom.Top >= Arguments.PanelSize.Height ||
                    rectgeom.Right < 0 || rectgeom.Right >= Arguments.PanelSize.Width ||
                    rectgeom.Bottom < 0 || rectgeom.Bottom >= Arguments.PanelSize.Height
                    )
                {
                    nofound = true;
                }
                // Platz belegt
                // neue Postion anhand Fläche bestimmen, min Schritte von 3,6°

                if (nofound)
                {
                    itemCnt++;
                    Cnt++;
                    var a = (this.Area(intersect) / this.Area(rectgeom));
                    pos += tau / Sectors + a;
                    //var a = 0.2 + (this.Area(intersect) / this.Area(rectgeom));
                    //pos += tau / Sectors * a;
                    p = GetSpiralPoint(pos);//this.Radius
                    //p.X -= (Arguments.WordMargin.Left );
                    //p.Y -= (Arguments.WordMargin.Top );
                    //rectangle.Width += Arguments.WordMargin.Left + Arguments.WordMargin.Right;
                    //rectangle.Height += Arguments.WordMargin.Top + Arguments.WordMargin.Bottom;
                    rectangle.Location = p;
                    rectgeom           = rectangle;
                    rectgeom.Offset(offsetvector);
                    //nofound = false;
                }
                else
                {
                    found   = true;
                    itemCnt = 0;
                    if (itemIndex > 44)
                    {
                        ;
                    }
                }
                if (itemCnt > Sectors * 2)
                {
                    break;
                }
            }

            //bzw. of Position (x,y) bis Position (x+size.Width,y+size.Height) frei/leer ist
            //wenn nicht, neue Position anhand Spirale a(r,phi) => a(x,y)

            //var durch = 0;
            //foreach (Rect r in Taken)
            //{
            //    Console.Write(durch);
            //    Console.Write(":");
            //    Console.Write(r.TopLeft);
            //    Console.Write("-");
            //    Console.Write(r.TopRight);
            //    Console.Write("\r\n");
            //    durch++;
            //};

            // raise flag to stop new Words
            if (
                (StopAfterWords >= 1 && itemIndex >= (StopAfterWords - 1)) ||
                !this.RectIntersectsRect(rectgeom, new Rect(new Point(0, 0), new System.Windows.Size(Arguments.PanelSize.Width, Arguments.PanelSize.Height)))
                )
            {
                CanAddWords = false;
            }

            //rechtecke für nächsten Durchlauf speichern
            if (!rectangle.IsEmpty || CanAddWords)
            {
                Taken.Add(rectangle);

                var vergl = new Range(Arguments.FontSizeRange.Min, Arguments.FontSizeRange.Max /*, 0.5*/).CalculateRelativeValue(Arguments.FontSizeRange, word.Weight);
                return(new VisualizedWord(word)
                {
                    Size = new Size(rectangle.Width, rectangle.Height),
                    //FontSize = Convert.ToInt32((Arguments.FontSizeRange.Min / Arguments.FontSizeRange.Max * word.Weight % Arguments.FontSizeRange.Max + Arguments.FontSizeRange.Min) / 0.5) * 0.5,
                    //FontSize = Arguments.FontSizeRange.CalculateRelativeValue(Arguments.FontSizeRange, word.Weight/*, 0.5, 1*/),
                    FontSize = CalculateRelativeValue(Arguments.FontSizeRange, word.Weight, 0.5, 1),
                    Position = new Point(rectangle.Top, rectangle.Left),
                    //Opacity = (Arguments.OpacityRange.Min / Arguments.OpacityRange.Max * word.Weight % 150 + Arguments.OpacityRange.Min) / 150 //CalculateRelativeValue(Arguments.OpacityRange, word.Weight, double Step)
                    Opacity = this.CalculateRelativeValue(Arguments.OpacityRange, word.Weight, 0.1, 1)
                              //Opacity = Arguments.OpacityRange.CalculateRelativeValue(Arguments.OpacityRange, word.Weight/*, 0.1, 1*/)
                }
                       );
            }
            else
            {
                return(new VisualizedWord(word));
            }
        }