Пример #1
0
 public IEnumerable <double> GetVisibleXPoints()
 {
     for (var x = M.Ceiling(MinimalVisibleX); x <= M.Floor(MaximalVisibleX); x++)
     {
         yield return(x);
     }
 }
Пример #2
0
        protected void OnMeasurePage(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (!_needsMeasurePage)
            {
                return;
            }

            if (_matchWidthChildResId == 0)
            {
                _needsMeasurePage = true;
            }
            else if (this.ChildCount > 0)
            {
                var child = GetChildAt(0);
                child.Measure(widthMeasureSpec, heightMeasureSpec);
                var pageWidth = child.MeasuredWidth;
                var match     = child.FindViewById(_matchWidthChildResId);
                if (match is null)
                {
                    throw new NullPointerException(
                              "MatchWithChildResId did not find that ID in the first fragment of the ViewPager; "
                              + "is that view defined in the child view's layout? Note that MultiViewPager "
                              + "only measures the child for index 0.");
                }
                var childWidth = match.MeasuredWidth;
                if (childWidth > 0)
                {
                    _needsMeasurePage = false;
                    PageMargin        = childWidth - pageWidth;
                    var offScreen = (int)Math.Ceiling((float)pageWidth / childWidth) + 1;
                    OffscreenPageLimit = offScreen;
                    RequestLayout();
                }
            }
        }
Пример #3
0
        public static float LinearInterpolate(Vector2 position, MapData[,] map, ScalarFieldType fieldType)
        {
            float x  = position.X;
            float y  = position.Y;
            float x1 = (int)MathFunctions.Clamp((float)Math.Ceiling(x), 0, map.GetLength(0) - 2);
            float y1 = (int)MathFunctions.Clamp((float)Math.Ceiling(y), 0, map.GetLength(1) - 2);
            float x2 = (int)MathFunctions.Clamp((float)Math.Floor(x), 0, map.GetLength(0) - 2);
            float y2 = (int)MathFunctions.Clamp((float)Math.Floor(y), 0, map.GetLength(1) - 2);

            if (Math.Abs(x1 - x2) < 0.5f)
            {
                x1 = x1 + 1;
            }

            if (Math.Abs(y1 - y2) < 0.5f)
            {
                y1 = y1 + 1;
            }


            float q11 = map[(int)x1, (int)y1].GetValue(fieldType);
            float q12 = map[(int)x1, (int)y2].GetValue(fieldType);
            float q21 = map[(int)x2, (int)y1].GetValue(fieldType);
            float q22 = map[(int)x2, (int)y2].GetValue(fieldType);

            return(MathFunctions.LinearCombination(x, y, x1, y1, x2, y2, q11, q12, q21, q22));
        }
Пример #4
0
 public void ExecuteCommandShowCoords(IRP caller, string[] command)
 {
     if (caller is UP player)
     {
         CSteamID steamid = player.CSteamID;
         if (command.Length == 0)
         {
             dict.TryGetValue(steamid, out var value);
             if (value == 1)
             {
                 dict[steamid] = 0;
                 EffectManager.askEffectClearByID(56843, steamid);
                 UnturnedChat.Say(player, Translate("ShowCoords"), Color.green);
             }
             else
             {
                 dict[steamid] = 1;
                 var x = Math.Ceiling(player.Position.x).ToString();
                 var y = Math.Ceiling(player.Position.y).ToString();
                 var z = Math.Ceiling(player.Position.z).ToString();
                 EffectManager.sendUIEffect(56843, 3457, steamid, true, x, y, z);
                 UnturnedChat.Say(player, Translate("HideCoords"), Color.green);
             }
         }
         else
         {
             UnturnedChat.Say(player, Translate("Usage"), Color.red);
         }
     }
 }
