Add() public method

Add the specified cell and add the cell to the collection.
public Add ( Position pCell ) : bool
pCell Position
return bool
Beispiel #1
0
        /// <summary>
        /// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range.
        /// </summary>
        /// <param name="p_Range1"></param>
        /// <param name="p_Range2"></param>
        /// <returns></returns>
        public static RangeRegion Union(Range p_Range1, Range p_Range2)
        {
            RangeRegion range = new RangeRegion();

            range.Add(p_Range1);
            range.Add(p_Range2);
            return(range);
        }
		public void GetRowsIndex()
		{
			RangeRegion region = new RangeRegion();
			region.Add(new Range(0, 0, 0, 0));
			region.Add(new Range(2, 2, 2, 2));
			
			int[] indexes = region.GetRowsIndex();
			Assert.AreEqual(2, indexes.Length);
			Assert.AreEqual(0, indexes[0]);
			Assert.AreEqual(2, indexes[1]);
		}
		public void SelectionBug()
		{
			// Bug report http://www.devage.com/Forum/ViewTopic.aspx?id=8addb0016ae24d97acdef5183bc745c4#msgae7217a8cdc149d383cfdc207f1dc056
			
			// 1. create new RangeRegion with single Range(3, 3, 3, 3);
			// 2. Add new range witch extends our range by one cell to right 
			// 3. original RangeRegion should fire event Changed,
			// witch should report that a new region was added
			
			// The bug is that the AddedRange reports to be empty
			
			RangeRegion region = new RangeRegion(
				new Range(3, 3, 3, 3));
			region.Changed += delegate (object sender, RangeRegionChangedEventArgs e)
			{
				Assert.AreEqual(1, e.AddedRange.Count);
			};
			region.Add(new Range(3, 3, 3, 4));
		}
Beispiel #4
0
        /// <summary>
        /// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells)
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public RangeRegion Exclude(Range range)
        {
            RangeRegion excluded;

            Range intersection = Intersect(range);

            if (intersection.IsEmpty())
            {
                excluded = new RangeRegion(this);
            }
            else
            {
                excluded = new RangeRegion();

                //Top Left
                if (this.Start.Row < intersection.Start.Row &&
                    this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1));
                }

                //Top
                if (this.Start.Row < intersection.Start.Row)
                {
                    excluded.Add(new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column));
                }

                //Top Right
                if (this.Start.Row < intersection.Start.Row &&
                    this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row - 1, this.End.Column));
                }

                //----------

                //Left
                if (this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column - 1));
                }

                //Right
                if (this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column));
                }

                //--------

                //Bottom Left
                if (this.End.Row > intersection.End.Row &&
                    this.Start.Column < intersection.Start.Column)
                {
                    excluded.Add(new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1));
                }

                //Bottom
                if (this.End.Row > intersection.End.Row)
                {
                    excluded.Add(new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column));
                }

                //Bottom Right
                if (this.End.Row > intersection.End.Row &&
                    this.End.Column > intersection.End.Column)
                {
                    excluded.Add(new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column));
                }
            }

            return(excluded);
        }
Beispiel #5
0
		/// <summary>
		/// Return all the cells that don't intersect with the specified cells. (Remove the specified cells from the current cells ad returns the remaining cells)
		/// </summary>
		/// <param name="range"></param>
		/// <returns></returns>
		public RangeRegion Exclude(Range range)
		{
			RangeRegion excluded;

			Range intersection = Intersect(range);
			if (intersection.IsEmpty())
			{
				excluded = new RangeRegion(this);
			}
			else
			{
				excluded = new RangeRegion();

				//Top Left
				if (this.Start.Row < intersection.Start.Row && 
					this.Start.Column < intersection.Start.Column)
					excluded.Add( new Range(this.Start.Row, this.Start.Column, intersection.Start.Row - 1, intersection.Start.Column - 1) );

				//Top
				if (this.Start.Row < intersection.Start.Row)
					excluded.Add( new Range(this.Start.Row, intersection.Start.Column, intersection.Start.Row - 1, intersection.End.Column) );

				//Top Right
				if (this.Start.Row < intersection.Start.Row && 
					this.End.Column > intersection.End.Column)
					excluded.Add( new Range(this.Start.Row, intersection.End.Column + 1, intersection.Start.Row -1, this.End.Column) );

				//----------

				//Left
				if (this.Start.Column < intersection.Start.Column)
					excluded.Add( new Range(intersection.Start.Row, this.Start.Column, intersection.End.Row, intersection.Start.Column -1) );

				//Right
				if (this.End.Column > intersection.End.Column)
					excluded.Add( new Range(intersection.Start.Row, intersection.End.Column + 1, intersection.End.Row, this.End.Column) );

				//--------

				//Bottom Left
				if (this.End.Row > intersection.End.Row &&
					this.Start.Column < intersection.Start.Column)
					excluded.Add( new Range(intersection.End.Row + 1, this.Start.Column, this.End.Row, intersection.Start.Column - 1) );

				//Bottom
				if (this.End.Row > intersection.End.Row)
					excluded.Add( new Range(intersection.End.Row + 1, intersection.Start.Column, this.End.Row, intersection.End.Column) );

				//Bottom Right
				if (this.End.Row > intersection.End.Row &&
					this.End.Column > intersection.End.Column)
					excluded.Add( new Range(intersection.End.Row + 1, intersection.End.Column + 1, this.End.Row, this.End.Column) );
			}

			return excluded;
		}
Beispiel #6
0
		/// <summary>
		/// Returns a range with the smaller Start and the bigger End. The Union of the 2 Range. If one of the range is empty then the return is the other range.
		/// </summary>
		/// <param name="p_Range1"></param>
		/// <param name="p_Range2"></param>
		/// <returns></returns>
		public static RangeRegion Union(Range p_Range1, Range p_Range2)
		{
			RangeRegion range = new RangeRegion();
			range.Add(p_Range1);
			range.Add(p_Range2);
			return range;
		}