public CommandContext(Command interpretedcommand, CommandSearchResult commandSearch, string argSection, IndexArray <string> args)
 {
     InterpretedCommand = interpretedcommand;
     CommandSearch      = commandSearch;
     ArgumentSection    = argSection;
     Arguments          = args;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public Mesh(IEnumerable <Point3d> vertices,
                    IEnumerable <Pointd> uvs,
                    IEnumerable <int> indices)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException("vertices");
            }

            if (indices == null)
            {
                throw new ArgumentNullException("indexes");
            }

            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

            VertexArray    = vertices.ToArray();
            IndexArray     = indices.ToArray();
            TextureUVArray = uvs.ToArray();

            if (VertexArray.Count() != TextureUVArray.Count())
            {
                throw new ArgumentException(
                          "頂点配列とテクスチャUV配列の数が一致しません。");
            }

            if (IndexArray.Count() % 3 != 0)
            {
                throw new ArgumentException(
                          "インデックス配列は三角形による指定をお願いします。");
            }
        }
        public GridSystem(Room room, int cellsX, Vector2 position, int? GridWidth = null, int? GridHeight = null)
        {
            linesToDraw = new List<Rectangle>();
            this.position = position;
            this.room = room;

            this.gridWidth = GridWidth ?? room.worldWidth;
            this.gridHeight = GridHeight ?? room.worldHeight;
            this.cellsX = cellsX;

            //this.cellReach = cellReach;
            cellWidth = (int)Math.Ceiling((double)gridWidth / (double)cellsX);
            cellHeight = cellWidth;
            this.cellsY = (gridHeight - 1)/ cellHeight + 1;
            //cellheight = gridheight / cellsY;
            grid = new List<Collider>[cellsX, cellsY];
            for (int i = 0; i < cellsX; i++)
            {
                for (int j = 0; j < cellsY; j++)
                {
                    grid[i, j] = new List<Collider>();
                }
            }

            //
            arrayGrid = new IndexArray<Collider>[cellsX][];
            for(int i = 0; i < cellsX; i++)
            {
                arrayGrid[i] = new IndexArray<Collider>[cellsY];
                for(int j = 0; j < cellsY; j++)
                {
                    arrayGrid[i][j] = new IndexArray<Collider>(100);
                }
            }
            bucketBags = new IndexArray<IndexArray<Collider>>[cellsX][];
            for (int i = 0; i < cellsX; i++)
            {
                bucketBags[i] = new IndexArray<IndexArray<Collider>>[cellsY];
                for (int j = 0; j < cellsY; j++)
                {
                    bucketBags[i][j] = new IndexArray<IndexArray<Collider>>(20);
                }
            }
            //
            distToOffsets = GenerateReachOffsetsDictionary();

            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();
            int generateReach = gridWidth / 3;
            //GenerateAllReachOffsetsPerCoord(generateReach); //takes a shitload of time.. but only for the temproom?
            //stopwatch.Stop();
            //string taken = stopwatch.Elapsed.ToString();
            //Console.WriteLine("gridsystem generation time taken: " + taken);

            bucketLists = new List<List<Collider>>[cellsX, cellsY];

            ///new attempt
            GenerateReachOffsetsArray();
        }
