Skip to content

Commit

Permalink
# This is a combination of 3 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

:sparkles: add lock function

# This is the commit message #2:

:construction: add private members and functions

# This is the commit message #3:

:construction: remove unused open statements
  • Loading branch information
vexx32 committed Feb 18, 2019
1 parent 9340397 commit 7b08fc1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
60 changes: 54 additions & 6 deletions Module/PSWordCloudModule/NewWordCloudCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ open SkiaSharp
type NewWordCloudCommand() =
inherit PSCmdlet()

let mutable _resolvedPath = String.Empty
let mutable _resolvedBackgroundPath = String.Empty
let mutable _colors : SKColor list = []
//#region Static Members

//#region Static Parameters
static let _stopWords = [
"a";"about";"above";"after";"again";"against";"all";"am";"an";"and";"any";"are";"aren't";"as";"at";"be";
"because";"been";"before";"being";"below";"between";"both";"but";"by";"can't";"cannot";"could";"couldn't";
Expand Down Expand Up @@ -48,7 +45,28 @@ type NewWordCloudCommand() =
static let random =
if isNull _random then _random <- Random()
_random
//#endregion Static Parameters

//#endregion Static Members

let mutable _resolvedPath = String.Empty
let mutable _resolvedBackgroundPath = String.Empty

let mutable _colors : SKColor list = []

let mutable _fontScale = 1.0f

let mutable _wordProcessingTasks : Task<string list> list = []

let _progressId = random.Next()

(*
private float _paddingMultiplier
{
get => Padding * PADDING_BASE_SCALE;
}*)
//#endregion Static Members

//#region Parameters

Expand Down Expand Up @@ -190,4 +208,34 @@ type NewWordCloudCommand() =
member val public AllowOverflow : SwitchParameter = SwitchParameter(false)
with get, set

//#endregion Parameters
//#endregion Parameters

member private self.RandomFloat
with get() =
_randomLock
|> lock <| random.NextDouble
|> As<single>
|> single

member private self.NextColor
with get() =
match _colors with
| head :: tail ->
_colors <- tail
head
| [] ->
match self.ColorSet with
| head :: tail ->
_colors <- tail
head
| [] -> SKColors.Red

member private self.NextOrientation
with get() =
if not self.DisableRotation.IsPresent then
match self.RandomFloat with
| x when x > 0.75f -> WordOrientation.Vertical
| x when x > 0.5f -> WordOrientation.FlippedVertical
| _ -> WordOrientation.Horizontal
else
WordOrientation.Horizontal
13 changes: 8 additions & 5 deletions Module/PSWordCloudModule/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ namespace PSWordCloud

open System
open System.Collections
open System.Collections.Generic
open System.Collections.ObjectModel
open System.Linq
open System.Management.Automation
open System.Reflection
open System.Runtime.CompilerServices
open System.Threading
open SkiaSharp
open System.Management.Automation
open System.Collections.Generic

module Operators =
let inline (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x)
Expand Down Expand Up @@ -67,6 +63,13 @@ module Utils =

let As<'T> value = LanguagePrimitives.ConvertTo<'T>(value)

let lock (padlock : obj) task =
Monitor.Enter padlock
try
task
finally
Monitor.Exit padlock

module Extensions =
type SKPoint with
member self.Multiply factor = SKPoint(self.X * factor, self.Y * factor)
Expand Down

0 comments on commit 7b08fc1

Please sign in to comment.