ToArray() public method

public ToArray ( ) : long[]
return long[]
Example #1
0
        /// <summary>
        /// Create a round section of type matidx in blocklist.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="vCenter">the coordinates of the center block</param>
        /// <param name="radius">the radius of the section.</param>
        /// <param name="diraxis">The list index for the axis to make the section perpendicular to.  0 indicates the x axis, 1 the y, 2 the z.  The section will extend along the other two axies.</param>
        /// <param name="mat">What to make the section out of</param>
        public void crossection(ref IMapHandler map, Vector3i vCenter, double radius, int diraxis, byte mat)
        {
            long[] centArray = vCenter.ToArray();
            int    rad       = (int)(radius + .618d);
            int    secidx1   = (diraxis - 1) % 3;
            int    secidx2   = (1 + diraxis) % 3;

            int[] coord = new int [] { 0, 0, 0 };
            for (int off1 = -rad; off1 < rad + 1; off1++)
            {
                for (int off2 = -rad; off2 < rad + 1; off2++)
                {
                    double thisdist = Math.Sqrt(Math.Pow((double)Math.Abs(off1) + .5d, 2d) + Math.Pow((double)Math.Abs(off2) + .5d, 2));
                    if (thisdist > radius)
                    {
                        continue;
                    }
                    int pri  = (int)centArray[diraxis];
                    int sec1 = (int)centArray[secidx1] + off1;
                    int sec2 = (int)centArray[secidx2] + off2;
                    coord[diraxis] = pri;
                    coord[secidx1] = sec1;
                    coord[secidx2] = sec2;
                    map.SetBlockAt(coord[0], coord[1], coord[2], mat);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Create a tapered cylinder in blocklist.
        /// start and end are the beginning and ending coordinates of form [x,y,z].
        /// startsize and endsize are the beginning and ending radius.
        /// The material of the cylinder is 17, which indicates wood in Minecraft.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="startsize"></param>
        /// <param name="endsize"></param>
        public void taperedlimb(ref IMapHandler map, Vector3i vStart, Vector3i vEnd, int startsize, int endsize)
        {
            // delta is the coordinate vector for the difference between
            // start and end.
            Vector3i vDelta = vEnd - vStart;

            long[] delta = vDelta.ToArray();
            long[] start = vStart.ToArray();
            long[] end = vEnd.ToArray();

            // primidx is the index (0,1,or 2 for x,y,z) for the coordinate
            // which has the largest overall delta.
            long maxdist = 0;
            int primidx=0;
            for(int i = 0;i<3;i++)
            {
                if(Math.Abs(delta[i])>maxdist)
                {
                    maxdist=delta[i];
                    primidx=i;
                }
            }
            if(maxdist == 0)
                return;

            // secidx1 and secidx2 are the remaining indicies out of [0,1,2].
            int secidx1 = (primidx - 1)%3;
            int secidx2 = (1 + primidx)%3;
            // primsign is the digit 1 or -1 depending on whether the limb is headed
            // along the positive or negative primidx axis.
            long primsign = delta[primidx]/Math.Abs(delta[primidx]);
            // secdelta1 and ...2 are the amount the associated values change
            // for every step along the prime axis.
            long secdelta1 = delta[secidx1];
            double secfac1 = (double)(secdelta1)/delta[primidx];
            long secdelta2 = delta[secidx2];
            double secfac2 = (double)(secdelta2)/delta[primidx];
            // Initialize coord.  These values could be anything, since
            // they are overwritten.
            long[] coord = new long[]{0,0,0};
            // Loop through each crossection along the primary axis,
            // from start to end.
            long endoffset = delta[primidx] + primsign;
            for(long primoffset=0;primoffset<endoffset;primoffset+=primsign)//primoffset in range(0, endoffset, primsign):
            {
                long primloc = start[primidx] + primoffset;
                int secloc1 = (int)(start[secidx1] + primoffset*secfac1);
                int secloc2 = (int)(start[secidx2] + primoffset*secfac2);
                coord[primidx] = primloc;
                coord[secidx1] = secloc1;
                coord[secidx2] = secloc2;
                long primdist = Math.Abs(delta[primidx]);
                int radius = (int)(endsize + (startsize-endsize) * Math.Abs(delta[primidx] - primoffset) / primdist);
                crossection(ref map,new Vector3i(coord[0],coord[1],coord[2]),radius,primidx,17);
            }
        }
Example #3
0
        /// <summary>
        /// Create a tapered cylinder in blocklist.
        /// start and end are the beginning and ending coordinates of form [x,y,z].
        /// startsize and endsize are the beginning and ending radius.
        /// The material of the cylinder is 17, which indicates wood in Minecraft.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="startsize"></param>
        /// <param name="endsize"></param>
        public void taperedlimb(ref IMapHandler map, Vector3i vStart, Vector3i vEnd, int startsize, int endsize)
        {
            // delta is the coordinate vector for the difference between
            // start and end.
            Vector3i vDelta = vEnd - vStart;

            long[] delta = vDelta.ToArray();
            long[] start = vStart.ToArray();
            long[] end   = vEnd.ToArray();

            // primidx is the index (0,1,or 2 for x,y,z) for the coordinate
            // which has the largest overall delta.
            long maxdist = 0;
            int  primidx = 0;

            for (int i = 0; i < 3; i++)
            {
                if (Math.Abs(delta[i]) > maxdist)
                {
                    maxdist = delta[i];
                    primidx = i;
                }
            }
            if (maxdist == 0)
            {
                return;
            }

            // secidx1 and secidx2 are the remaining indicies out of [0,1,2].
            int secidx1 = (primidx - 1) % 3;
            int secidx2 = (1 + primidx) % 3;
            // primsign is the digit 1 or -1 depending on whether the limb is headed
            // along the positive or negative primidx axis.
            long primsign = delta[primidx] / Math.Abs(delta[primidx]);
            // secdelta1 and ...2 are the amount the associated values change
            // for every step along the prime axis.
            long   secdelta1 = delta[secidx1];
            double secfac1   = (double)(secdelta1) / delta[primidx];
            long   secdelta2 = delta[secidx2];
            double secfac2   = (double)(secdelta2) / delta[primidx];

            // Initialize coord.  These values could be anything, since
            // they are overwritten.
            long[] coord = new long[] { 0, 0, 0 };
            // Loop through each crossection along the primary axis,
            // from start to end.
            long endoffset = delta[primidx] + primsign;

            for (long primoffset = 0; primoffset < endoffset; primoffset += primsign)//primoffset in range(0, endoffset, primsign):
            {
                long primloc = start[primidx] + primoffset;
                int  secloc1 = (int)(start[secidx1] + primoffset * secfac1);
                int  secloc2 = (int)(start[secidx2] + primoffset * secfac2);
                coord[primidx] = primloc;
                coord[secidx1] = secloc1;
                coord[secidx2] = secloc2;
                long primdist = Math.Abs(delta[primidx]);
                int  radius   = (int)(endsize + (startsize - endsize) * Math.Abs(delta[primidx] - primoffset) / primdist);
                crossection(ref map, new Vector3i(coord[0], coord[1], coord[2]), radius, primidx, 17);
            }
        }
Example #4
0
 /// <summary>
 /// Create a round section of type matidx in blocklist.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="vCenter">the coordinates of the center block</param>
 /// <param name="radius">the radius of the section.</param>
 /// <param name="diraxis">The list index for the axis to make the section perpendicular to.  0 indicates the x axis, 1 the y, 2 the z.  The section will extend along the other two axies.</param>
 /// <param name="mat">What to make the section out of</param>
 public void crossection(ref IMapHandler map, Vector3i vCenter, double radius, int diraxis, byte mat)
 {
     long[] centArray=vCenter.ToArray();
     int rad = (int)(radius + .618d);
     int secidx1 = (diraxis - 1)%3;
     int secidx2 = (1 + diraxis)%3;
     int[] coord = new int []{0,0,0};
     for(int off1 =-rad; off1<rad+1;off1++)
     {
         for(int off2 =-rad; off2<rad+1;off2++)
         {
             double thisdist = Math.Sqrt(Math.Pow((double)Math.Abs(off1)+.5d,2d) + Math.Pow((double)Math.Abs(off2) + .5d,2));
             if(thisdist > radius)
                 continue;
             int pri = (int)centArray[diraxis];
             int sec1 = (int)centArray[secidx1] + off1;
             int sec2 = (int)centArray[secidx2] + off2;
             coord[diraxis] = pri;
             coord[secidx1] = sec1;
             coord[secidx2] = sec2;
             map.SetBlockAt(coord[0],coord[1],coord[2],mat);
         }
     }
 }