示例#1
0
        public void PointRotateCenterTestMethod()
        {
            Point p1 = new Point(30, 20);
            Point p2 = new Point(20, 30);
            Point c  = new Point(20, 20);

            Point r1 = p1.Rotate(0, c).Round(8);
            Point r2 = p1.Rotate(90, c).Round(8);
            Point r3 = p1.Rotate(180, c).Round(8);
            Point r4 = p1.Rotate(270, c).Round(8);

            Point r5 = p2.Rotate(0, c).Round(8);
            Point r6 = p2.Rotate(90, c).Round(8);
            Point r7 = p2.Rotate(180, c).Round(8);
            Point r8 = p2.Rotate(270, c).Round(8);

            Assert.AreEqual(new Point(20 + 10, 20 + 0), r1);
            Assert.AreEqual(new Point(20 + 0, 20 + 10), r2);
            Assert.AreEqual(new Point(20 - 10, 20 + 0), r3);
            Assert.AreEqual(new Point(20 + 0, 20 - 10), r4);

            Assert.AreEqual(new Point(20 + 0, 20 + 10), r5);
            Assert.AreEqual(new Point(20 - 10, 20 + 0), r6);
            Assert.AreEqual(new Point(20 + 0, 20 - 10), r7);
            Assert.AreEqual(new Point(20 + 10, 20 + 0), r8);
        }
示例#2
0
        private void AddPaths(Point startingPosition, int player)
        {
            Point towardsCenter = (center - startingPosition).ScaleTo(pathLength);

            Point centerStart = startingPosition + towardsCenter;

            map.AddWaypath(
                "Center" + player,
                info.ObjectFactory.CreateWaypoint(centerStart.X, centerStart.Y),
                info.ObjectFactory.CreateWaypoint(startingPosition.X, startingPosition.Y));

            Point flankStart = centerStart.Rotate(startingPosition, Angle.ToRadians(angleBetweenPaths));

            map.AddWaypath(
                "Flank" + player,
                info.ObjectFactory.CreateWaypoint(flankStart.X, flankStart.Y),
                info.ObjectFactory.CreateWaypoint(startingPosition.X, startingPosition.Y));

            Point backDoorStart = centerStart.Rotate(startingPosition, Angle.ToRadians(-angleBetweenPaths));

            map.AddWaypath(
                "BackDoor" + player,
                info.ObjectFactory.CreateWaypoint(backDoorStart.X, backDoorStart.Y),
                info.ObjectFactory.CreateWaypoint(startingPosition.X, startingPosition.Y));

            AddPatrolPath(startingPosition, flankStart, "player" + player + "_patrol1");
            AddPatrolPath(startingPosition, backDoorStart, "player" + player + "_patrol2");
        }
示例#3
0
        public void PointRotateTestMethod()
        {
            Point p1 = new Point(10, 0);
            Point p2 = new Point(0, 10);

            Point r1 = p1.Rotate(0).Round(8);
            Point r2 = p1.Rotate(90).Round(8);
            Point r3 = p1.Rotate(180).Round(8);
            Point r4 = p1.Rotate(270).Round(8);

            Point r5 = p2.Rotate(0).Round(8);
            Point r6 = p2.Rotate(90).Round(8);
            Point r7 = p2.Rotate(180).Round(8);
            Point r8 = p2.Rotate(270).Round(8);

            Assert.AreEqual(new Point(10, 0), r1);
            Assert.AreEqual(new Point(0, 10), r2);
            Assert.AreEqual(new Point(-10, 0), r3);
            Assert.AreEqual(new Point(0, -10), r4);

            Assert.AreEqual(new Point(0, 10), r5);
            Assert.AreEqual(new Point(-10, 0), r6);
            Assert.AreEqual(new Point(0, -10), r7);
            Assert.AreEqual(new Point(10, 0), r8);
        }
        private Point RotatePoint(Point point, double angle)
        {
            Point p = rotate == Axis.x ? point.Rotate(angle) : point.Rotate(0, angle);

            UpdateLimits(GetRelativeElements(p));

            return(p);
        }
        internal static void Sweep(IEnumerable <Polyline> obstacles,
                                   Point direction, double coneAngle, VisibilityGraph visibilityGraph,
                                   IEnumerable <Point> portLocations)
        {
            var cs = new LineSweeperForPortLocations(obstacles, direction, direction.Rotate(-coneAngle / 2),
                                                     direction.Rotate(coneAngle / 2), visibilityGraph, portLocations);

            cs.Calculate();
        }