Пример #5
0
        public void UpdateBarometer(float pressure)
        {
            if (_ledRainbowStrip == null)
            {
                return;
            }

            int[] clearColors = new int[_rainbow.Length];

            float t = (pressure - BarometerRangeLow) / (BarometerRangeHigh - BarometerRangeLow);
            int   n = (int)Math.Ceiling(_rainbow.Length * t);

            n = Math.Max(0, Math.Min(n, _rainbow.Length));
            int[] colors = new int[_rainbow.Length];
            for (int i = 0; i < n; i++)
            {
                int ri = _rainbow.Length - 1 - i;
                colors[ri] = _rainbow[ri];
            }
            try
            {
                _ledRainbowStrip.Write(clearColors);
                _ledRainbowStrip.Write(colors);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
        }
Пример #6
0
 public void Insert(T quadObject)
 {
     lock (syncLock)
     {
         if (sort & !objectSortOrder.ContainsKey(quadObject))
         {
             objectSortOrder.Add(quadObject, objectSortId++);
         }
         Box2 bounds = quadObject.GetBBox();
         if (root == null)
         {
             var rootSize = new Vector2(
                 SysMath.Ceiling(bounds.Width / minLeafSize.X),
                 SysMath.Ceiling(bounds.Height / minLeafSize.Y));
             double mul = SysMath.Max(rootSize.X, rootSize.Y);
             rootSize = new Vector2(minLeafSize.X, minLeafSize.Y) * mul;
             var center     = bounds.Min + new Vector2(bounds.Width, bounds.Height) / 2;
             var rootOrigin = center - rootSize / 2;
             root = new QuadNode(new Box2(rootOrigin, rootOrigin + rootSize));
         }
         while (!root.BBox.Contains(bounds))
         {
             ExpandRoot(bounds);
         }
         InsertNodeObject(root, quadObject);
     }
 }
Пример #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Popup.Init(this, savedInstanceState);
            Forms.Init(this, savedInstanceState);
            Platform.Init(this, savedInstanceState);
            FormsMaps.Init(this, savedInstanceState);

            Receiver = new LocationSettingsBroadcastsReceiver();

            AppCenter.Start("4b376e42-98b2-47fd-af73-7a84453954f9", typeof(Analytics), typeof(Crashes));

            var dm            = new DisplayMetrics();
            var windowManager = GetSystemService(WindowService).JavaCast <IWindowManager>();

            windowManager.DefaultDisplay.GetRealMetrics(dm);
            App.ScreenHeight  = (int)Math.Ceiling(dm.Ydpi);
            App.ScreenWidth   = (int)Math.Ceiling(dm.Xdpi);
            App.ScreenDensity = dm.Density;

            if (_app == null)
            {
                _app = new App();
            }

            LoadApplication(_app);
        }
Пример #8
0
 public IEnumerable <double> GetVisibleYPoints()
 {
     for (var y = M.Ceiling(MinimalVisibleY); y <= M.Floor(MaximalVisibleY); y++)
     {
         yield return(y);
     }
 }
        public CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
        {
            var quickSelectShortcut = (CalendarBaseQuickSelectShortcut)GetItemAt(indexPath);
            var title     = new NSString(quickSelectShortcut.Title);
            var titleSize = title.GetSizeUsingAttributes(titleAttributes);

            return(new CGSize(
                       Math.Ceiling(titleSize.Width) + horizontalPadding,
                       cellHeight
                       ));
        }
