-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRectangularStep.cs
More file actions
52 lines (41 loc) · 1.57 KB
/
RectangularStep.cs
File metadata and controls
52 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedOCR
{
abstract class RectangularStep : Step
{
public RectangularStep(int width, int height, IList<RectangularStep> upstream)
: base(width * height, upstream == null ? null : upstream.ToList<Step>())
{
if (width <= 0 || height <= 0) throw new ArgumentException();
this.Width = width;
this.Height = height;
if (upstream != null)
this.Upstream = new ReadOnlyCollection<RectangularStep>(upstream);
else
this.Upstream = null;
}
protected static int WidthOf(IList<RectangularStep> upstream)
{
if (upstream == null || upstream.Count == 0) throw new ArgumentException();
int width = upstream[0].Width;
if (!upstream.All(step => step.Width == width)) throw new ArgumentException();
return width;
}
protected static int HeightOf(IList<RectangularStep> upstream)
{
if (upstream == null || upstream.Count == 0) throw new ArgumentException();
int height = upstream[0].Height;
if (!upstream.All(step => step.Height == height)) throw new ArgumentException();
return height;
}
public readonly int Width;
public readonly int Height;
public new readonly ReadOnlyCollection<RectangularStep> Upstream;
}
}