示例#6
0
        public void Rotate2()
        {
            const int away  = 90;
            var       x     = 10;
            var       y     = 20;
            var       point = new Point(x, y);
            var       move  = new Point(-away, 0);
            var       p     = point + move;

            for (var i = 1; i <= 3; i++)
            {
                var rotated = Point.Rotate(point, p, 90 * i);

                switch (i)
                {
                case 1:
                    Assert.AreEqual(rotated.X, x, $"Check X and Rotate: {90 * i}");
                    Assert.AreEqual(rotated.Y, y - away, $"Check Y Rotate: {90 * i}");
                    break;

                case 2:
                    Assert.AreEqual(rotated.X, x + away, $"Check X and Rotate: {90 * i}");
                    Assert.AreEqual(rotated.Y, y, $"Check Y Rotate: {90 * i}");
                    break;

                case 3:
                    Assert.AreEqual(rotated.X, x, $"Check X and Rotate: {90 * i}");
                    Assert.AreEqual(rotated.Y, y + away, $"Check Y and Rotate: {90 * i}");
                    break;
                }
            }
        }
示例#7
0
        public void RotateAroundOtherPointTest(Point original, Point axis, double degrees, Point expected)
        {
            Point answer = original.Rotate(degrees, axis);

            Assert.Equal(expected, answer);
            AssertEquidistant(expected, answer, axis);
        }
示例#8
0
        /// <inheritdoc/>
        protected override void OnApply(ImageBase <TPixel> source, Rectangle sourceRectangle)
        {
            if (this.OptimizedApply(source))
            {
                return;
            }

            int       height = this.CanvasRectangle.Height;
            int       width  = this.CanvasRectangle.Width;
            Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix);

            using (var targetPixels = new PixelAccessor <TPixel>(width, height))
            {
                Parallel.For(
                    0,
                    height,
                    this.ParallelOptions,
                    y =>
                {
                    Span <TPixel> targetRow = targetPixels.GetRowSpan(y);

                    for (int x = 0; x < width; x++)
                    {
                        var transformedPoint = Point.Rotate(new Point(x, y), matrix);

                        if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y))
                        {
                            targetRow[x] = source[transformedPoint.X, transformedPoint.Y];
                        }
                    }
                });

                source.SwapPixelsBuffers(targetPixels);
            }
        }