Пример #10
0
        internal static void CreateAudioTracks()
        {
            const int audioMemoryOS          = 1024 * 1024; // the audio client have only this amount of memory available for streaming (see: AudioFlinger::Client constructor -> https://android.googlesource.com/platform/frameworks/av/+/126a630/services/audioflinger/AudioFlinger.cpp : line 1153)
            const int memoryDealerHeaderSize = 64;          // size taken by the header of each memory section of the MemoryDealer.

            GetSetArrayRegionFunctionPointer();

            // the minimum size that can have an audio track in streaming mode (with that audio format)
            var minimumBufferSize = AudioTrack.GetMinBufferSize(SoundEffectInstanceFrameRate, ChannelOut.Stereo, Encoding.Pcm16bit);

            // the size that should be kept in order to be able to play sound music correctly (note: we need to be able to play 2 music simultaneously because destruction is asynchronous)
            var memoryNeededForSoundMusic = 2 * (GetUpperPowerOfTwo(minimumBufferSize) + memoryDealerHeaderSize);

            // the size taken by one of our sub-buffers => 2 bytes (16 bits sample) * 2 channels * 30 ms at 44100Hz
            var subBufferSize = Math.Max((int)Math.Ceiling(minimumBufferSize / (float)NumberOfSubBuffersInAudioTrack), 2 * 2 * 8000);

            // the memory taken by one audio track creation for sound effects
            var memoryNeededAudioTrack = GetUpperPowerOfTwo(subBufferSize * NumberOfSubBuffersInAudioTrack);

            // the java buffer used to copy blank sound data
            blankJavaDataBuffer = JNIEnv.NewGlobalRef(JNIEnv.NewArray(new byte[subBufferSize]));

            // create the pool of audio tracks
            var trackNumber = 0;

            while (trackNumber < MaximumNumberOfTracks && audioMemoryOS - (trackNumber + 1) * memoryNeededAudioTrack >= memoryNeededForSoundMusic)
            {
                // create the audio track
                var audioTrack = new AudioTrack(Stream.Music, SoundEffectInstanceFrameRate, ChannelOut.Stereo, Encoding.Pcm16bit,
                                                NumberOfSubBuffersInAudioTrack * subBufferSize, AudioTrackMode.Stream);

                if (audioTrack.State == AudioTrackState.Uninitialized) // the maximum number of tracks is reached
                {
                    break;
                }

                // create the c# buffer for internal copy
                var dataBuffer = new byte[subBufferSize];

                // create the java buffer
                var javaDataBuffer = JNIEnv.NewGlobalRef(JNIEnv.NewArray(dataBuffer));

                // add the new track to the audio track pool
                var newTrackInfo = new TrackInfo(audioTrack, javaDataBuffer, dataBuffer, subBufferSize)
                {
                    BuffersToWrite = NumberOfSubBuffersInAudioTrack
                };
                audioTrackPool.Enqueue(newTrackInfo);

                ++trackNumber;
            }
        }
Пример #11
0
        public static float PenalizeFood(Colony c, float percent)
        {
            var cost = (float)Math.Ceiling(c.Stockpile.TotalFood * percent);
            var num  = 0f;

            if (cost < 1)
            {
                cost = 1;
            }

            c.Stockpile.TryRemoveFood(ref num, cost);
            return(cost);
        }
Пример #12
0
        private Path[] GetPaths()
        {
            var path    = new Path();
            var altPath = new Path();

            var p0 = Point0;
            var p1 = Point1;

            var lineWidth  = p1.X - p0.X;
            var lineHeight = p1.Y - p0.Y;
            var lineLength = SMath.Sqrt(SMath.Pow(lineWidth, 2) + SMath.Pow(lineHeight, 2));
            var sin        = lineHeight / lineLength;
            var cos        = lineWidth / lineLength;

            var dashCount = (int)SMath.Ceiling(lineLength / (DashWidth + AltDashWidth));
            var point     = p0.Clone();

            for (var i = 0; i < dashCount; i++)
            {
                path.MoveTo(point.ToPointF());
                point.Translate(DashWidth * cos, DashWidth * sin);

                if (SMath.Abs(point.X - p0.X) <= SMath.Abs(lineWidth) && SMath.Abs(point.Y - p0.Y) <= SMath.Abs(lineHeight))
                {
                    path.LineTo(point.ToPointF());

                    altPath.MoveTo(point.ToPointF());
                    point.Translate(AltDashWidth * cos, AltDashWidth * sin);

                    if (SMath.Abs(point.X - p0.X) <= SMath.Abs(lineWidth) && SMath.Abs(point.Y - p0.Y) <= SMath.Abs(lineHeight))
                    {
                        altPath.LineTo(point.ToPointF());
                    }
                    else
                    {
                        altPath.LineTo(p1.ToPointF());
                    }
                }
                else
                {
                    path.LineTo(p1.ToPointF());
                }
            }

            return(new[] { path, altPath });
        }
