From 2b432c09ae81fc33fd23ea6270af51bd1f6633ba Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 11 Sep 2018 01:38:53 +0100 Subject: [PATCH] make minor changes to variable names in library. Change the exeption code for file validation in library. --- DeathSocket/Domain.fs | 5 +++-- DeathSocket/GridPainter.fs | 13 +++++++++---- DeathSocket/ImageServices.fs | 24 +++++++++++------------- DeathSocket/ScratchPad.fsx | 5 ++--- DeathSocket/Validation.fs | 3 +-- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/DeathSocket/Domain.fs b/DeathSocket/Domain.fs index 67b71c1..e181d0c 100644 --- a/DeathSocket/Domain.fs +++ b/DeathSocket/Domain.fs @@ -1,11 +1,12 @@ namespace DeathSocket + [] module Domain = open System.Drawing - + type ImageSpec = - { filePath: string; + { originalPath: string; savePath: string; colour: Brush; penWidth: float32 diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index e1c2b8d..643ba5b 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -1,11 +1,16 @@ namespace DeathSocket + open System.IO + module GridPainter = open Validation open ImageServices - let applyGridToImage spec = - validateFilePath |> ignore - drawGrid spec - 0 \ No newline at end of file + let applyGrid spec = + try + validateFilePath |> ignore + drawGrid spec |> ignore + with + | :? FileNotFoundException as ex -> printfn"%s" ex.Message + \ No newline at end of file diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index 19297d8..05815bf 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -1,34 +1,32 @@ module internal ImageServices -open System.Drawing -open DeathSocket.Domain -open System.Drawing.Imaging + open System.Drawing + open System.Drawing.Imaging + open DeathSocket - let createHorizontalLines width height columns = - let interval = width / columns - [| for point in 1 .. columns -> + let createHorizontalLines width height rows = + let interval = width / rows + [| for point in 1 .. (rows - 1) -> [|Point (0, (interval * point)) Point (height, (interval * point) )|]|] - let createVerticalLines width height columns = + let createVerticalLines height columns = let interval = height / columns - [| for point in 1 .. columns -> + [| for point in 1 .. (columns - 1) -> [| Point ((interval * point), 0) Point ((interval * point), height)|]|] let drawGrid spec = - let img = Bitmap.FromFile spec.filePath + let img = Bitmap.FromFile spec.originalPath let graphics = Graphics.FromImage img let pen = new Pen (spec.colour, width = spec.penWidth) let horizontalLines = createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns) - let verticalLines = - createVerticalLines (img.Size.Width) (img.Size.Height) (spec.columns) + let verticalLines = createVerticalLines (img.Size.Height) (spec.columns) for line in horizontalLines do graphics.DrawLines (pen, line) for line in verticalLines do graphics.DrawLines (pen, line) img.Save (spec.savePath, ImageFormat.Png) img.Dispose () graphics.Dispose () pen.Dispose () - 0 - + () \ No newline at end of file diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index 1c3530e..11d4f84 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -6,7 +6,6 @@ open System.Drawing open System open DeathSocket -open Domain open Validation open ImageServices @@ -52,9 +51,9 @@ let validationTest = validateFilePath testSavePath let horizontalLines = createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10 let verticalLines = - createVerticalLines (testImg.Size.Width) (testImg.Size.Height) 10 + createVerticalLines (testImg.Size.Height) 10 let spec = - { filePath = testImagePath + { originalPath = testImagePath savePath = testSavePath colour = Brushes.Red penWidth = float32 (10) diff --git a/DeathSocket/Validation.fs b/DeathSocket/Validation.fs index 86b075a..cf34e74 100644 --- a/DeathSocket/Validation.fs +++ b/DeathSocket/Validation.fs @@ -5,6 +5,5 @@ open System.IO let validateFilePath path = match File.Exists path with | true -> () - | false -> - invalidArg "File Path" "The image can not be loaded because the file path specified does not exist." + | false -> raise (new FileNotFoundException (path + "could not be found."))