예제 #1
0
        public Input GetInput()
        {
            var   file      = new StreamReader(_filePath);
            var   line1     = file.ReadLine();
            Input inputData = new Input();

            // Get Totals from 1st line
            inputData.TotalBooks     = int.Parse(line1.Split(' ')[0]);
            inputData.TotalLibraries = int.Parse(line1.Split(' ')[1]);
            inputData.TotalDays      = int.Parse(line1.Split(' ')[2]);
            // Get Books from 2nd line
            var line2 = file.ReadLine();

            inputData.Books = line2.Split(' ').Select(int.Parse).ToArray();
            InputLibrary[] libraries = new InputLibrary[inputData.TotalLibraries];
            // Get inputData.TotalLibraries from subsequent lines
            for (int i = 0; i <= inputData.TotalLibraries - 1; i++)
            {
                // 1st line of library will hold the library totals
                var          libraryLine = file.ReadLine();
                InputLibrary library     = new InputLibrary();
                library.NumberOfBooks       = int.Parse(libraryLine.Split(' ')[0]);
                library.SignupDays          = int.Parse(libraryLine.Split(' ')[1]);
                library.BooksScanningPerDay = int.Parse(libraryLine.Split(' ')[2]);
                // 2nd line contains book ids that the library contains
                var booksPerLibraryLine = file.ReadLine();
                library.Books = booksPerLibraryLine.Split(' ').Select(int.Parse).ToArray();
                libraries[i]  = library;
            }

            inputData.Libraries = libraries;
            file.Dispose();
            return(inputData);
        }
예제 #2
0
        public void InputLibraryInjectTest()
        {
            InputContext ic = TestScaffold.ConstructContext();

            // create a library
            InputLibrary il = new InputLibrary("l:testlibrary");
            Exline       ex = new Exline("a:0 + 5");

            ic.CompileLine(ex);
            il.Funcs.Add("f:add5", ex);

            // add the library to the inputcontext
            ic.SetLibrary("anon", il);

            // test using the library
            Exline t1 = new Exline("f:add5(10.0)");
            Exline t2 = new Exline("f:add5(1.3)");

            ic.CompileLine(t1);
            ic.CompileLine(t2);

            double r1 = (double)t1.Execute(new object[] { 0 });
            double r2 = (double)t2.Execute(new object[] { 0 });

            Assert.AreEqual(15.0, r1);
            Assert.AreEqual(6.3, r2);
        }
        private void InputLibrary_Click(object sender, RoutedEventArgs e)
        {
            List.Children.Clear();
            InputLibrary InputLibrary = new InputLibrary();

            List.Children.Add(InputLibrary);
            InputLibrary.SetValue(Grid.RowProperty, 0);
            InputLibrary.SetValue(Grid.ColumnProperty, 3);
            InputLibrary.SetValue(Grid.ColumnSpanProperty, 12);
        }
        private void HandleMagicWandClick(InputLibrary.Cursor cursor)
        {
            int minX;
            int minY;
            int maxX;
            int maxY;

            var camera = imageRegionSelectionControl1.SystemManagers.Renderer.Camera;

            float worldX;
            float worldY;
            camera.ScreenToWorld(cursor.X, cursor.Y, out worldX, out worldY); ;

            inspectableTexture.GetOpaqueWandBounds((int)worldX, (int)worldY, out minX, out minY, out maxX, out maxY);

            bool hasValidSelection = minX > 0 && maxX > 0;

            if (hasValidSelection)
            {
                // increase by 1 to capture the extra pixels:
                maxX += 1;
                maxY += 1;

                var texture = imageRegionSelectionControl1.CurrentTexture;
                SetSelectionTextureCoordinates(minY / (float)texture.Height, maxY / (float)texture.Height, minX / (float)texture.Width, maxX / (float)texture.Width);

                if (RegionChanged != null)
                {
                    RegionChanged();
                }
            }
        }
        private mapTilesetTile TryGetOrMakeNewTilesetTileAtCursor( InputLibrary.Cursor cursor)
        {
            var tileset = AppState.Self.CurrentTileset;

            float worldX = cursor.GetWorldX(mManagers);
            float worldY = cursor.GetWorldY(mManagers);

            int id = tileset.CoordinateToLocalId(
                    (int)worldX,
                    (int)worldY);

            mapTilesetTile newTile = tileset.Tiles.FirstOrDefault(item=>item.id == id);

            if (newTile == null)
            {
                if (worldX > -1 && worldY > -1 &&
                    worldX < AppState.Self.CurrentTileset.Images[0].width &&
                    worldY < AppState.Self.CurrentTileset.Images[0].height)
                {
                    newTile = new mapTilesetTile();
                    newTile.id = id;

                    newTile.properties = new List<property>();
                }
            }

            return newTile;
        }