@@ -15,17 +15,17 @@ public readonly struct Buffer2DRegion<T>
1515 /// Initializes a new instance of the <see cref="Buffer2DRegion{T}"/> struct.
1616 /// </summary>
1717 /// <param name="buffer">The <see cref="Buffer2D{T}"/>.</param>
18- /// <param name="rectangle ">The <see cref="Rectangle "/> defining a rectangular area within the buffer.</param>
18+ /// <param name="bounds ">The <see cref="Bounds "/> defining a rectangular area within the buffer.</param>
1919 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
20- public Buffer2DRegion ( Buffer2D < T > buffer , Rectangle rectangle )
20+ public Buffer2DRegion ( Buffer2D < T > buffer , Rectangle bounds )
2121 {
22- DebugGuard . MustBeGreaterThanOrEqualTo ( rectangle . X , 0 , nameof ( rectangle ) ) ;
23- DebugGuard . MustBeGreaterThanOrEqualTo ( rectangle . Y , 0 , nameof ( rectangle ) ) ;
24- DebugGuard . MustBeLessThanOrEqualTo ( rectangle . Width , buffer . Width , nameof ( rectangle ) ) ;
25- DebugGuard . MustBeLessThanOrEqualTo ( rectangle . Height , buffer . Height , nameof ( rectangle ) ) ;
22+ DebugGuard . MustBeGreaterThanOrEqualTo ( bounds . X , 0 , nameof ( bounds ) ) ;
23+ DebugGuard . MustBeGreaterThanOrEqualTo ( bounds . Y , 0 , nameof ( bounds ) ) ;
24+ DebugGuard . MustBeLessThanOrEqualTo ( bounds . Width , buffer . Width , nameof ( bounds ) ) ;
25+ DebugGuard . MustBeLessThanOrEqualTo ( bounds . Height , buffer . Height , nameof ( bounds ) ) ;
2626
2727 this . Buffer = buffer ;
28- this . Rectangle = rectangle ;
28+ this . Bounds = bounds ;
2929 }
3030
3131 /// <summary>
@@ -34,15 +34,10 @@ public Buffer2DRegion(Buffer2D<T> buffer, Rectangle rectangle)
3434 /// <param name="buffer">The <see cref="Buffer2D{T}"/>.</param>
3535 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3636 public Buffer2DRegion ( Buffer2D < T > buffer )
37- : this ( buffer , buffer . FullRectangle ( ) )
37+ : this ( buffer , buffer . Bounds )
3838 {
3939 }
4040
41- /// <summary>
42- /// Gets the rectangle specifying the boundaries of the area in <see cref="Buffer"/>.
43- /// </summary>
44- public Rectangle Rectangle { get ; }
45-
4641 /// <summary>
4742 /// Gets the <see cref="Buffer2D{T}"/> being pointed by this instance.
4843 /// </summary>
@@ -51,12 +46,12 @@ public Buffer2DRegion(Buffer2D<T> buffer)
5146 /// <summary>
5247 /// Gets the width
5348 /// </summary>
54- public int Width => this . Rectangle . Width ;
49+ public int Width => this . Bounds . Width ;
5550
5651 /// <summary>
5752 /// Gets the height
5853 /// </summary>
59- public int Height => this . Rectangle . Height ;
54+ public int Height => this . Bounds . Height ;
6055
6156 /// <summary>
6257 /// Gets the number of elements between row starts in <see cref="Buffer"/>.
@@ -66,20 +61,25 @@ public Buffer2DRegion(Buffer2D<T> buffer)
6661 /// <summary>
6762 /// Gets the size of the area.
6863 /// </summary>
69- internal Size Size => this . Rectangle . Size ;
64+ public Size Size => this . Bounds . Size ;
65+
66+ /// <summary>
67+ /// Gets the rectangle specifying the boundaries of the area in <see cref="Buffer"/>.
68+ /// </summary>
69+ public Rectangle Bounds { get ; }
7070
7171 /// <summary>
7272 /// Gets a value indicating whether the area refers to the entire <see cref="Buffer"/>
7373 /// </summary>
74- internal bool IsFullBufferArea => this . Size == this . Buffer . Size ( ) ;
74+ internal bool IsFullBufferArea => this . Size == this . Buffer . Size ;
7575
7676 /// <summary>
7777 /// Gets or sets a value at the given index.
7878 /// </summary>
7979 /// <param name="x">The position inside a row</param>
8080 /// <param name="y">The row index</param>
8181 /// <returns>The reference to the value</returns>
82- internal ref T this [ int x , int y ] => ref this . Buffer [ x + this . Rectangle . X , y + this . Rectangle . Y ] ;
82+ internal ref T this [ int x , int y ] => ref this . Buffer [ x + this . Bounds . X , y + this . Bounds . Y ] ;
8383
8484 /// <summary>
8585 /// Gets a span to row 'y' inside this area.
@@ -89,9 +89,9 @@ public Buffer2DRegion(Buffer2D<T> buffer)
8989 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
9090 public Span < T > DangerousGetRowSpan ( int y )
9191 {
92- int yy = this . Rectangle . Y + y ;
93- int xx = this . Rectangle . X ;
94- int width = this . Rectangle . Width ;
92+ int yy = this . Bounds . Y + y ;
93+ int xx = this . Bounds . X ;
94+ int width = this . Bounds . Width ;
9595
9696 return this . Buffer . DangerousGetRowSpan ( yy ) . Slice ( xx , width ) ;
9797 }
@@ -114,16 +114,16 @@ public Buffer2DRegion<T> GetSubRegion(int x, int y, int width, int height)
114114 /// <summary>
115115 /// Returns a subregion as <see cref="Buffer2DRegion{T}"/>. (Similar to <see cref="Span{T}.Slice(int, int)"/>.)
116116 /// </summary>
117- /// <param name="rectangle">The <see cref="Rectangle "/> specifying the boundaries of the subregion</param>
117+ /// <param name="rectangle">The <see cref="Bounds "/> specifying the boundaries of the subregion</param>
118118 /// <returns>The subregion</returns>
119119 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
120120 public Buffer2DRegion < T > GetSubRegion ( Rectangle rectangle )
121121 {
122- DebugGuard . MustBeLessThanOrEqualTo ( rectangle . Width , this . Rectangle . Width , nameof ( rectangle ) ) ;
123- DebugGuard . MustBeLessThanOrEqualTo ( rectangle . Height , this . Rectangle . Height , nameof ( rectangle ) ) ;
122+ DebugGuard . MustBeLessThanOrEqualTo ( rectangle . Width , this . Bounds . Width , nameof ( rectangle ) ) ;
123+ DebugGuard . MustBeLessThanOrEqualTo ( rectangle . Height , this . Bounds . Height , nameof ( rectangle ) ) ;
124124
125- int x = this . Rectangle . X + rectangle . X ;
126- int y = this . Rectangle . Y + rectangle . Y ;
125+ int x = this . Bounds . X + rectangle . X ;
126+ int y = this . Bounds . Y + rectangle . Y ;
127127 rectangle = new Rectangle ( x , y , rectangle . Width , rectangle . Height ) ;
128128 return new Buffer2DRegion < T > ( this . Buffer , rectangle ) ;
129129 }
@@ -135,8 +135,8 @@ public Buffer2DRegion<T> GetSubRegion(Rectangle rectangle)
135135 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
136136 internal ref T GetReferenceToOrigin ( )
137137 {
138- int y = this . Rectangle . Y ;
139- int x = this . Rectangle . X ;
138+ int y = this . Bounds . Y ;
139+ int x = this . Bounds . X ;
140140 return ref this . Buffer . DangerousGetRowSpan ( y ) [ x ] ;
141141 }
142142
@@ -152,7 +152,7 @@ internal void Clear()
152152 return ;
153153 }
154154
155- for ( int y = 0 ; y < this . Rectangle . Height ; y ++ )
155+ for ( int y = 0 ; y < this . Bounds . Height ; y ++ )
156156 {
157157 Span < T > row = this . DangerousGetRowSpan ( y ) ;
158158 row . Clear ( ) ;
@@ -172,7 +172,7 @@ internal void Fill(T value)
172172 return ;
173173 }
174174
175- for ( int y = 0 ; y < this . Rectangle . Height ; y ++ )
175+ for ( int y = 0 ; y < this . Bounds . Height ; y ++ )
176176 {
177177 Span < T > row = this . DangerousGetRowSpan ( y ) ;
178178 row . Fill ( value ) ;
0 commit comments