예제 #1
0
        public DataTable Create(DataTable.IFieldTypeConverter ftc)
        {
            var rows      = new List <DataTable.Row>(_rows.Count);
            var startRef  = _schema.rangeStartRef;
            var rowOffset = (_schema.isRotated) ? 0 : _schema.nextBlockOffset;
            var colOffset = (!_schema.isRotated) ? 0 : _schema.nextBlockOffset;

            var count      = System.Math.Min(_rows.Count, _rowCountLimit);
            var isEmptyRow = System.Array.TrueForAll(
                _rows[count - 1], x => x == null
                );

            if (isEmptyRow)
            {
                --count;
            }
            for (var n = 0; n < count; ++n)
            {
                var cr = new CellRef(
                    startRef.row + (n * rowOffset),
                    startRef.col + (n * colOffset)
                    );
                rows.Add(new DataTable.Row(cr, _rows[n]));
            }

            return(new DataTable(_schema, rows, ftc));
        }
        public void AddColumnsWorks()
        {
            var a1 = new CellRef("A1");
            var g1 = a1.AddColumns(6);

            g1.ToString().Should().Be("G1");
        }
예제 #3
0
        public void IsNextAdjacentWorksForNextRow()
        {
            var a1 = new CellRef("A1");
            var a2 = new CellRef("A2");

            a2.IsNextAdjacentTo(a1).Should().BeTrue();
        }
        public void AddRowsWorks()
        {
            var a1 = new CellRef("A1");
            var a7 = a1.AddRows(6);

            a7.ToString().Should().Be("A7");
        }
        public void IsNextAdjacentReturnsFalseForPreviousAdjacentRow()
        {
            var a1 = new CellRef("A1");
            var a2 = new CellRef("A2");

            a1.IsNextAdjacentTo(a2).Should().BeFalse();
        }
예제 #6
0
        public void IsNextAdjacentReturnsFalseFoPreviousAdjacentRow()
        {
            var a1 = new CellRef("A1");
            var b1 = new CellRef("B1");

            a1.IsNextAdjacentTo(b1).Should().BeFalse();
        }
        public void AddLargeColumnsWorks()
        {
            var aa1 = new CellRef("AA1");
            var ag1 = aa1.AddColumns(6);

            ag1.ToString().Should().Be("AG1");
        }
