Browse Source

make minor changes to variable names in library.

Change the exeption code for file validation in library.
master
Craig Oates 6 years ago
parent
commit
2b432c09ae
  1. 5
      DeathSocket/Domain.fs
  2. 13
      DeathSocket/GridPainter.fs
  3. 24
      DeathSocket/ImageServices.fs
  4. 5
      DeathSocket/ScratchPad.fsx
  5. 3
      DeathSocket/Validation.fs

5
DeathSocket/Domain.fs

@ -1,11 +1,12 @@
namespace DeathSocket namespace DeathSocket
[<AutoOpen>]
module Domain = module Domain =
open System.Drawing open System.Drawing
type ImageSpec = type ImageSpec =
{ filePath: string; { originalPath: string;
savePath: string; savePath: string;
colour: Brush; colour: Brush;
penWidth: float32 penWidth: float32

13
DeathSocket/GridPainter.fs

@ -1,11 +1,16 @@
namespace DeathSocket namespace DeathSocket
open System.IO
module GridPainter = module GridPainter =
open Validation open Validation
open ImageServices open ImageServices
let applyGridToImage spec = let applyGrid spec =
validateFilePath |> ignore try
drawGrid spec validateFilePath |> ignore
0 drawGrid spec |> ignore
with
| :? FileNotFoundException as ex -> printfn"%s" ex.Message

24
DeathSocket/ImageServices.fs

@ -1,34 +1,32 @@
module internal ImageServices module internal ImageServices
open System.Drawing open System.Drawing
open DeathSocket.Domain open System.Drawing.Imaging
open System.Drawing.Imaging open DeathSocket
let createHorizontalLines width height columns = let createHorizontalLines width height rows =
let interval = width / columns let interval = width / rows
[| for point in 1 .. columns -> [| for point in 1 .. (rows - 1) ->
[|Point (0, (interval * point)) [|Point (0, (interval * point))
Point (height, (interval * point) )|]|] Point (height, (interval * point) )|]|]
let createVerticalLines width height columns = let createVerticalLines height columns =
let interval = height / columns let interval = height / columns
[| for point in 1 .. columns -> [| for point in 1 .. (columns - 1) ->
[| Point ((interval * point), 0) [| Point ((interval * point), 0)
Point ((interval * point), height)|]|] Point ((interval * point), height)|]|]
let drawGrid spec = let drawGrid spec =
let img = Bitmap.FromFile spec.filePath let img = Bitmap.FromFile spec.originalPath
let graphics = Graphics.FromImage img let graphics = Graphics.FromImage img
let pen = new Pen (spec.colour, width = spec.penWidth) let pen = new Pen (spec.colour, width = spec.penWidth)
let horizontalLines = let horizontalLines =
createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns) createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns)
let verticalLines = let verticalLines = createVerticalLines (img.Size.Height) (spec.columns)
createVerticalLines (img.Size.Width) (img.Size.Height) (spec.columns)
for line in horizontalLines do graphics.DrawLines (pen, line) for line in horizontalLines do graphics.DrawLines (pen, line)
for line in verticalLines do graphics.DrawLines (pen, line) for line in verticalLines do graphics.DrawLines (pen, line)
img.Save (spec.savePath, ImageFormat.Png) img.Save (spec.savePath, ImageFormat.Png)
img.Dispose () img.Dispose ()
graphics.Dispose () graphics.Dispose ()
pen.Dispose () pen.Dispose ()
0 ()

5
DeathSocket/ScratchPad.fsx

@ -6,7 +6,6 @@
open System.Drawing open System.Drawing
open System open System
open DeathSocket open DeathSocket
open Domain
open Validation open Validation
open ImageServices open ImageServices
@ -52,9 +51,9 @@ let validationTest = validateFilePath testSavePath
let horizontalLines = let horizontalLines =
createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10 createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10
let verticalLines = let verticalLines =
createVerticalLines (testImg.Size.Width) (testImg.Size.Height) 10 createVerticalLines (testImg.Size.Height) 10
let spec = let spec =
{ filePath = testImagePath { originalPath = testImagePath
savePath = testSavePath savePath = testSavePath
colour = Brushes.Red colour = Brushes.Red
penWidth = float32 (10) penWidth = float32 (10)

3
DeathSocket/Validation.fs

@ -5,6 +5,5 @@ open System.IO
let validateFilePath path = let validateFilePath path =
match File.Exists path with match File.Exists path with
| true -> () | true -> ()
| false -> | false -> raise (new FileNotFoundException (path + "could not be found."))
invalidArg "File Path" "The image can not be loaded because the file path specified does not exist."

Loading…
Cancel
Save