Пример #13
0
        internal MeasureStringCache.Entry CreateMeasureStringCacheEntryCore(string text, Font font, SizeF area, StringFormat format)
        {
            var c = new MeasureStringCache.Entry(text, font, area, format);

            if (String.IsNullOrEmpty(text))
            {
                return(c);
            }

            var atts = buildAttributedString(text, font, format);

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                area = new SizeF(area.Height, area.Width);
            }

            float lineHeight = font.nativeFont.GetLineHeight();
            var   lines      = CreateLines(font, atts, area, format, lineHeight);

            foreach (var line in lines)
            {
                if (line != null)
                {
                    var lineWidth = (StringFormatFlags.FitBlackBox & format.FormatFlags) != 0
                                                ? line.GetBounds(CTLineBoundsOptions.UseOpticalBounds).Width
                                                : line.GetTypographicBounds(out _, out _, out _);
                    if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                    {
                        lineWidth += line.TrailingWhitespaceWidth;
                    }
                    c.measure.Width     = Math.Max(c.measure.Width, (float)NMath.Ceiling((float)lineWidth));
                    c.charactersFitted += (int)line.StringRange.Length;
                    line.Dispose();
                }
                c.measure.Height += lineHeight;
                c.linesFilled++;
            }

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                c.measure = new SizeF(c.measure.Height, c.measure.Width);
            }

            return(c);
        }
Пример #14
0
 public void AddSeconds(double sec)
 {
     week.Seconds += sec;
     if (sec < 0)
     {
         int weekNum = (int)Math.Ceiling(sec / Time.SecondsPerWeek);
         week.Weeks   -= weekNum;
         Week.Seconds += weekNum * Time.SecondsPerWeek;
         Week          = Week;
     }
     else
     {
         int weekNum = (int)Math.Floor(sec / Time.SecondsPerWeek);
         week.Weeks   += weekNum;
         Week.Seconds -= weekNum * Time.SecondsPerWeek;
         Week          = Week;
     }
 }
Пример #15
0
        internal MeasureStringCache.Entry CreateMeasureStringCacheEntry(string text, Font font, SizeF area, StringFormat format)
        {
            var c = new MeasureStringCache.Entry(text, font, area, format);

            if (String.IsNullOrEmpty(text))
            {
                return(c);
            }

            var atts = buildAttributedString(text, font, format);

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                area = new SizeF(area.Height, area.Width);
            }

            float lineHeight = (float)NMath.Ceiling(font.nativeFont.AscentMetric + font.nativeFont.DescentMetric + font.nativeFont.LeadingMetric + 1);
            var   lines      = CreateLines(font, atts, area, format, lineHeight);

            foreach (var line in lines)
            {
                if (line != null)
                {
                    nfloat ascent, descent, leading;
                    var    lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);
                    if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                    {
                        lineWidth += line.TrailingWhitespaceWidth;
                    }
                    c.measure.Width     = Math.Max(c.measure.Width, (float)NMath.Ceiling((float)lineWidth));
                    c.charactersFitted += (int)line.StringRange.Length;
                    line.Dispose();
                }
                c.measure.Height += lineHeight;
                c.linesFilled++;
            }

            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                c.measure = new SizeF(c.measure.Height, c.measure.Width);
            }

            return(c);
        }
Пример #16
0
        public void NSortedList_Size_Test()
        {
            var sorted = new NSortedList <int>();

            int length = Math.Probability.Sampling.GetUniform(10, 1024);

            var dict = new Dictionary <int, int>();

            for (int i = 0; i < length; i++)
            {
                int val = Math.Probability.Sampling.GetUniform(0, length - 1);
                sorted.Add(val);

                dict[val] = (dict.ContainsKey(val) ? dict[val] + 1 : 1);
            }

            int remove = (int)MATH.Ceiling(length / 2.0);

            for (int i = 0; i < remove; i++)
            {
                int val = Math.Probability.Sampling.GetUniform(0, sorted.Count - 1);

                if (dict.ContainsKey(val))
                {
                    sorted.Remove(val);

                    dict[val] = 0;

                    Assert.False(sorted.Contains(val));
                }
            }

            var contains = (dict.Where(w => w.Value == 0 && sorted.Contains(w.Key)));

            bool result = (contains.Count() == 0);

            Assert.True(result, "Length was not equal to the elements in the collection");

            bool lresult = (sorted.Select(s => s).Count() == sorted.Count);

            Assert.True(lresult, "Enumerator extends beyond number of accessible items in collection");
        }
