예제 #1
0
        /**
         *      Gives a new point that represents the
         *      reminder when the first point is divided
         *      by the second point	component-wise. The
         *      division is integer division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public PointyHexPoint Mod(PointyHexPoint otherPoint)
        {
            var x = Mathi.Mod(X, otherPoint.X);
            var y = Mathi.Mod(Y, otherPoint.Y);

            return(new PointyHexPoint(x, y));
        }
예제 #2
0
    public static float[,] average(float[,] grid, int radius, float strength)
    {
        float f = Mathf.Clamp01(strength);
        float p = 1f / (float)((2 * radius + 1) * (2 * radius + 1));
        float a = 0f;

        float[,] g = new float[grid.GetLength(0), grid.GetLength(1)];

        for (int x = 0; x < grid.GetLength(0); ++x)
        {
            for (int y = 0; y < grid.GetLength(1); ++y)
            {
                a = 0f;
                for (int xx = -radius; xx <= radius; ++xx)
                {
                    for (int yy = -radius; yy <= radius; ++yy)
                    {
                        int px = Mathi.Clamp(xx + x, 0, grid.GetLength(0) - 1);
                        int py = Mathi.Clamp(yy + y, 0, grid.GetLength(1) - 1);

                        a += grid[px, py] * p;
                    }
                }
                g[x, y] = (1.0f - f) * grid[x, y] + f * a;
            }
        }
        return(g);
    }
예제 #3
0
        public DiamondShapeInfo <TCell> FatRectangle(int width, int height)
        {
            int diamondSize       = width + Mathi.Div(height, 2);
            var storageBottomLeft = new DiamondPoint(0, 1 - width);

            return(Shape(diamondSize, diamondSize, p => IsInsideFatRectangle(p, width, height), storageBottomLeft));
        }
예제 #4
0
        public PointyHexShapeInfo <TCell> ThinRectangle(int width, int height)
        {
            int storageWidth      = width + Mathi.Div(height - 1, 2);
            int storageHeight     = height;
            var storageBottomLeft = new PointyHexPoint(-Mathi.Div(height - 1, 2), 0);

            return(Shape(storageWidth, storageHeight, x => IsInsideThinRectangle(x, width, height), storageBottomLeft));
        }
예제 #5
0
        public FlatHexShapeInfo <TCell> ThinRectangle(int width, int height)
        {
            var storageWidth      = width;
            var storageHeight     = height + Mathi.Div(width - 1, 2);
            var storageBottomLeft = new FlatHexPoint(0, -Mathi.Div(width - 1, 2));

            return(Shape(storageWidth, storageHeight, x => IsInsideThinRectangle(x, width, height), storageBottomLeft));
        }
예제 #6
0
        public DiamondShapeInfo <TCell> Rectangle(int width, int height)
        {
            //Note: this fit is not the tightest possible.
            int diamondSize = width + Mathi.Div(height, 2);

            var storageBottomLeft = new DiamondPoint(0, 1 - width);

            return(Shape(diamondSize, diamondSize, p => IsInsideRaggedRectangle(p, width, height), storageBottomLeft));
        }
예제 #7
0
파일: Program.cs 프로젝트: titi20117/DotNet
        static void Main(string[] args)
        {
            Console.Write("Введите число N : ");
            string num = Console.ReadLine();

            Console.WriteLine("Factorail {0} = {1}", Int32.Parse(num), Mathi.Factorial(Int32.Parse(num)));
            Console.WriteLine("Math pow n^4 = {0}", Mathi.Power(Int32.Parse(num), 4));
            Console.ReadKey();
        }
예제 #8
0
    public Vector3Int getGridPosition(Vector3 worldPosition)
    {
        Vector3    localPosition = transform.worldToLocalMatrix * worldPosition;
        Vector3Int gridPosition  = new Vector3Int((int)localPosition.x, (int)localPosition.y, (int)localPosition.z);

        gridPosition.x = Mathi.Clamp(gridPosition.x, 0, Width - 1);
        gridPosition.y = Mathi.Clamp(gridPosition.y, 0, Height - 1);
        return(gridPosition);
    }
예제 #9
0
        private static bool IsInsideFatRectangle(PointyHexPoint point, int width, int height)
        {
            int startX = -(Mathi.Div(point.Y, 2));

            return
                (point.X >= startX - Mathi.Mod(point.Y, 2) &&
                 point.X < startX + width &&
                 point.Y >= 0 &&
                 point.Y < height);
        }
예제 #10
0
        private static bool IsInsideFatRectangle(FlatHexPoint point, int width, int height)
        {
            int startY = -(Mathi.Div(point.X, 2));

            return
                (point.Y >= startY - Mathi.Mod(point.X, 2) &&
                 point.Y < startY + height &&
                 point.X >= 0 &&
                 point.X < width);
        }
예제 #11
0
        private bool IsInsideThinRectangle(FlatHexPoint point, int width, int height)
        {
            int startY = -(Mathi.Div(point.X, 2));

            return
                (point.Y >= startY &&
                 point.Y + Mathi.Mod(point.X, 2) < startY + height &&
                 point.X >= 0 &&
                 point.X < width);
        }
예제 #12
0
        public StoredResource Buy(StoredResource goods, int price)
        {
            goods.Amount = (float)Mathi.Clamp((int)goods.Amount, 0, Cash / price);
            Cash        -= (int)goods.Amount * price;

            Debug.Log(name + " buying for " + ((int)goods.Amount * price) + " -> Cash " + Cash);

            _stock.Add(goods);
            return(goods);
        }
예제 #13
0
    public static int GetColor3(this RectPoint point)
    {
        int color = point.GetColor1_2();

        if (Mathi.Mod(point.X, 2) == 0)
        {
            color += 2;
        }

        return(color);
    }
예제 #14
0
        private static bool IsInsideThinRectangle(DiamondPoint point, int width, int height)
        {
            int x = Mathi.Div(point.X - point.Y, 2);
            int y = point.X + point.Y;

            return
                (x >= 0 &&
                 x < width - Mathi.Mod(y, 2) &&
                 y >= 0 &&
                 y < height);
        }
예제 #15
0
    public void Start()
    {
        var grid = LineGrid <int>
                   .BeginShape()
                   .Segment(10)
                   .EndShape();

        var map = new ArchimedeanSpiralMap(CellDimensions, grid);

        var voronoiMap = new VoronoiMap <LinePoint>(grid, map);

        ExampleUtils.PaintScreenTexture(plane, voronoiMap, n => Mathi.Mod(n, 12));
    }
예제 #16
0
        public StoredResource Lookup(string goodsName, float amount)
        {
            StoredResource returnGoods;

            returnGoods.Description = _economyManager.GetResource(goodsName);
            returnGoods.Amount      = 0f;
            returnGoods.Price       = 0;
            returnGoods.PriceSale   = 0;

            StoredResource stored;

            if (_stock.TryGetValue(goodsName, out stored))
            {
                returnGoods.Price     = stored.Price;
                returnGoods.PriceSale = stored.PriceSale;
                returnGoods.Amount    = (float)Mathi.Min((int)amount, (int)stored.Amount);
            }
            return(returnGoods);
        }
예제 #17
0
    int GetMax(int[,] grid)
    {
        if (grid.GetLength(0) != columns || grid.GetLength(1) != rows)
        {
            return(-1);
        }

        int max = 0;

        for (int y = 0; y < rows; ++y)
        {
            for (int x = 0; x < columns; ++x)
            {
                max = Mathi.Max(grid[x, y], max);
            }
        }

        return(max);
    }
예제 #18
0
        /**
         *      Gives a coloring of the grid such that
         *      if a point p has color k, then all points
         *      p + m[ux, 0] + n[vx, vy] have the same color
         *      for any integers a and b.
         *
         *      More information anout grid colorings:
         *      http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/
         *
         *      @since 1.7
         */
        public int GetColor(int ux, int vx, int vy)
        {
            int colorCount = ux * vy;

            float a = (x * vy - y * vx) / (float)colorCount;
            float b = (y * ux) / (float)colorCount;

            int m = Mathi.FloorToInt(a);
            int n = Mathi.FloorToInt(b);

            int baseVectorX = m * ux + n * vx;
            int baseVectorY = n * vy;

            int offsetX = Mathi.Mod(X - baseVectorX, ux);
            int offsetY = Y - baseVectorY;

            int colorIndex = Mathi.FloorToInt(offsetX + offsetY * ux);

            return(colorIndex);
        }