示例#9
0
        private PointSet method_3(Autodesk.AutoCAD.DatabaseServices.Circle circle_0, double double_1)
        {
            PointSet result;

            try
            {
                PointSet pointSet = new PointSet();
                ngeometry.VectorGeometry.Circle circle = Conversions.ToCeometricCircle(circle_0);
                if (double_1 > 0.0 && double_1 < circle.Circumference)
                {
                    int    num   = Math.Max((int)Math.Ceiling(circle.Circumference / double_1), 4);
                    double num2  = 6.2831853071795862 / (double)num;
                    Point  point = Conversions.ToCeometricPoint(circle_0.StartPoint);
                    for (int i = 0; i < num; i++)
                    {
                        ngeometry.VectorGeometry.Matrix3d rotationMatrix = ngeometry.VectorGeometry.Matrix3d.RotationArbitraryAxis(circle.NormalVector, (double)i * num2);
                        pointSet.Add(point.Rotate(circle.Center, rotationMatrix));
                    }
                }
                else
                {
                    pointSet.Add(circle.Center);
                }
                result = pointSet;
            }
            catch (System.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Can not subdivide circle (handle: " + circle_0.Handle.ToString() + ")\n");
                result = null;
            }
            return(result);
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <param name="third"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="padding"></param>
        /// <returns>number of new points</returns>
        static int GetPaddedCorner(PolylinePoint first, PolylinePoint second, PolylinePoint third, out Point a, out Point b,
                                   double padding)
        {
            Point u = first.Point;
            Point v = second.Point;
            Point w = third.Point;
            // System.Diagnostics.Debug.Assert(Point.GetTriangleOrientation(u, v, w) == TriangleOrientation.Clockwise);

            Point uvPerp = (v - u).Rotate(Math.PI / 2).Normalize();
            ////uvPerp has to look outside of the curve
            //if (uvPerp * (v - Origin) < 0)
            //    uvPerp *= -1;

            Point l = (v - u).Normalize() + (v - w).Normalize();

            if (l.Length < ApproximateComparer.IntersectionEpsilon)
            {
                a = b = v + padding * uvPerp;
                return(1);
            }
            Point d  = l.Normalize() * padding;
            Point dp = d.Rotate(Math.PI / 2);

            //look for a in the form d+x*dp
            //we have:  Padding=(d+x*dp)*uvPerp
            double xp = (padding - d * uvPerp) / (dp * uvPerp);

            a = d + xp * dp + v;
            b = d - xp * dp + v;
            return(2); //number of points to add
        }
示例#11
0
        /// <inheritdoc/>
        public override void Apply(ImageBase <TColor, TPacked> target, ImageBase <TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
        {
            if (this.OptimizedApply(target, source))
            {
                return;
            }

            int       height = target.Height;
            int       width  = target.Width;
            Matrix3x2 matrix = GetCenteredMatrix(target, source, this.processMatrix);

            using (PixelAccessor <TColor, TPacked> sourcePixels = source.Lock())
                using (PixelAccessor <TColor, TPacked> targetPixels = target.Lock())
                {
                    Parallel.For(
                        0,
                        height,
                        this.ParallelOptions,
                        y =>
                    {
                        for (int x = 0; x < width; x++)
                        {
                            Point transformedPoint = Point.Rotate(new Point(x, y), matrix);
                            if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y))
                            {
                                targetPixels[x, y] = sourcePixels[transformedPoint.X, transformedPoint.Y];
                            }
                        }
                    });
                }
        }
示例#12
0
        protected override void ExecuteInstructionSimple(InstructionSimple instruction)
        {
            JoueurEnCours.EtatJoueur.Angle += instruction.EtatFinal.Angle;
            JoueurEnCours.EtatJoueur.Angle  = JoueurEnCours.EtatJoueur.Angle % 360.0;
            if (instruction.EtatFinal.Crayon != Etat.EtatCrayon.SAME)
            {
                JoueurEnCours.EtatJoueur.Crayon = instruction.EtatFinal.Crayon;
            }


            if (instruction.EtatFinal.Position != null)
            {
                Point position      = instruction.EtatFinal.Position;
                Point imageRotation = position.Rotate(JoueurEnCours.EtatJoueur.Angle);

                Point positionJoueur = JoueurEnCours.EtatJoueur.Position;
                Point image          = positionJoueur.Add(imageRotation);

                if (JoueurEnCours.EtatJoueur.Crayon == Etat.EtatCrayon.BAISSER)
                {
                    IVecteur vect = FabriqueVecteur.getVecteur(niveauEnCours.Type, JoueurEnCours.EtatJoueur.Position, image);
                    FormeEnCours.Add(vect);
                }
                JoueurEnCours.EtatJoueur.Position = image;
            }
        }
