Browse Source

update DeathSocket.fsproj.

master
Craig Oates 5 years ago
parent
commit
1be66fecca
  1. 1
      DeathSocket/DeathSocket.fsproj
  2. 1
      DeathSocket/GridPainter.fs
  3. 66
      DeathSocket/ImagePrep.fs
  4. 31
      DeathSocket/ValidationServices.fs

1
DeathSocket/DeathSocket.fsproj

@ -25,6 +25,7 @@
<Compile Include="Domain.fs" />
<Compile Include="ValidationServices.fs" />
<Compile Include="ColourServices.fs" />
<Compile Include="ImagePrep.fs" />
<Compile Include="ImageServices.fs" />
<Compile Include="GridPainter.fs" />
<None Include="ScratchPad.fsx" />

1
DeathSocket/GridPainter.fs

@ -14,6 +14,7 @@ namespace DeathSocket
module GridPainter =
open ValidationServices
open ImagePrep
open ImageServices
open SkiaSharp

66
DeathSocket/ImagePrep.fs

@ -0,0 +1,66 @@
module internal ImagePrep
open System.IO
open DeathSocket
open SkiaSharp
open System.Drawing
let determineLongestDimension pDims aDims =
let width = (fst pDims) - (fst aDims)
let height = (snd pDims) - (snd aDims)
match width > height with
| true -> Width
| false -> Height
let determineImageScale pDimension aDimension =
(double aDimension) / (double pDimension)
let determineLineScale (lineWidth: double) (scale: double) =
lineWidth / scale
let adjustLineThickness pDimensions aDimensions lineWidth =
match (determineLongestDimension pDimensions aDimensions) with
| Width ->
let thickness =
determineImageScale (fst pDimensions) (fst aDimensions)
|> determineLineScale lineWidth
thickness
| Height ->
let thickness =
determineImageScale (snd pDimensions) (snd aDimensions)
|> determineLineScale lineWidth
thickness
let createSKHorizontalLines width height rows =
let interval = float32 (height / rows)
[|for point in 1 .. (rows - 1) ->
[| SKPoint ((float32 0), (interval * (float32 point)))
SKPoint ((float32 width), (interval * (float32 point)))|]|]
let createSKVerticalLines width height columns =
let interval = float32 (width / columns)
[| for point in 1 .. (columns - 1) ->
[| SKPoint ((interval * (float32 point)), (float32 0))
SKPoint ((interval * (float32 point)), (float32 height))|]|]
let determineSkiaDimensions filePath =
use fileStream = File.Open (filePath, FileMode.Open)
use skStream = new SKManagedStream (fileStream)
use bitmap = SKBitmap.Decode (skStream)
(bitmap.Width, bitmap.Height)
let createHorizontalLines width height rows =
let interval = height / rows
[| for point in 1 .. (rows - 1) ->
[|Point (0, (interval * point))
Point (width, (interval * point) )|]|]
let createVerticalLines width height columns =
let interval = width / columns
[| for point in 1 .. (columns - 1) ->
[| Point ((interval * point), 0)
Point ((interval * point), height)|]|]
let determineSystemDrawingDimensions filePath =
use bitmap = Bitmap.FromFile filePath
(bitmap.Width, bitmap.Height)

31
DeathSocket/ValidationServices.fs

@ -0,0 +1,31 @@
module internal ValidationServices
open System.IO
let validateFilePath path =
match File.Exists path with
| true -> ()
| false -> raise (new FileNotFoundException ("No file found at " + path))
let validateSaveFileType file =
match Path.GetExtension file with
| ".jpg" -> ()
| ".JPG" -> ()
| ".png" -> ()
| ".PNG" -> ()
| _ -> invalidArg "savePath" "The file type must be a .jpg or .png file."
let validateIO iPath oPath =
validateFilePath iPath
validateSaveFileType oPath
let validateDimensions dimensions =
match dimensions with
| (0, _) -> invalidArg "Width" "Width must be greater than 0."
| (_, 0) -> invalidArg "Height" "Height must be greater than 0."
| (_, _) -> ()
let validateLineThickness thickness =
match thickness with
| thickness when thickness <= 0.0 -> invalidArg "LineThickness" "LineThickness must be greater than 0."
| _ -> ()
Loading…
Cancel
Save