Ejemplo n.º 4
0
        public void TestEnumerator()
        {
            int[]            expected = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
            IndexArray <int> actual   = new IndexArray <int>(5, expected);

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 5
0
 public Cubo(float baseX, float baseY, float baseZ)
     : base()
 {
     initValue(baseX, baseY, baseZ);
     indexArray         = new IndexArray(indicedata);
     positionIndexArray = new VertexArray();
     colorIndexArray    = new VertexArray();
 }
Ejemplo n.º 6
0
        public void TestIncert_ShouldThrowIndexOutOfRangeException()
        {
            // arrange
            int[]            arr         = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            IndexArray <int> index_array = new IndexArray <int>(3, arr);

            // act and assert
            Assert.Throws <IndexOutOfRangeException>(() => index_array.Insert(14, 5));
        }
Ejemplo n.º 7
0
 public NpyHeader(byte major, byte minor, DType numpyType, bool fortranOrder,
                  IndexArray shape)
 {
     MajorVersion = major;
     MinorVersion = minor;
     NumpyType    = numpyType;
     FortranOrder = fortranOrder;
     Shape        = shape;
 }
Ejemplo n.º 8
0
        public void TestIndexatorGet_1_2_3_4_5_6_7_8_9_ShouldThrow_IndexOutOfRangeException(int startIndex, int searchIndex)
        {
            // arrange
            int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            // act
            IndexArray <int> actual = new IndexArray <int>(startIndex, arr);

            // assert
            Assert.Throws <IndexOutOfRangeException>(() => actual[searchIndex]);
        }
Ejemplo n.º 9
0
        private static IndexArray TransposeShape(IndexArray baseShape, ReadOnlySpan <int> axisMap)
        {
            Span <int> newShape = stackalloc int[baseShape.Length];

            for (var i = 0; i < baseShape.Length; ++i)
            {
                newShape[i] = baseShape[axisMap[i]];
            }
            return(new IndexArray(newShape));
        }
Ejemplo n.º 10
0
        public void TestContains_ShouldReturn_False()
        {
            // arrange
            int[]            arr         = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            IndexArray <int> index_array = new IndexArray <int>(new Random().Next(), arr);
            // act
            bool actual = index_array.Contains(48);

            // assert
            Assert.False(actual);
        }
Ejemplo n.º 11
0
 internal static void ToTransposedShapedIndices(
     IndexArray shape,
     ReadOnlySpan <int> shapedIndices,
     ReadOnlySpan <int> axisMap,
     Span <int> resultIndices)
 {
     for (var i = 0; i < shape.Length; ++i)
     {
         resultIndices[i] = shapedIndices[axisMap[i]];
     }
 }
Ejemplo n.º 12
0
        public void TestIndexator_Get_1_2_3_4_5_6_7_8_9_StartedAt_FIRST_index_Get_SECOND_index_ShouldReturn_THIRD_value
            (int startIndex, int searchIndex, int expectedValue)
        {
            // arrange
            int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            // act
            IndexArray <int> actual = new IndexArray <int>(startIndex, arr);

            // assert
            Assert.True(actual[searchIndex] == expectedValue);
        }
Ejemplo n.º 13
0
        public void TestIndexOf_0_1_2_3_4_5_6_7_8_WithStartAt_5_ShouldReturn_Minus_1()
        {
            // arrange
            int[]            arr         = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
            IndexArray <int> index_array = new IndexArray <int>(5, arr);
            int expected = -1;
            // act
            int actual = index_array.IndexOf(10);

            // assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 14
0
        public void TestCreateWithArray_ShouldReturn_3_5_6_4_8_AtPosition_3()
        {
            // arrange
            int[] expected = new int[] { 3, 5, 6, 4, 8 };
            // act
            IndexArray <int> actual = new IndexArray <int>(3, expected);

            // assert

            Assert.Equal(expected, actual);
            Assert.True(actual[3] == 3);
        }
Ejemplo n.º 15
0
        public void TestRemove_ShouldReturn_False()
        {
            // arrange
            int[]            arr         = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            IndexArray <int> index_array = new IndexArray <int>(new Random().Next(), arr);
            // act
            bool actual = index_array.Remove(14);

            // assert
            Assert.False(actual);
            Assert.Equal(arr, index_array);
        }
Ejemplo n.º 16
0
        public void TestIndexator_Set_1_2_3_4_5_6_7_8_9_StartedAt_FIRST_index_SetAt_SECOND_index_THIRD_value
            (int startIndex, int pasteIndex, int pastedValue)
        {
            // arrange
            int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            // act
            IndexArray <int> actual = new IndexArray <int>(startIndex, arr);

            actual[pasteIndex] = pastedValue;
            // assert
            Assert.True(actual[pasteIndex] == pastedValue);
        }
Ejemplo n.º 17
0
        public void Read(string filename, byte major, byte minor, DType dtype,
                         bool fortranOrder, IndexArray shape)
        {
            var stream = LoadTestResource(filename);
            var header = NpyHeader.LoadHeader(stream);

            Assert.Equal(major, header.MajorVersion);
            Assert.Equal(minor, header.MinorVersion);
            Assert.Equal(dtype, header.NumpyType);
            Assert.Equal(fortranOrder, header.FortranOrder);
            Assert.Equal(shape, header.Shape);
        }
Ejemplo n.º 18
0
 public void Build()
 {
     IndexArray.Build();
     if (_unique)
     {
         keyent = new Dictionary <Tkey, PaEntry>();
     }
     else
     {
         keyents = new Dictionary <Tkey, List <PaEntry> >();
     }
 }
Ejemplo n.º 19
0
 public int peek(stacks s)
 {
     if (!isEmpty(s))
     {
         IndexArray idx = idxStack[(int)s];
         return(array[idx.Current - 1]);
     }
     else
     {
         throw new EmptyStackException();
     }
 }
Ejemplo n.º 20
0
        public void TestRemoveAt_ShouldReturn_Without_6()
        {
            // arrange
            int[]            arr         = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[]            expected    = new int[] { 1, 2, 3, 4, 5, 7, 8, 9 };
            IndexArray <int> index_array = new IndexArray <int>(-3, arr);

            // act
            index_array.RemoveAt(2);

            // assert
            Assert.Equal(expected, index_array);
        }
Ejemplo n.º 21
0
        public void TestIncert()
        {
            // arrange
            int[]            arr         = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[]            expected    = new int[] { 1, 2, 3, 4, 5, 6, 100, 7, 8, 9 };
            IndexArray <int> index_array = new IndexArray <int>(-3, arr);

            // act
            index_array.Insert(2, 100);

            // assert
            Assert.Equal(expected, index_array);
        }
Ejemplo n.º 22
0
            public void push(stacks s, int el)
            {
                IndexArray idx = idxStack[(int)s];

                if (!isFull(s))
                {
                    array[idx.Current] = el;
                    idx.Current++;
                }
                else
                {
                    throw new FullStackException();
                }
            }
Ejemplo n.º 23
0
        public void Write(string filename, byte major, byte minor, DType dtype,
                          bool fortranOrder, IndexArray shape)
        {
            var stream = LoadTestResource(filename);
            var buffer = new byte[stream.Length];

            stream.Read(buffer);

            var header       = new NpyHeader(major, minor, dtype, fortranOrder, shape);
            var headerBuffer = header.GenerateHeader();

            Assert.Equal(0, headerBuffer.Length % 16);
            Assert.True(buffer.Take(headerBuffer.Length).SequenceEqual(headerBuffer));
        }
Ejemplo n.º 24
0
        public void TestAdd_ShouldReturn_Param(int param)
        {
            IndexArray <int> arr = new IndexArray <int>();
            Random           r   = new Random();

            for (int i = 0; i < param; i++)
            {
                arr.Add(r.Next(0, 500));
            }

            int actual  = param;
            int current = arr.Count;

            Assert.Equal(current, actual);
        }
Ejemplo n.º 25
0
            public int pop(stacks s)
            {
                IndexArray idx = idxStack[(int)s];

                if (!isEmpty(s))
                {
                    int result = array[idx.Current - 1];
                    array[idx.Current] = 0;
                    idx.Current--;
                    return(result);
                }
                else
                {
                    throw new EmptyStackException();
                }
            }
Ejemplo n.º 26
0
            //Parameter: capacity
            // Size of the array that have to contain the stacks
            public FixedMultiStack(int capacity)
            {
                if (capacity < numberOfStack)
                {
                    throw new ArgumentException("Capacity cannot be less than the number of the stacks available");
                }
                idxStack           = new IndexArray[numberOfStack];
                this.arrayCapacity = capacity;
                for (int i = 0; i < numberOfStack; i++)
                {
                    idxStack[i] = new IndexArray(i * capacity / numberOfStack,
                                                 (i + 1) * capacity / numberOfStack - 1);
                }

                array = new int[capacity];
            }
Ejemplo n.º 27
0
        private Node parseCall()
        {
            Node left = parsePrimary();

            while (true)
            {
                if (match(TType.OPEN_PAREN))
                {
                    if (!(left is Variable))
                    {
                        throw new Exception($"Invalid call target '{left.GetType().Name}', can only be a function.");
                    }

                    List <Node> args = new List <Node>();

                    if (!check(TType.CLOSE_PAREN))
                    {
                        do
                        {
                            args.Add(parseExpression());
                        } while (match(TType.COMMA));
                    }

                    consume(TType.CLOSE_PAREN, "Expected ')' after function call parameters");

                    left = new CallFunc(((Variable)left).Name.lexeme, args.ToArray());
                }
                else if (match(TType.OPEN_SQR))
                {
                    Node idx = parsePrimary();

                    if (!(left is Variable))
                    {
                        throw new Exception($"Expected variable name before indexing, got {idx.GetType().Name}");
                    }

                    consume(TType.CLOSE_SQR, "Expected ']' after index");
                    left = new IndexArray(left, idx);
                }
                else
                {
                    break;
                }
            }

            return(left);
        }
Ejemplo n.º 28
0
        private static async Task MoveNext(ISocketMessageChannel channel, IndexArray <DesyncItem> desyncs)
        {
            var embed = desyncs.First.ToEmbed();

            embed.Footer = new EmbedFooterBuilder()
            {
                Text = "Desyncs left: " + desyncs.Count
            };
            var message = await channel.SendEmbedAsync(embed);

            GuildDesyncInteractiveMessage interactiveMessage = new GuildDesyncInteractiveMessage(message, desyncs);

            IEmote[] emotes = new IEmote[desyncs.First.Options.Count];
            for (int i = 0; i < emotes.Length; i++)
            {
                emotes[i] = UnicodeEmoteService.Numbers[i];
            }
            await message.AddReactionsAsync(emotes);
        }
Ejemplo n.º 29
0
 //Такой вариант не получается из-за использования шкалы
 //public IEnumerable<PolarDB.PaEntry> GetAllByKey(Tkey key)
 //{
 //    return GetAllByKey(0, IndexArray.Count(), key);
 //}
 public IEnumerable <PaEntry> GetAllByKey(Tkey key)
 {
     if (_unique)
     {
         PaEntry entry;
         if (keyent.TryGetValue(key, out entry))
         {
             return(Enumerable.Repeat <PaEntry>(entry, 1).Concat <PaEntry>(IndexArray.GetAllByKey(key)));
         }
         return(IndexArray.GetAllByKey(key));
     }
     else
     {
         List <PaEntry> entries;
         if (keyents.TryGetValue(key, out entries))
         {
             return(entries.Concat <PaEntry>(IndexArray.GetAllByKey(key)));
         }
         return(IndexArray.GetAllByKey(key));
     }
     //return GetAllByKey(0, IndexArray.Count(), key);
 }
Ejemplo n.º 30
0
        public override ICommandContext ParseCommand(IMessageContext dmContext)
        {
            string commandIdentifier = null;
            string argumentSection;
            IndexArray <string> arguments;
            Command             interpretedCommand = null;
            CommandSearchResult commandSearch;

            string message = dmContext.Content.Substring(Prefix.Length).TrimStart();

            int firstSpace = message.IndexOf(' ');

            if (firstSpace == -1)
            {
                commandIdentifier = message.Trim();
                commandSearch     = CommandCollection.TryFindCommand(commandIdentifier, 0, out interpretedCommand);
                return(new CommandContext(interpretedCommand, commandSearch, string.Empty, new IndexArray <string>(0)));
            }

            commandIdentifier = message.Substring(0, firstSpace).Trim();
            argumentSection   = message.Substring(firstSpace + 1);

            int argcnt;

            if (string.IsNullOrEmpty(argumentSection))
            {
                arguments = new IndexArray <string>(0);
                argcnt    = 0;
            }
            else
            {
                argcnt = 1;
                for (int i = 0; i < argumentSection.Length; i++)
                {
                    bool isUnescapedComma = argumentSection[i] == ',';
                    if (i > 0 && isUnescapedComma)
                    {
                        isUnescapedComma = argumentSection[i - 1] != '\\';
                    }
                    if (isUnescapedComma)
                    {
                        argcnt++;
                    }
                }
                arguments = new IndexArray <string>(argcnt);
                int argindex  = 0;
                int lastindex = 0;
                for (int i = 0; i < argumentSection.Length; i++)
                {
                    bool isUnescapedComma = argumentSection[i] == ',';
                    if (i > 0 && isUnescapedComma)
                    {
                        isUnescapedComma = argumentSection[i - 1] != '\\';
                    }
                    if (isUnescapedComma)
                    {
                        if (lastindex < i)
                        {
                            arguments[argindex] = argumentSection.Substring(lastindex, i - lastindex).Trim().Replace("\\,", ",");
                        }
                        else
                        {
                            arguments[argindex] = string.Empty;
                        }
                        argindex++;
                        lastindex = i + 1;
                    }
                }
                if (lastindex <= argumentSection.Length - 1)
                {
                    arguments[argindex] = argumentSection.Substring(lastindex, argumentSection.Length - lastindex).Trim().Replace("\\,", ",");
                }
                else
                {
                    arguments[argindex] = string.Empty;
                }
            }

            commandSearch = CommandCollection.TryFindCommand(commandIdentifier, argcnt, out interpretedCommand);

            return(new CommandContext(interpretedCommand, commandSearch, argumentSection, arguments));
        }
Ejemplo n.º 31
0
        public static void TestCountArray()
        {
            //Weird.
            int length = 1000000;
            int[] ints = new int[length];
            IndexArray<int> counted = new IndexArray<int>(new int[length]);
            List<int> list = new List<int>();
            w("count").Start();
            for (int i = 0; i < counted.index; i++)
            {
                counted.array[i] = i;
            }
            w("count").Stop();
            int len = ints.Length;
            w("array").Start();
            for (int i = 0; i < len; i++)
            {
                ints[i] = i;
            }
            w("array").Stop();

            w("listadd").Start();
            for (int i = 0; i < length; i++)
            {
                list.Add(i);
            }
            w("listadd").Stop();
            w("listmod").Start();
            for (int i = 0; i < length; i++)
            {
                list[i] = i+1;
            }
            w("listmod").Stop();

            PrintTimer("count");
            PrintTimer("array");
            PrintTimer("listadd");
            PrintTimer("listmod");
        }
Ejemplo n.º 32
0
 public void FillFinish()
 {
     IndexArray.FillFinish();
 }