예제 #19
0
        public StoredResource Retrieve(string goodsName, float amount)
        {
            StoredResource returnGoods;

            returnGoods.Description = _economyManager.GetResource(goodsName);
            returnGoods.Amount      = 0;
            returnGoods.Price       = 0;
            returnGoods.PriceSale   = 0;

            StoredResource stored;

            if (_stock.TryGetValue(goodsName, out stored))
            {
                returnGoods.Price     = stored.Price;
                returnGoods.PriceSale = stored.PriceSale;
                returnGoods.Amount    = (float)Mathi.Min((int)amount, (int)stored.Amount);
                stored.Amount        -= returnGoods.Amount;
                stored.Price          = (int)(1f / stored.Description.Probability - 0.01f * (float)stored.Amount);
                _stock[goodsName]     = stored;
            }
            return(returnGoods);
        }
예제 #20
0
        public void InitDemand(float scale)
        {
            _economyManager   = GameObject.Find("Universe").GetComponent <EconomyManager>();
            _maxGoods         = _economyManager.MaxGoods;
            _stock            = GetComponent <Stock>();
            _demand           = new Dictionary <string, Demand>();
            _scale            = scale;
            _numDemandedGoods = Mathi.Clamp((int)(UnityEngine.Random.value * scale), 2, _maxGoods);

            for (int i = 0; i < _numDemandedGoods; ++i)
            {
                Resource desc = _economyManager.GetRandomResource();
                Demand   demand;
                demand.Description = desc;
                demand.Consumed    = (_scale * UnityEngine.Random.value * desc.Probability);

                if (!_demand.ContainsKey(demand.Description.ID))
                {
                    _demand.Add(demand.Description.ID, demand);
                }
            }
        }