示例#13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <param name="third"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="padding"></param>
        /// <returns>number of new points</returns>
        static int GetPaddedCorner(PolylinePoint first, PolylinePoint second, PolylinePoint third, out Point a, out Point b,
                                   double padding)
        {
            Point u   = first.Point;
            Point v   = second.Point;
            Point w   = third.Point;
            bool  ccw = Point.GetTriangleOrientation(u, v, w) == TriangleOrientation.Counterclockwise;

            //uvPerp has to look outside of the curve
            var uvPerp = (v - u).Rotate((ccw? -Math.PI:Math.PI) / 2).Normalize();



            //l is bisector of the corner (u,v,w) pointing out of the corner - outside of the polyline
            Point l = (v - u).Normalize() + (v - w).Normalize();

            Debug.Assert(l * uvPerp >= 0);
            if (l.Length < ApproximateComparer.IntersectionEpsilon)
            {
                a = b = v + padding * uvPerp;
                return(1);
            }
// flip uvPerp if it points inside of the polyline
            Point d  = l.Normalize() * padding;
            Point dp = d.Rotate(Math.PI / 2);

            //look for a in the form d+x*dp
            //we have:  Padding=(d+x*dp)*uvPerp
            double xp = (padding - d * uvPerp) / (dp * uvPerp);

            a = d + xp * dp + v;
            b = d - xp * dp + v;
            return(2); //number of points to add
        }
示例#14
0
        /// <summary>
        /// p1 and p2 represent the closest feature. Two cases are possible p1=p2, or p1 and p2 share an edge going from p1 to p2
        /// Remind that the polygons are oriented clockwise
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="bisectorPivot"></param>
        /// <param name="bisectorRay"></param>
        /// <returns></returns>
        internal int FindTheFurthestVertexFromBisector(int p1, int p2, Point bisectorPivot, Point bisectorRay)
        {
            Point directionToTheHill = bisectorRay.Rotate(Math.PI / 2);

            if ((polyline.StartPoint.Point - bisectorPivot) * directionToTheHill < 0)
            {
                directionToTheHill = -directionToTheHill;
            }
            if (p1 == p2)
            {
                p2 = Next(p1);
            }
            //binary search
            do
            {
                int   m  = Median(p2, p1); //now the chunk goes clockwise from p2 to p1
                Point mp = Pnt(m);

                if ((Pnt(Next(m)) - mp) * directionToTheHill >= 0)
                {
                    p2 = Next(m);
                }
                else if ((Pnt(Prev(m)) - mp) * directionToTheHill >= 0)
                {
                    p1 = Prev(m);
                }
                else
                {
                    p1 = p2 = m;
                }
            }while (p1 != p2);

            return(p1);
        }
示例#15
0
        public void AddTemplateToMap(ObjectTemplate template, Map map, MapInfo info, TileInfo blockedTileInfo, Point position, float?rotation, string roadType)
        {
            if (template.IsInstantiated)
            {
                throw new InvalidOperationException("A template can only be added to a map once. Consider cloning it before adding it to the map.");
            }

            Point origin = template.CalculateOrigin();

            foreach (var obj in template.Objects)
            {
                obj.Properties["uniqueID"].Value = objectId.ToString();
                Point point = new Point(position.X + obj.X - origin.X, position.Y + obj.Y - origin.Y);
                if (rotation.HasValue)
                {
                    point         = point.Rotate(position, rotation.Value);
                    obj.Rotation += rotation.Value;
                }

                obj.X = point.X;
                obj.Y = point.Y;

                map.Objects.Add(obj);
                objectId++;
            }

            AddFlattenedArea(template, info);

            AddTextures(template, map, info, blockedTileInfo, position, rotation, origin);

            AddRoadsFromTemplateToMap(template, map, info, roadType);

            template.IsInstantiated = true;
        }
示例#16
0
        /// <inheritdoc/>
        protected override void OnApply(ImageBase <TColor> source, Rectangle sourceRectangle)
        {
            if (this.OptimizedApply(source))
            {
                return;
            }

            int       height = this.CanvasRectangle.Height;
            int       width  = this.CanvasRectangle.Width;
            Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix);

            TColor[] target = new TColor[width * height];

            using (PixelAccessor <TColor> sourcePixels = source.Lock())
                using (PixelAccessor <TColor> targetPixels = target.Lock <TColor>(width, height))
                {
                    Parallel.For(
                        0,
                        height,
                        this.ParallelOptions,
                        y =>
                    {
                        for (int x = 0; x < width; x++)
                        {
                            Point transformedPoint = Point.Rotate(new Point(x, y), matrix);
                            if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y))
                            {
                                targetPixels[x, y] = sourcePixels[transformedPoint.X, transformedPoint.Y];
                            }
                        }
                    });
                }

            source.SetPixels(width, height, target);
        }