Пример #17
0
 void FixedUpdate()
 {
     if ((DateTime.Now - c).TotalSeconds >= 0.5)
     {
         var untplayer = UP.FromPlayer(player);
         var steamid   = untplayer.CSteamID;
         if (Pos != lastPos)
         {
             dict.TryGetValue(steamid, out var value);
             lastPos = Pos;
             var x = Math.Ceiling(untplayer.Position.x).ToString();
             var y = Math.Ceiling(untplayer.Position.y).ToString();
             var z = Math.Ceiling(untplayer.Position.z).ToString();
             if (value == 1)
             {
                 EffectManager.sendUIEffect(56843, 3457, steamid, true, x, y, z);
             }
         }
     }
 }
Пример #18
0
        public void AddMinesToTheBoard()
        {
            var min       = (int)Math.Ceiling(Width * Height * 0.2);
            var max       = (int)Math.Floor(Width * Height * 0.6);
            var mineCount = random.Next(min, max);

            RemainingMineCount = mineCount;

            while (mineCount > 0)
            {
                var row    = random.Next(0, Width - 1);
                var column = random.Next(0, Height - 1);

                if (Board[row, column].State == State.Mine)
                {
                    continue;
                }

                Board[row, column].State = State.Mine;
                mineCount--;

                for (var i = 0; i < 8; i++)
                {
                    int xDir = Helper.Directions[i, 0];
                    int yDir = Helper.Directions[i, 1];

                    if (Helper.CellIsOutOfTheBoardRange(xDir, yDir, row, column, Width, Height))
                    {
                        continue;
                    }

                    if (Board[row + yDir, column + xDir].State == State.MinesAround ||
                        Board[row + yDir, column + xDir].State == State.Empty)
                    {
                        Board[row + yDir, column + xDir].State = State.MinesAround;
                        Board[row + yDir, column + xDir].MinesAround++;
                    }
                }
            }
        }
Пример #19
0
        public void NSortedList_Sort_Test()
        {
            for (int run = 0; run < 2; run++)
            {
                bool reverse = (run != 0);

                var sorted = new NSortedList <int>(-1, reverse);

                int length = Math.Probability.Sampling.GetUniform(10, 1024);

                for (int i = 0; i < length; i++)
                {
                    int val = Math.Probability.Sampling.GetUniform(0, length - 1);
                    sorted.Add(val);
                }

                int remove = (int)MATH.Ceiling(length / 2.0);
                for (int i = 0; i < remove; i++)
                {
                    int index = Math.Probability.Sampling.GetUniform(0, sorted.Count - 1);
                    sorted.Remove(index);
                }

                bool result = false;
                for (int i = 1; i < (length - remove); i++)
                {
                    if (reverse)
                    {
                        result = sorted[i - 1] >= sorted[i];
                        Assert.True(result, $"Item at {i - 1} was larger than expected");
                    }
                    else
                    {
                        result = sorted[i - 1] <= sorted[i];
                        Assert.True(result, $"Item at {i - 1} was smaller than expected");
                    }
                }
            }
        }
Пример #20
0
        internal Rectangle GetImageRectangle(float dpi)
        {
            var rect   = Rectangle.ToRectangleF();
            var mul    = dpi / 72f;
            var values = new[] { rect.X *mul, rect.Y *mul, rect.Width *mul, rect.Height *mul };

            // BUG 0015690
            for (int i = 0; i < values.Length; i++)
            {
                var v = SMath.Round(values[i]);
                if (SMath.Abs(v - values[i]) < 0.01f)
                {
                    values[i] = (float)v;
                }
            }

            int x      = (int)SMath.Floor(values[0]);
            int y      = (int)SMath.Floor(values[1]);
            int width  = (int)SMath.Ceiling(values[2]);
            int height = (int)SMath.Ceiling(values[3]);

            return(new Rectangle(x, y, width, height));
        }
Пример #21
0
 public static float Ceiling(float c)
 {
     return((float)XMath.Ceiling(c));
 }
