예제 #1
0
		public void Point()
		{
			//Do various Point method calls to cover the point class with sufficient testing
			Point p0 = new Point();
			Point p1 = new Point(0,0);
			Point p2 = new Point(450, 120);
			Assert.IsTrue(p0.IsEmpty());
			Assert.IsFalse(p1.IsEmpty());
			Assert.AreNotEqual(p0, p1);
			Assert.AreEqual(450, p2.X);
			Assert.AreEqual(120, p2.Y);
			Assert.AreNotSame(p2.Clone(), p2);
			p0 = p2.Clone();
			p0.X += 100; p0.Y = 150;
			p0[0] += p0[1];
			Assert.AreEqual(new Point(700, 150),p0);
			Assert.AreEqual(p2, p2.GetBoundingBox().Min);
			Assert.AreEqual(p2, p2.GetBoundingBox().Max);
			Assert.IsTrue(p2.IsSimple());
			Assert.IsFalse(p2.IsEmpty());
			Assert.AreEqual(2, p2.NumOrdinates);
			Assert.AreEqual(new Point(400, 100), p2 + new Point(-50, -20));
			Assert.AreEqual(new Point(500, 100), p2 - new Point(-50, 20));
			Assert.AreEqual(new Point(900, 240), p2 * 2);
			Assert.AreEqual(0, p2.Dimension);
			Assert.AreEqual(450, p2[0]);
			Assert.AreEqual(120, p2[1]);
			Assert.IsNull(p2.Boundary());
			Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty().GetHashCode(), p2.GetHashCode());
			Assert.Greater(p2.CompareTo(p1), 0);
			Assert.Less(p1.CompareTo(p2), 0);
			Assert.AreEqual(p2.CompareTo(new Point(450,120)), 0);
		}
예제 #2
0
        private double _yw; //y width

        #endregion Fields

        #region Constructors

        public AABB(Point pos, double xw, double yw)
        {
            _pos = pos;
              _oldPos = (Point)pos.Clone();
              _xw = xw;
              _yw = yw;
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var point = new Point(1, 2);
            var point2 = point.Clone() as Point;
            point.Move(2, 3);
            point.Print();
            point2.Print();

            var personWithChildren = new PersonWithChildren("John", "Doe");
            Console.WriteLine(personWithChildren.Name);
            personWithChildren.Children.Add(new PersonWithChildren("John", "Little"));
            Console.WriteLine(personWithChildren["John Little"].Name);
        }
예제 #4
0
        public Point raycast(Point start, Point goal)
        {
            List<Point> pointsOnLine = Bresenham.getCellsOnLine(start, goal);

            Point hitPoint = (Point) start.Clone();
            foreach(Point p in pointsOnLine) {
                AStarCell cell = map.getCell(p.x, p.y);
                if(cell == null || cell.isObstacle()) {
                    break;
                } else {
                    hitPoint = p;
                }
            }
            return hitPoint;
        }
        /// <summary>
        /// Lets the tree grow according to the ideal distances.
        /// </summary>
        /// <param name="treeEdges"></param>
        /// <param name="nodePositions"></param>
        /// <param name="rootNodeId"></param>
        static void MoveNodePositions(List<Tuple<int, int, double, double, double>> treeEdges, Point[] nodePositions,
            int rootNodeId) {
            var posOld = (Point[]) nodePositions.Clone();

            var visited = new Set<int>();
            visited.Insert(rootNodeId);
            for (int i = 0; i < treeEdges.Count; i++) {
                var tupleEdge = treeEdges[i];
                if (visited.Contains(tupleEdge.Item1))
                    MoveUpperSite(tupleEdge, nodePositions, posOld, visited);
                else {
                    Debug.Assert(visited.Contains(tupleEdge.Item2));
                    MoveLowerSite(tupleEdge, nodePositions, posOld, visited);
                }
            }

        }
		/// <summary>
		/// Transforms a coordinate point. The passed parameter point should not be modified.
		/// </summary>
		/// <param name="point"></param>
		/// <returns></returns>
		public override Point Transform(Point point)
		{
			Point pOut = point.Clone() as Point;
			pOut.X /= SourceGCS.AngularUnit.RadiansPerUnit;
			pOut.X -= SourceGCS.PrimeMeridian.Longitude/SourceGCS.PrimeMeridian.AngularUnit.RadiansPerUnit;
			pOut.X += TargetGCS.PrimeMeridian.Longitude/TargetGCS.PrimeMeridian.AngularUnit.RadiansPerUnit;
			pOut.X *= SourceGCS.AngularUnit.RadiansPerUnit;
			return pOut;
		}
예제 #7
0
        /// <summary>
        /// Sets the vertices making a copy of the specified array.
        /// The polygon vertices must be clock-wise and not overlap.
        /// </summary>
        /// <param name="vertices">The vertices.</param>
        /// <exception cref="ArgumentNullException">
        /// Vertices cannot be null.
        /// </exception>
        public void SetVertices(Point[] vertices)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException("vertices");
            }

            this.vertices = vertices.Clone() as Point[];
            this.UpdateArea();
        }
        /// <summary>
        /// sometimes we have very small mistakes in the positions that have to be fixed
        /// </summary>
        /// <returns></returns>
        static Point Rectilinearise(Point a, Point b) {
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=369
            b = b.Clone();
#endif
            if (a.X != b.X && a.Y != b.Y) {
                var dx = Math.Abs(a.X - b.X);
                var dy = Math.Abs(a.Y - b.Y);
                if (dx < dy)
                    b.X = a.X;
                else
                    b.Y = a.Y;
            }
            return b;
        }