示例#17
0
        public void RotateAroundZeroZeroTest(Point original, double degrees, Point expected)
        {
            Point answer = original.Rotate(degrees);

            Assert.Equal(expected, answer);
            AssertEquidistant(expected, answer, (0, 0));
        }
示例#18
0
        private static void AddTextures(ObjectTemplate template, Map map, MapInfo info, TileInfo blockedTileInfo, Point position, float?rotation, Point origin)
        {
            float width  = template.Tiles.Width * Map.TileWidth;
            float height = template.Tiles.Height * Map.TileWidth;

            Point[] corners = new Point[]
            {
                new Point(position.X - origin.X, position.Y - origin.Y),
                new Point(position.X - origin.X, position.Y - origin.Y + height),
                new Point(position.X - origin.X + width, position.Y - origin.Y + height),
                new Point(position.X - origin.X + width, position.Y - origin.Y)
            };

            if (rotation.HasValue)
            {
                for (int i = 0; i < corners.Length; i++)
                {
                    corners[i] = corners[i].Rotate(position, rotation.Value);
                }
            }

            var bottomLeft = map.PositionToCoordinates(new Point(corners.Min(c => c.X), corners.Min(c => c.Y)));
            var topRight   = map.PositionToCoordinates(new Point(corners.Max(c => c.X), corners.Max(c => c.Y)));

            for (int x = bottomLeft.X; x <= topRight.X; x++)
            {
                for (int y = bottomLeft.Y; y <= topRight.Y; y++)
                {
                    if (map.Tiles.CheckCoordinates(x, y))
                    {
                        Point positionInTemplate = map.CoordinatesToPosition(new Coordinates(x, y));

                        if (rotation.HasValue)
                        {
                            positionInTemplate = positionInTemplate.Rotate(position, -rotation.Value);
                        }

                        positionInTemplate = positionInTemplate - position + origin;

                        var coordinates = template.Map.PositionToCoordinates(positionInTemplate);
                        if (template.Tiles.CheckCoordinates(coordinates.X, coordinates.Y))
                        {
                            if (template.Tiles[coordinates.X, coordinates.Y].Impassable)
                            {
                                info.Tiles[x, y] |= blockedTileInfo;
                            }

                            Texture texture = template.Tiles.GetTexture(coordinates.X, coordinates.Y);
                            if (texture.Name != ObjectTemplate.TextureTemplate)
                            {
                                texture = new Texture(texture.Name, texture.BlocksPerRow);
                                texture = map.Tiles.AddTexture(texture);
                                info.TextureData[x, y] = texture;
                            }
                        }
                    }
                }
            }
        }
示例#19
0
        public static System.Drawing.Point ToHeadSpace(this Point target, Point windowDims, double headAngle, double scaleX, double scaleY, double offsetX, double offsetY, double priorAngle, double scapeDistance)
        {
            target = target.Multiply(scaleX * scapeDistance, scaleY * scapeDistance);
            target = target.Rotate(headAngle - priorAngle);
            target.Offset(windowDims.X / 2.0 - offsetX, windowDims.Y / 2.0 - offsetY);

            return(target.ToDrawingPoint());
        }
示例#20
0
        public static Point ToPriorSpace(this Point target, Point windowDims, double headAngle, double scaleX, double scaleY, double offsetX, double offsetY, double priorAngle, double scapeDistance)
        {
            target.Offset(-windowDims.X / 2.0 + offsetX, -windowDims.Y / 2.0 + offsetY);
            target = target.Multiply(1.0 / (scaleX * scapeDistance), 1.0 / (scaleY * scapeDistance));
            target = target.Rotate(-(headAngle - priorAngle));

            return(target);
        }