Пример #22
0
        internal DrawStringCache.Entry CreateCacheEntry(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
        {
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }
            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            layoutRectangle.Location = PointF.Empty;
            var c = new DrawStringCache.Entry(s, font, brush, layoutRectangle, format);

            brush.Setup(this, false);             // Stroke
            var attributedString = buildAttributedString(s, font, format, lastBrushColor);

            // Work out the geometry
            c.layoutAvailable = true;
            var insetBounds = layoutRectangle;

            if (insetBounds.Size == SizeF.Empty)
            {
                insetBounds.Width  = float.MaxValue;
                insetBounds.Height = float.MaxValue;
                c.layoutAvailable  = false;
            }

            c.lineHeight     = font.nativeFont.GetLineHeight();
            c.lines          = new List <CTLine>();
            c.verticalMatrix = default(CGAffineTransform);

            // Calculate the lines
            // If we are drawing vertical direction then we need to rotate our context transform by 90 degrees
            if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                // Swap out the width and height and calculate the lines
                c.lines        = CreateLines(font, attributedString, new SizeF(insetBounds.Height, insetBounds.Width), format, c.lineHeight);
                c.boundsWidth  = insetBounds.Height;
                c.boundsHeight = insetBounds.Width;
            }
            else
            {
                c.lines        = CreateLines(font, attributedString, insetBounds.Size, format, c.lineHeight);
                c.boundsWidth  = insetBounds.Width;
                c.boundsHeight = insetBounds.Height;
            }

            c.textPosition = new PointF(insetBounds.X + .5f, insetBounds.Y + .5f);
            if (c.layoutAvailable)
            {
                if (format.LineAlignment == StringAlignment.Far)
                {
                    c.textPosition.Y += c.boundsHeight - (c.lines.Count * c.lineHeight);
                }
                else if (format.LineAlignment == StringAlignment.Center)
                {
                    c.textPosition.Y += (c.boundsHeight - (c.lines.Count * c.lineHeight)) / 2;
                }
            }
            else
            {
                // Precalculate maximum width to allow for aligning lines
                if (format.Alignment != StringAlignment.Near)
                {
                    float maxLineWidth = 0;
                    foreach (var line in c.lines)
                    {
                        if (line != null)
                        {
                            nfloat ascent, descent, leading;
                            var    lineWidth = line.GetTypographicBounds(out ascent, out descent, out leading);
                            if ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
                            {
                                lineWidth += line.TrailingWhitespaceWidth;
                            }
                            maxLineWidth = Math.Max(maxLineWidth, (float)NMath.Ceiling((float)lineWidth));
                        }
                    }
                    c.boundsWidth = maxLineWidth;
                }
                if (format.LineAlignment == StringAlignment.Far)
                {
                    c.textPosition.Y -= c.lineHeight * c.lines.Count;
                }
                else if (format.LineAlignment == StringAlignment.Center)
                {
                    c.textPosition.Y -= (c.lineHeight * c.lines.Count) / 2;
                }
            }
            return(c);
        }
 public static int CeilToInt(double d)
 => (int)Math.Ceiling(d);
 public static double Ceil(double d)
 => Math.Ceiling(d);
Пример #25
0
 public static Half Ceiling(Half x) =>
 (Half)M.Ceiling(x);