예제 #8
0
        private void GetDimension()
        {
            while (ReadNextXmlElementAndLogRowNumber())
            {
                if (_xmlReader.IsStartOfElement("dimension"))
                {
                    var rangeRef         = _xmlReader.GetAttribute("ref");
                    var regex            = new Regex("^([A-Z]+[0-9]+)(?::([A-Z]+[0-9]+))?$");
                    var match            = regex.Match(rangeRef);
                    var topLeftRange     = match.Groups[1].Value;
                    var bottomRightRange = match.Groups[2].Value;
                    var topLeft          = new CellRef(topLeftRange);
                    var bottomRight      = bottomRightRange != ""
                        ? new CellRef(bottomRightRange)
                        : new CellRef(topLeftRange);
                    WorksheetDimension = new WorksheetDimension {
                        TopLeft = topLeft, BottomRight = bottomRight
                    };
                    MinRow          = topLeft.Row;
                    MaxRow          = bottomRight.Row;
                    MinColumnNumber = topLeft.ColumnNumber;
                    MaxColumnNumber = bottomRight.ColumnNumber;
                    break;
                }

                if (_xmlReader.IsStartOfElement("sheetData"))
                {
                    break;
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Gets a list of all the cell values in the specified row
        /// </summary>
        /// <param name="row">The 1-based row index</param>
        /// <returns>An enumerable of objects representing the values of cells in the row</returns>
        public IEnumerable <object> Row(int row)
        {
            var topLeft     = new CellRef(row, MinColumnNumber);
            var bottomRight = new CellRef(row, MaxColumnNumber);

            return(this[topLeft.ToString(), bottomRight.ToString()]);
        }
예제 #10
0
        /// <summary>
        /// Gets a list of all the cell values at the specified ordinal column index.
        /// </summary>
        /// <param name="column">The column index </param>
        /// <returns>An enumerable of objects representing the values of cells in the column</returns>
        public IEnumerable <object> Column(int column)
        {
            var topLeft     = new CellRef(MinRow, column);
            var bottomRight = new CellRef(MaxRow, column);

            return(this[topLeft.ToString(), bottomRight.ToString()]);
        }
예제 #11
0
        public override int GetCost(CellRef cell)
        {
            Building building = edificeGrid[cell.Index];

            if (building is Building_Door door)
            {
                if (pawn != null && door.PawnCanOpen(pawn) && !door.IsForbiddenToPass(pawn) && !door.FreePassage)
                {
                    return(door.TicksToOpenNow);
                }
                if ((pawn != null && door.CanPhysicallyPass(pawn)) || door.FreePassage)
                {
                    return(0);
                }
                // NOTE: I don't know why all three of these cases have different costs in vanilla
                if (mode == TraverseMode.PassDoors)
                {
                    return(150);
                }
                if (mode == TraverseMode.ByPawn)
                {
                    // NOTE: Vanilla has a can-bash check here but that gets taken care of in the Passability rule
                    // ...no, I don't know why it checks if the pawn can bash but doesn't bother accounting for door
                    // hit points if they can.
                    return(300);
                }
                return(Cost_BlockedDoorBase + (int)(door.HitPoints * Cost_BlockedDoorPerHitPoint));
            }
            return(0);
        }
        public void IsNextAdjacentWorksForSameRow()
        {
            var a1 = new CellRef("A1");
            var b1 = new CellRef("B1");

            b1.IsNextAdjacentTo(a1).Should().BeTrue();
        }
예제 #13
0
        public void EqualityWorks()
        {
            var cellRefA1         = new CellRef("A1");
            var cellRefA1FromInts = new CellRef(1, 1);

            (cellRefA1 == cellRefA1FromInts).Should().BeTrue();
            (cellRefA1 != cellRefA1FromInts).Should().BeFalse();
        }
예제 #14
0
 void RemoveFromCell(CellRef r, GameObject obj)
 {
     r.Cell.Remove(obj);
     if (r.Cell.Count == 0)
     {
         cells.Remove(r.Key);
     }
 }
 public override int GetCost(CellRef cell)
 {
     if (!allowedArea[cell.Index])
     {
         return(Cost_OutsideAllowedArea);
     }
     return(0);
 }
예제 #16
0
        public void CellRefIndexerWorks()
        {
            var cellRef          = new CellRef("A3");
            var testFileLocation = TestHelper.TestsheetPath("TestSpreadsheet1.xlsx");
            var sheet1           = new ExcelReader(testFileLocation)["Sheet1"];

            sheet1[cellRef].Should().Be("zyx987");
        }
        public void IntegerIsNextAdjacentWorksForNextRow()
        {
            var a1 = new CellRef("A1");
            var a2 = new CellRef("A2");

            CellRefExtensionMethods.IsNextAdjacentTo(a2.Row, a2.ColumnNumber, a1.Row, a1.ColumnNumber).Should()
            .BeTrue();
        }
        public void IntegerIsNextAdjacentWorksForSameRow()
        {
            var a1 = new CellRef("A1");
            var b1 = new CellRef("B1");

            CellRefExtensionMethods.IsNextAdjacentTo(b1.Row, b1.ColumnNumber, a1.Row, a1.ColumnNumber).Should()
            .BeTrue();
        }
예제 #19
0
 public override int GetCost(CellRef cell)
 {
     if (PawnUtility.AnyPawnBlockingPathAt(cell, pawn, false, false, true))
     {
         return(Cost_PawnCollision);
     }
     return(0);
 }
예제 #20
0
        public void IsNextAdjacentReturnsFalseForNonAdjacent()
        {
            var a1 = new CellRef("A1");
            var c3 = new CellRef("C3");

            a1.IsNextAdjacentTo(c3).Should().BeFalse();
            c3.IsNextAdjacentTo(a1).Should().BeFalse();
        }
예제 #21
0
        private bool _TryAppendCellToDown(XlsxReader reader)
        {
            var fields = _schema.fieldsForBuilder;
            var bW     = _schema.blockWidth;
            var r      = reader.cellRef.row - _rowRef.row;
            var c      = reader.cellRef.col - _rowRef.col;

            if (r < 0 || c < 0 || c >= bW)
            {
                return(false);
            }
            while (r >= _schema.nextBlockOffset)
            {
                var row = _rowRef.row + _schema.nextBlockOffset;
                _rowRef     = new CellRef(row, _rowRef.col);
                _fieldOrder = 0;
                var isFullRow = System.Array.TrueForAll(
                    _rows[_rowIndex], x => x != null
                    );
                if (!isFullRow)
                {
                    tryAppendCell = _DoNotAppendCell;
                    return(false);
                }
                _rows.Add(new string[_schema.fieldCount]);
                _rowIndex = _rows.Count - 1;
                r        -= _schema.nextBlockOffset;
            }
            do
            {
                if (_fieldOrder >= fields.Count)
                {
                    return(false);
                }
                var field = fields[_fieldOrder];
                if (field.rowOffset > r)
                {
                    return(false);
                }
                if (field.rowOffset < r)
                {
                    ++_fieldOrder; continue;
                }
                if (field.colOffset > c)
                {
                    return(false);
                }
                if (field.colOffset < c)
                {
                    ++_fieldOrder; continue;
                }
                var fi = fields[_fieldOrder].index;
                var v  = reader.cellValue;
                _rows[_rowIndex][fi] = v;
                ++_fieldOrder;
            } while (false);
            return(true);
        }
예제 #22
0
        public void SingleColumnRangeWorks()
        {
            var range = CellRef.Range("A1", "A4").ToArray();

            range[0].ToString().Should().Be("A1");
            range[1].ToString().Should().Be("A2");
            range[2].ToString().Should().Be("A3");
            range[3].ToString().Should().Be("A4");
        }
예제 #23
0
 /// <summary>
 ///     Get a list of cell values covered by the range in the index, e.g. sheetReader["A1","B2"] will return a list of four
 ///     values,
 ///     going left-to-right and then top-to-bottom, from the cells A1, B1, A2, B2.
 /// </summary>
 /// <example>
 /// <code>
 /// var range = sheetReader["A1","B2"];
 /// </code>
 /// </example>
 /// <param name="topLeft">The top left cell of the required range</param>
 /// <param name="bottomRight">The bottom right cell of the required range</param>
 public IEnumerable <object> this[string topLeft, string bottomRight]
 {
     get
     {
         var range  = CellRef.Range(topLeft, bottomRight).Select(x => x.ToString());
         var result = range.Select(x => this[x]);
         return(result);
     }
 }
 public override bool IsPassable(CellRef cell)
 {
     if (!pathGrid.WalkableFast(cell.Index))
     {
         Building building = edificeGrid[cell.Index];
         return(canDestroy && building != null && PathFinder.IsDestroyable(building));
     }
     return(true);
 }
예제 #25
0
        public void RangeWorks()
        {
            var range = CellRef.Range("A1", "B2").ToArray();

            range[0].ToString().Should().Be("A1");
            range[1].ToString().Should().Be("B1");
            range[2].ToString().Should().Be("A2");
            range[3].ToString().Should().Be("B2");
        }
예제 #26
0
        public void InequalityWorks()
        {
            var cellRefA1         = new CellRef("A1");
            var cellRefA2FromInts = new CellRef(1, 2);

            (cellRefA1 != cellRefA2FromInts).Should().BeTrue();
            (cellRefA1 == cellRefA2FromInts).Should().BeFalse();
            cellRefA1.Equals(cellRefA2FromInts).Should().BeFalse();
        }
예제 #27
0
        public override bool IsPassable(CellRef cell)
        {
            Building building = edificeGrid[cell.Index];

            if (building is Building_Door door)
            {
                return(door.FreePassage);
            }
            return(true);
        }
예제 #28
0
        public void SendingInvalidStringToConstructorThrowsMeaningfulException()
        {
            Action action = () =>
            {
                // ReSharper disable once UnusedVariable
                var cellRef = new CellRef("Not a valid cell ref");
            };

            action.Should().Throw <FormatException>().WithMessage("Input string was not in a correct format. Was expecting cell address in ColumnLetterRowNumber format (e.g. 'AM56') but received 'Not a valid cell ref'");
        }
예제 #29
0
        public override int GetCost(CellRef cell)
        {
            Building building = edificeGrid[cell.Index];

            // Note - vanilla never calls PathFindCostFor() on doors, but it does do so for walls.  I don't know why.
            if (building != null && !(building is Building_Door))
            {
                return(building.PathFindCostFor(pawn));
            }
            return(0);
        }
 public override int GetCost(CellRef cell)
 {
     if (pathGrid.WalkableFast(cell.Index))
     {
         int cost = pathGrid.pathGrid[cell];
         cost += pawnDrafted ? terrainGrid.topGrid[cell].extraDraftedPerceivedPathCost
                 : terrainGrid.topGrid[cell].extraNonDraftedPerceivedPathCost;
         return(cost);
     }
     return(0);
 }
예제 #31
0
파일: RefSet.cs 프로젝트: josiahdj/SDFCalc
		public bool SeenBefore(CellRef cellRef) { return !cellRefsSeen.Add(cellRef); }
예제 #32
0
		public void CallVisitor(CellRef cellRef) {
			FullCellAddr cellAddr = cellRef.GetAbsoluteAddr(thisFca);
			if (cellAddr.sheet != thisFca.sheet) {
				// Reference to other sheet, hopefully a normal sheet
				result = new CGNormalCellRef(cellAddr);
			}
			else if (this.addressToVariable.ContainsKey(cellAddr)) {
				// Reference to a cell that has already been computed in a local variable
				result = new CGCellRef(cellAddr, this.addressToVariable[cellAddr]);
			}
			else // Inline the cell's formula's expression
			{
				result = BuildExpression(cellAddr, addressToVariable);
			}
		}
예제 #33
0
파일: Parser.cs 프로젝트: josiahdj/SDFCalc
		private void Factor(out Expr e) {
			RARef r1, r2;
			Sheet s1 = null;
			double d;
			bool sheetError = false;
			e = null;
			switch (la.kind) {
				case 1: {
					Application(out e);
					break;
				}
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
				case 10:
				case 11:
				case 12:
				case 13:
				case 14: {
					if (StartOf(2)) {}
					else {
						Get();
						s1 = workbook[t.val.Substring(0, t.val.Length - 1)];
						if (s1 == null) {
							sheetError = true;
						}
					}
					Raref(out r1);
					if (StartOf(3)) {
						if (sheetError) {
							e = new Error(ErrorValue.refError);
						}
						else {
							e = new CellRef(s1, r1);
						}
					}
					else if (la.kind == 26) {
						Get();
						Raref(out r2);
						if (sheetError) {
							e = new Error(ErrorValue.refError);
						}
						else {
							e = new CellArea(s1, r1, r2);
						}
					}
					else {
						SynErr(37);
					}
					break;
				}
				case 2: {
					Number(out d);
					e = new NumberConst(d);
					break;
				}
				case 18: {
					Get();
					Factor(out e);
					if (e is NumberConst) {
						e = new NumberConst(-((NumberConst)e).value.value);
					}
					else {
						e = FunCall.Make("NEG", new Expr[] {e});
					}

					break;
				}
				case 15: {
					Get();
					e = new TextConst(t.val.Substring(1, t.val.Length - 2));
					break;
				}
				case 27: {
					Get();
					Expr(out e);
					Expect(28);
					break;
				}
				default:
					SynErr(38);
					break;
			}
		}