示例#21
0
        public void Rotate90Degrees()
        {
            Point p = new Point(1, 2);

            p = p.Rotate(90);

            Assert.AreEqual(-2, p.X);
            Assert.AreEqual(1, p.Y);
        }
示例#22
0
        public void RotateTest()
        {
            var       p      = new Point(13, 17);
            Matrix3x2 matrix = Matrix3x2Extensions.CreateRotationDegrees(45, Point.Empty);

            var pout = Point.Rotate(p, matrix);

            Assert.Equal(new Point(-3, 21), pout);
        }
示例#23
0
        public void PointRotateTest2()
        {
            var a = new Point(-2, 1);
            var o = new Point(0, 0);

            a.Rotate(Math.PI * 2, o);
            Assert.AreEqual(-2, Math.Round(a.x));
            Assert.AreEqual(1, Math.Round(a.y));
        }
示例#24
0
        public void RotateTest()
        {
            Point p5 = new Point(1, 0);

            p5.Rotate(90);

            Assert.Equal(p5.getX(), 6.123233995736766E-17);
            Assert.Equal(p5.getY(), 1);
        }
示例#25
0
        public void Rotate270Degrees()
        {
            Point p = new Point(1, 2);

            p = p.Rotate(270);

            Assert.AreEqual(2, p.X);
            Assert.AreEqual(-1, p.Y);
        }
        private static Point GetSearchDirection(Point derivative, double side)
        {
            Point direction = derivative.Rotate(Math.PI / 2).Normalize() * side;

            // Rotating can cause tiny drift in the X/Y values.  Round so that 0 actually equals 0
            direction = new Point(Math.Round(direction.X, 5), Math.Round(direction.Y, 5));

            return(direction);
        }
示例#27
0
        public void Rotate135Degrees()
        {
            Point p = new Point(1, 0);

            p = p.Rotate(135);

            Assert.AreEqual(-p.X, p.Y, 0.0000001);
            Assert.IsTrue(p.Y > 0);
        }
 private void AttachedWall_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "X" || e.PropertyName == "Y" || e.PropertyName == "Orientation")
     {
         Orientation = _attachedWall.Orientation;
         Point newPosition = new Point(_attachedWall.X, _attachedWall.Y).Add(_pointOnWall.Rotate(Orientation));
         X = newPosition.X;
         Y = newPosition.Y;
     }
 }
示例#29
0
        public void TestRotate()
        {
            var pt1 = new Point(1, 1);
            var pt2 = new Point(2, 2);

            var pt1_1 = pt1.Rotate(UnitVector.FromAngle(Math.PI / 4), Point.Zero);
            var pt2_1 = pt2.Rotate(UnitVector.FromAngle(Math.PI / 4), Point.Zero);

            var a1 = (pt2_1 - pt1_1).Unit.ToAngle();

            var pt1_2 = pt1.Rotate(UnitVector.FromAngle(Math.PI / 8), Point.Zero);
            var pt2_2 = pt2.Rotate(UnitVector.FromAngle(Math.PI / 8), Point.Zero);

            pt2_2 = pt2_2.Rotate(UnitVector.FromAngle(Math.PI / 8), pt1_2);

            var a2 = (pt2_2 - pt1_2).Unit.ToAngle();

            Assert.AreEqual(a1, a2, Tol);
        }
示例#30
0
 public LineSweeperBase(IEnumerable <Polyline> obstacles, Point sweepDirection)
 {
     Obstacles             = obstacles;
     SweepDirection        = sweepDirection;
     DirectionPerp         = sweepDirection.Rotate(-Math.PI / 2);
     EventQueue            = new BinaryHeapWithComparer <SweepEvent>(this);
     ObstacleSideComparer  = new ObstacleSideComparer(this);
     LeftObstacleSideTree  = new RbTree <SegmentBase>(ObstacleSideComparer);
     RightObstacleSideTree = new RbTree <SegmentBase>(ObstacleSideComparer);
 }