Пример #26
0
        public static List <Vector3Int> MakeCylinder(Vector3Int pos, double radiusX, double radiusZ, int height, bool filled)
        {
            List <Vector3Int> affected = new List <Vector3Int>();

            radiusX += 0.5;
            radiusZ += 0.5;

            if (height == 0)
            {
                return(affected);
            }
            else if (height < 0)
            {
                height = -height;
                pos    = pos - new Vector3Int(0, height, 0);
            }

            double invRadiusX = 1 / radiusX;
            double invRadiusZ = 1 / radiusZ;

            int ceilRadiusX = (int)Math.Ceiling(radiusX);
            int ceilRadiusZ = (int)Math.Ceiling(radiusZ);

            double nextXn = 0;

            for (int x = 0; x <= ceilRadiusX; x++)
            {
                double xn = nextXn;
                nextXn = (x + 1) * invRadiusX;
                double nextZn = 0;
                for (int z = 0; z <= ceilRadiusZ; z++)
                {
                    double zn = nextZn;
                    nextZn = (z + 1) * invRadiusZ;

                    double distanceSq = LengthSq(xn, zn);
                    if (distanceSq > 1)
                    {
                        if (z == 0)
                        {
                            goto forX;
                        }
                        goto forZ;
                    }

                    if (!filled)
                    {
                        if (LengthSq(nextXn, zn) <= 1 && LengthSq(xn, nextZn) <= 1)
                        {
                            continue;
                        }
                    }

                    for (int y = 0; y < height; y++)
                    {
                        affected.Add(new Vector3Int(x, y, z) + pos);
                        affected.Add(new Vector3Int(-x, y, z) + pos);
                        affected.Add(new Vector3Int(x, y, -z) + pos);
                        affected.Add(new Vector3Int(-x, y, -z) + pos);
                    }
                }
forZ:
                { }
            }
forX:
            { }

            return(affected);
        }
Пример #27
0
        public static List <Vector3Int> MakeSphere(Vector3Int pos, double radiusX, double radiusY, double radiusZ, bool filled)
        {
            List <Vector3Int> affected = new List <Vector3Int>();

            radiusX += 0.5;
            radiusY += 0.5;
            radiusZ += 0.5;

            double invRadiusX = 1 / radiusX;
            double invRadiusY = 1 / radiusY;
            double invRadiusZ = 1 / radiusZ;

            int ceilRadiusX = (int)Math.Ceiling(radiusX);
            int ceilRadiusY = (int)Math.Ceiling(radiusY);
            int ceilRadiusZ = (int)Math.Ceiling(radiusZ);

            double nextXn = 0;

            for (int x = 0; x <= ceilRadiusX; x++)
            {
                double xn = nextXn;
                nextXn = (x + 1) * invRadiusX;
                double nextYn = 0;

                for (int y = 0; y <= ceilRadiusY; y++)
                {
                    double yn = nextYn;
                    nextYn = (y + 1) * invRadiusY;
                    double nextZn = 0;

                    for (int z = 0; z <= ceilRadiusZ; z++)
                    {
                        double zn = nextZn;
                        nextZn = (z + 1) * invRadiusZ;

                        double distanceSq = LengthSq(xn, yn, zn);
                        if (distanceSq > 1)
                        {
                            if (z == 0)
                            {
                                if (y == 0)
                                {
                                    goto forX;
                                }
                                goto forY;
                            }
                            goto forZ;
                        }

                        if (!filled)
                        {
                            if (LengthSq(nextXn, yn, zn) <= 1 && LengthSq(xn, nextYn, zn) <= 1 && LengthSq(xn, yn, nextZn) <= 1)
                            {
                                continue;
                            }
                        }

                        affected.Add(new Vector3Int(x, y, z) + pos);
                        affected.Add(new Vector3Int(-x, y, z) + pos);
                        affected.Add(new Vector3Int(x, -y, z) + pos);
                        affected.Add(new Vector3Int(x, y, -z) + pos);
                        affected.Add(new Vector3Int(-x, -y, z) + pos);
                        affected.Add(new Vector3Int(x, -y, -z) + pos);
                        affected.Add(new Vector3Int(-x, y, -z) + pos);
                        affected.Add(new Vector3Int(-x, -y, -z) + pos);
                    }
forZ:
                    { }
                }
forY:
                { }
            }
forX:
            { }

            return(affected);
        }
Пример #28
0
 public static long Ceiling(double value)
 {
     return((long)CSMath.Ceiling(value));
 }