예제 #21
0
        private void Window_Changed()
        {
            matrix.UpdateProjection(Window.ProjectionSize);
            matrix.CalculateMVP();

            if (2 * Window.Ratio / DRAW_WIDTH != VertexSize)
            {
                VertexSize    = 2 * Window.Ratio / DRAW_WIDTH;
                DrawSize      = new Size(DRAW_WIDTH + 2, Mathi.Ceil(DRAW_WIDTH / Window.Ratio + 1));
                drawThreshold = new Vector2(DrawSize.Width / 2f, DrawSize.Height / 2f);

                mainBuffer?.Dispose();
                mainTextureBuffer = new CachedGPUBuffer(2, DrawSize.Area * 2, BufferPrimitiveType.Quad);
                mainBuffer        = new BufferBatch(new IndexBuffer(DrawSize.Area * 2), new GPUBuffer(2, DrawSize.Area * 2, BufferPrimitiveType.Quad, GenerateMainVerticies()), mainTextureBuffer);

                foregroundBuffer?.Dispose();
                foregroundTextureBuffer = new CachedGPUBuffer(2, DrawSize.Area, BufferPrimitiveType.Quad);
                foregroundBuffer        = new BufferBatch(new IndexBuffer(DrawSize.Area), new GPUBuffer(2, DrawSize.Area, BufferPrimitiveType.Quad, GenerateForegroundVerticies()), foregroundTextureBuffer);

                UpdateTextureBuffer();
            }
        }
예제 #22
0
        /**
         *      Gives a coloring of the grid such that
         *      if a point p has color k, then all points
         *      p + m[ux, 0] + n[vx, vy] have the same color
         *      for any integers a and b.
         *
         *      More information anout grid colorings:
         *      http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/
         *
         *      @since 1.7
         */
        public int __GetColor__ReferenceImplementation(int ux, int vx, int vy)
        {
            var u = new DiamondPoint(ux, 0);
            var v = new DiamondPoint(vx, vy);

            int colorCount = u.PerpDot(v);

            float a = PerpDot(v) / (float)colorCount;
            float b = -PerpDot(u) / (float)colorCount;

            int m = Mathi.FloorToInt(a);
            int n = Mathi.FloorToInt(b);

            int baseVectorX = m * u.X + n * v.X;
            int baseVectorY = n * u.Y + n * v.Y;

            int offsetX = Mathi.Mod(X - baseVectorX, ux);
            int offsetY = Y - baseVectorY;

            int colorIndex = Mathi.FloorToInt(offsetX + offsetY * ux);

            return(colorIndex);
        }
예제 #23
0
 public DiamondPoint Wrap(DiamondPoint point)
 {
     return(new DiamondPoint(point.X, Mathi.Mod(point.Y, height)));
 }
예제 #24
0
 public DiamondPoint Wrap(DiamondPoint point)
 {
     return(new DiamondPoint(Mathi.Mod(point.X, width), point.Y));
 }
예제 #25
0
 public DiamondPoint ScaleDown(int r)
 {
     return(new DiamondPoint(Mathi.Div(x, r), Mathi.Div(y, r)));
 }
예제 #26
0
 public RectPoint Wrap(RectPoint point)
 {
     return(new RectPoint(point.X, Mathi.Mod(point.Y, height)));
 }
예제 #27
0
 public RectPoint Wrap(RectPoint point)
 {
     return(new RectPoint(Mathi.Mod(point.X, width), point.Y));
 }
예제 #28
0
 public FlatHexPoint Wrap(FlatHexPoint point)
 {
     return(new FlatHexPoint(point.X, Mathi.Mod(point.Y, height)));
 }
예제 #29
0
 public FlatHexPoint Wrap(FlatHexPoint point)
 {
     return(new FlatHexPoint(Mathi.Mod(point.X, width), point.Y));
 }
예제 #30
0
 public FlatHexPoint ScaleDown(int r)
 {
     return(new FlatHexPoint(Mathi.Div(x, r), Mathi.Div(y, r)));
 }