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
[<AutoOpen>]
module Domain =
open System.Drawing
type ImageSpec =
{ filePath: string;
{ originalPath: string;
savePath: string;
colour: Brush;
penWidth: float32

13
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
let applyGrid spec =
try
validateFilePath |> ignore
drawGrid spec |> ignore
with
| :? FileNotFoundException as ex -> printfn"%s" ex.Message

24
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
()

5
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)

3
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."))

Loading…
Cancel
Save