示例#31
0
文件: IRob.cs 项目: eastcm/RobSim
 public void Rotate(double a, double b, double c)
 {
     Point point = new Point(X, Y, Z);
     point.Rotate(a, b, c);
     X = (int)point.X;
     Y = (int)point.Y;
     Z = (int)point.Z;
 }
示例#32
0
文件: IRob.cs 项目: eastcm/RobSim
 public void Rotate(RotationMatrix R)
 {
     Point point = new Point(X, Y, Z);
     point.Rotate(R);
     X = (int)point.X;
     Y = (int)point.Y;
     Z = (int)point.Z;
 }
示例#33
0
        /// <summary>
        /// Calculates Canvas position with a given game world position
        /// </summary>
        public void Update(Vector3 position)
        {
            try
            {
                WorldVector = position;

                var centerActorPosition = CanvasData.CenterVector;

                // Distance from Actor to Player
                RawWorldDistanceX = centerActorPosition.X - position.X;
                RawWorldDistanceY = centerActorPosition.Y - position.Y;

                // We want 1 yard of game distance to = Gridsize
                RawDrawDistanceX = RawWorldDistanceX * (float)CanvasData.GridSquareSize.Width;
                RawDrawDistanceY = RawWorldDistanceY * (float)CanvasData.GridSquareSize.Height;

                // Distance on canvas from center to actor
                RawDrawPositionX = (CanvasData.Center.X + RawDrawDistanceX);
                RawDrawPositionY = (CanvasData.Center.Y + RawDrawDistanceY);

                // Points in Canvas and Grid Scale
                RawPoint = new Point(RawDrawPositionX, RawDrawPositionY);
                RawGridPoint = new Point(RawDrawPositionX / CanvasData.GridSquareSize.Width, RawDrawPositionY / CanvasData.GridSquareSize.Height);

                // Switched to manual calculations because WPF transforms are very slow 
                // (0.0015ms+ each versus 0.0000ms for raw math).
                Point = RawPoint.Rotate(CanvasData.Center, CanvasData.GobalRotationAngle);
                Point = Point.FlipX(CanvasData.Center);               

                GridPoint = new Point((int)(Point.X / CanvasData.GridSquareSize.Width), (int)(Point.Y / CanvasData.GridSquareSize.Height));
                IsBeyondCanvas = Point.X < 0 || Point.X > CanvasData.CanvasSize.Width || Point.Y < 0 || Point.Y > CanvasData.CanvasSize.Height;
            }
            catch (Exception ex)
            {
                Logger.Debug("Exception in RadarUI.PointMorph.Update(). {0} {1}", ex.Message, ex.InnerException);
            }
        }
        /// <summary>
        /// 子要素配置のオーバーライド
        /// </summary>
        /// <param name="arrangeBounds">使用可能領域</param>
        /// <returns>使用した領域のサイズを返します。</returns>
        protected override Size ArrangeOverride(Size arrangeBounds)
        {
#if DEBUG
            Debug.WriteLine("[{0}] ArrangeOverride[{1}]", this._measureCounter, arrangeBounds);
#endif
            var angle = 360.0 / this.InternalChildren.Count;
            foreach (var item in this.InternalChildren.OfType<UIElement>().Select((x, i) => new { Element = x, Angle = i * angle }))
            {
                if (item.Element != null)
                {
                    var origin = new Point(this._mainboardCenter.X, this._mainboardCenter.Y - this._mainboardSize.Height / 2.0);
                    var pt = origin.Rotate(item.Angle, this._mainboardCenter);
                    pt.Offset(-item.Element.DesiredSize.Width / 2.0, -(pt.Y - origin.Y) / this._mainboardSize.Height * item.Element.DesiredSize.Height);
                    var offset = GetLabelOffset(item.Element);
                    pt.Offset(offset.X, offset.Y);
                    item.Element.Arrange(new Rect(pt, item.Element.DesiredSize));
                }
            }

            return arrangeBounds;
        }