コード例 #1
0
        public Sheet ParseFile(string filePath)
        {
            var sheet = new Sheet();
            var mode  = 0;

            foreach (var line in ReadData(filePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    mode++;
                    continue;
                }
                if (mode == 0)
                {
                    var regResult = pointRule.Match(line);
                    var point     = new Point(Convert.ToInt32(regResult.Groups.Values.First(g => g.Name == "X").Captures[0].Value)
                                              , Convert.ToInt32(regResult.Groups.Values.First(g => g.Name == "Y").Captures[0].Value)
                                              );
                    sheet.Points.Add(point);
                }
                else if (mode == 1)
                {
                    var foldResult      = foldRule.Match(line);
                    var foldInstruction = new FoldInstruction
                    {
                        Direction = foldResult.Groups.Values.First(g => g.Name == "direction").Captures[0].Value == "x" ? FoldDirection.Vertical : FoldDirection.Horizontal,
                        Position  = Convert.ToInt32(foldResult.Groups.Values.First(g => g.Name == "position").Captures[0].Value)
                    };

                    sheet.Instruction.Add(foldInstruction);
                }
            }
            return(sheet);
        }
コード例 #2
0
        static Point PositionAfterFold(Point point, FoldInstruction instruction)
        {
            if (instruction.Direction == FoldDirection.Horizontal)
            {
                var y = point.Y > instruction.Position ? 2 * instruction.Position - point.Y : point.Y;
                return(new Point(point.X, y));
            }
            var x = point.X > instruction.Position ? 2 * instruction.Position - point.X : point.X;

            return(new Point(x, point.Y));
        }