Пример #29
0
        /// <summary>
        /// add a grid
        /// </summary>
        private void AddGrid()
        {
            if (NumberOfGrids == 1)
            {
                B_Add.Visibility = ViewStates.Gone;
            }

            //get first or second grid accordingly
            int index = (int)Math.Ceiling((decimal)NumberOfGrids / 2) - 1;

            if (_CellularAutomata == null)
            {
                InitiateCellularAutomata();
            }

            bool[,] newGrid = (bool[, ])CellValues[0].Clone();
            CellValues.Add(newGrid);
            _CellularAutomata.Add(new CellularAutomata <LangtonsAnt>(
                                      new CircularArray2D <bool>((bool[, ])newGrid.Clone()))
            {
                Iterations = _CellularAutomata[0].Iterations
            });

            LayoutParams layoutParams = GridLayouts[0].LayoutParameters;

            //shrink cells
            CellMagnitude /= 2;

            if (GridWiderThanScreen)
            //grid is wider than screen
            //stack grids atop eachother
            {
                GridPixelHeight /= 2;

                layoutParams.Width  = Resolution.X / 2;
                layoutParams.Height = GridPixelHeight;

                GridY = (Resolution.Y - GridPixelHeight) / 2;

                GridLayouts[0].SetY(GridY);
                GridLayouts[0].LayoutParameters = layoutParams;

                layoutParams = GridLayouts[NumberOfGrids].LayoutParameters;
                GridLayouts[NumberOfGrids].SetX(Resolution.X / 2);
                GridLayouts[NumberOfGrids].SetY(GridY);
                layoutParams.Width  = Resolution.X / 2;
                layoutParams.Height = GridPixelHeight;
                GridLayouts[NumberOfGrids].LayoutParameters = layoutParams;
            }
            else
            //grid is thinner than screen
            //stack grids beside eachother
            {
                GridPixelWidth /= 2;

                layoutParams.Width  = GridPixelWidth;
                layoutParams.Height = Resolution.Y / 2;

                GridX = (Resolution.X - GridPixelWidth) / 2;

                GridLayouts[0].SetX(GridX * 2);
                GridLayouts[0].LayoutParameters = layoutParams;

                layoutParams = GridLayouts[NumberOfGrids].LayoutParameters;
                GridLayouts[NumberOfGrids].SetX(GridX);
                GridLayouts[NumberOfGrids].SetY(Resolution.Y / 2);
                layoutParams.Width  = GridPixelWidth;
                layoutParams.Height = Resolution.Y / 2;
                GridLayouts[NumberOfGrids].LayoutParameters = layoutParams;
            }


            NumberOfGrids++;


            //draw grid
            for (int z = 0; z < NumberOfGrids; z++)
            {
                GridLayouts[z].RemoveAllViews();
                LayoutParams gridCellLayoutParams = new LayoutParams(CellMagnitude, CellMagnitude);
                Console.WriteLine("{0}: X: {1}, width: {2}. Y: {3}, height: {4}", z, GridLayouts[z].GetX(), layoutParams.Width, GridLayouts[z].GetY(), layoutParams.Height);
                for (int yCell = 0; yCell < Height; yCell++)
                {
                    for (int xCell = 0; xCell < Width; xCell++)
                    {
                        //define cell
                        ImageView cell = new ImageView(this);
                        if (CellValues[z][xCell, yCell])
                        {
                            cell.SetTag(Resource.String.cellOn, true);
                            cell.SetImageBitmap(ActiveCellBitmap);
                        }
                        else
                        {
                            cell.SetTag(Resource.String.cellOn, null);
                            cell.SetImageBitmap(InactiveCellBitmap);
                        }
                        cell.SetTag(Resource.String.cellX, xCell);
                        cell.SetTag(Resource.String.cellY, yCell);
                        cell.SetTag(Resource.String.cellZ, z);
                        cell.Touch           += new EventHandler <TouchEventArgs>(ToggleCell);
                        cell.LayoutParameters = gridCellLayoutParams;
                        GridLayouts[z].AddView(cell);
                    }
                }

                GridLayouts[z].Visibility = ViewStates.Visible;

                //define column count
                GridLayouts[z].ColumnCount = Width;
            }
        }
Пример #30
0
 /// <summary>
 ///     Returns the first integer greater than the number
 /// </summary>
 /// <param name="number">Number to round up.</param>
 /// <returns name="integer">First integer greater than the number.</returns>
 /// <search>ceiling,round</search>
 public static long Ceiling(double number)
 {
     return((long)CSMath.Ceiling(number));
 }