diff --git a/DeathSocket/Domain.fs b/DeathSocket/Domain.fs index 4bde64e..18bc1a6 100644 --- a/DeathSocket/Domain.fs +++ b/DeathSocket/Domain.fs @@ -97,7 +97,7 @@ ///The number of columns the grid will have. columns: int } - /// Discriminated Union representing the various specification types + /// A Discriminated Union representing the various specification types /// Death Socket can use to apply a grid to an image. type ImageSpec = | Brush of BrushSpec @@ -105,9 +105,14 @@ | Skia of SkiaSpec | SkiaRGB of SkiaRGBSpec - /// Discriminated Union representing the graphics libraries used by - /// Death Socket. Useful for selecting which one you want to use. - /// System.Drawing for using Windows/Mono and SkiaSharp for Xamarin. + /// A Discriminated Union representing a type of image. The type refers + /// to the graphics library used to read the image file. + /// The graphics library determines how the image is stored in memory + /// and the functions you can perform on it. + /// When creating an ImageType, pass in the file path of the image + /// as a string. If you are on Windows or using Mono, SystemDrawing is + /// the recommended choice. If you using Xamarin, SkiaSharp is the + /// recommended choice. type ImageType = | SkiaSharp of string | SystemDrawing of string \ No newline at end of file diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 726e2ae..4b986b1 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -51,8 +51,6 @@ namespace DeathSocket printfn "File could not be found at %s" ex.Message } - // NOT TESTED - /// /// Determines the current scale an image is viewed at (E.G. scaled /// preview in image viewer). The (pen) line thickness is then updated @@ -75,7 +73,7 @@ namespace DeathSocket /// you should not need to use this function when using them. /// let scaleLineThickness (previewDimension: double) (actualDimension: double) (lineThickness: double) = - lineThickness / (previewDimension / actualDimension) + setLineThickness previewDimension actualDimension lineThickness // NOT TESTED diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index 12cba6b..c6408c3 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -6,6 +6,12 @@ open DeathSocket open ColourServices open SkiaSharp + open System + + let setLineThickness pDimension aDimension lineWidth = + if (pDimension <= 0.0 || aDimension <= 0.0 || lineWidth <= 0.0) then + raise (new DivideByZeroException ("[ERROR] The images height and width must be greater than 0.")) + else lineWidth / (pDimension / aDimension) // SkiaSharp Functions // ======================================================================== diff --git a/TestCentre/LibraryTests.fs b/TestCentre/LibraryTests.fs index 0678e99..8a2462d 100644 --- a/TestCentre/LibraryTests.fs +++ b/TestCentre/LibraryTests.fs @@ -111,6 +111,8 @@ "reset" function to see all the images produced by this test. This will mean you will need to manually delete the images yourself if you do. *) + // scaleLineThickness + [] let ``Can apply grid to image and save it using BrushSpec`` () = resetSavingTestArea () @@ -219,6 +221,8 @@ module UnitTests = + // scaleLineThickness + open TestingHelpers open Xunit open DeathSocket @@ -254,4 +258,22 @@ [] let ``Divide By Zero Exception is thrown when 0 columns is used when determining vertical lines`` () = let result () = GridPainter.determineVerticalLines 100 100 0 + Assert.Throws(fun () -> result () |> ignore) + + [] + let ``Divide By Zero Exception is thrown when previewDimension is set to 0 when calling scaleLineThickness`` () = + let result () = + GridPainter.scaleLineThickness 0.0 1.0 1.0 + Assert.Throws(fun () -> result () |> ignore) + + [] + let ``Divide By Zero Exception is thrown when actualDimension is set to 0 when calling scaleLineThickness`` () = + let result () = + GridPainter.scaleLineThickness 1.0 0.0 1.0 + Assert.Throws(fun () -> result () |> ignore) + + [] + let ``Divide By Zero Exception is thrown when lineThickness is set to 0 when calling scaleLineThickness`` () = + let result () = + GridPainter.scaleLineThickness 1.0 1.0 0.0 Assert.Throws(fun () -> result () |> ignore) \ No newline at end of file