From 4f0c89e5cf5d927d11d1410e7ee93a3ce21901ac Mon Sep 17 00:00:00 2001 From: Arnoud Buzing Date: Fri, 26 Jan 2018 14:27:26 -0600 Subject: [PATCH] Start of refactor: Prototypes.wl is becoming too large, so splitting off related prototype functions (like String* functions) into their own files. --- Prototypes/Dataset.wl | 7 ++++++ Prototypes/Image.wl | 26 ++++++++++++++++++++ Prototypes/Paclet.wl | 3 +++ Prototypes/PacletInfo.m | 2 +- Prototypes/Prototypes.wl | 51 ++++++++++------------------------------ Prototypes/String.wl | 5 ++++ 6 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 Prototypes/Dataset.wl create mode 100644 Prototypes/Image.wl create mode 100644 Prototypes/Paclet.wl create mode 100644 Prototypes/String.wl diff --git a/Prototypes/Dataset.wl b/Prototypes/Dataset.wl new file mode 100644 index 0000000..223e840 --- /dev/null +++ b/Prototypes/Dataset.wl @@ -0,0 +1,7 @@ +(* dataset extensions *) + +DatasetMap[ func_ , expr_ ] := Dataset[ AssociationMap[ func, expr ] ] + +DatasetImport[ file_, a___] := Dataset[ Import[ file, a ] ] + +DatasetImportFiles[ files_, a___] := Map[ Dataset, ImportFiles[ files, a]] diff --git a/Prototypes/Image.wl b/Prototypes/Image.wl new file mode 100644 index 0000000..7fcc5ed --- /dev/null +++ b/Prototypes/Image.wl @@ -0,0 +1,26 @@ +(* image extensions *) + +ImageStrictlyPortraitQ[image_Image] := Less @@ ImageDimensions[image] +ImageStrictlyPortraitQ[___] := False + +ImagePortraitQ[image_Image] := LessEqual @@ ImageDimensions[image] +ImagePortraitQ[___] := False + +ImageStrictlyLandscapeQ[image_Image] := Greater @@ ImageDimensions[image] +ImageStrictlyLandscapeQ[___] := False + +ImageLandscapeQ[image_Image] := GreaterEqual @@ ImageDimensions[image] +ImageLandscapeQ[___] := False + +ImageSquareQ[image_Image] := Equal @@ ImageDimensions[image] +ImageSquareQ[___] := False + +Image3DCubeQ[image_Image3D] := Equal @@ ImageDimensions[image] +Image3DCubeQ[___] := False + +ImageCropResize[image_Image, dims_List] := First[ ConformImages[ {image}, dims, "Fill"]] +ImageCropResize[___] := $Failed + +AlphaChannelQ[image_Image] := If[RemoveAlphaChannel[image] == image, False, True] +AlphaChannelQ[image_Image3D] := If[RemoveAlphaChannel[image] == image, False, True] +AlphaChannelQ[___] := False diff --git a/Prototypes/Paclet.wl b/Prototypes/Paclet.wl new file mode 100644 index 0000000..d675022 --- /dev/null +++ b/Prototypes/Paclet.wl @@ -0,0 +1,3 @@ +(* paclet *) + +PacletInformationDataset[paclet_String] := Dataset @ Association @ PacletInformation[paclet] diff --git a/Prototypes/PacletInfo.m b/Prototypes/PacletInfo.m index af07516..4337d03 100644 --- a/Prototypes/PacletInfo.m +++ b/Prototypes/PacletInfo.m @@ -3,7 +3,7 @@ Description -> "A paclet for prototype functions", Creator -> "Arnoud Buzing", Publisher -> "Wolfram Research", - Version -> "0.0.4", + Version -> "0.0.5", MathematicaVersion -> "11.2+", Loading -> Automatic, Extensions -> { diff --git a/Prototypes/Prototypes.wl b/Prototypes/Prototypes.wl index 89ba8ab..78f4335 100644 --- a/Prototypes/Prototypes.wl +++ b/Prototypes/Prototypes.wl @@ -71,7 +71,8 @@ PacletInformationDataset::usage = "PacletInformationDataset[paclet] returns pacl (* github utilities *) BuildWikiDocumentation::usage = "BuildWikiDocumentation[directory,context] creates wiki pages for the symbols in the given context"; -BuildInfo::usage = "BuildInfo[] copies build information to the clipboard and returns a button which does the same copy operation" +BuildInfo::usage = "BuildInfo[] copies build information to the clipboard and returns a button which does the same copy operation"; + Begin["`Private`"] (* general extensions *) @@ -80,7 +81,7 @@ InformationDataset[pattern_] := Dataset[Association[ Map[ Function[ # -> ToExpr (* file extensions *) -$InputDirectoryName := DirectoryName[$InputDirectoryName]; +$InputDirectoryName := DirectoryName[$InputFileName]; ImportFiles[ files_List, a___ ] := Map[ Function[ Import[ #, a ] ], files ] @@ -131,49 +132,24 @@ MinBy[ data_, func_ ] := By[ Min, data, func ] Rarest[ data_ ] := MinimalBy[Tally[data], Last][[All, 1]] RarestBy[ data_, func_ ] := By[ Rarest, data, func] -(* dataset extensions *) -DatasetMap[ func_ , expr_ ] := Dataset[ AssociationMap[ func, expr ] ] +(* load dataset prototype functions *) +Get[ FileNameJoin[{DirectoryName[$InputFileName], "Dataset.wl"}] ] -DatasetImport[ file_, a___] := Dataset[ Import[ file, a ] ] +(* load string prototype functions *) +Get[ FileNameJoin[{DirectoryName[$InputFileName], "Dataset.wl"}] ] -DatasetImportFiles[ files_, a___] := Map[ Dataset, ImportFiles[ files, a]] +(* load image processing prototype functions *) +Get[ FileNameJoin[{DirectoryName[$InputFileName], "Image.wl"}] ] -(* strings *) +(* load paclet prototype functions *) +Get[ FileNameJoin[{DirectoryName[$InputFileName], "Image.wl"}] ] -StringRest[string_String] := StringTake[string,{2,-1}] -StringMost[string_String] := StringTake[string,{1,-2}] (* random extensions *) RandomGeoPosition[] := GeoPosition[{RandomReal[{-90, 90}], RandomReal[{-180, 180}]}] -(* image extensions *) - -ImageStrictlyPortraitQ[image_Image] := Less @@ ImageDimensions[image] -ImageStrictlyPortraitQ[___] := False - -ImagePortraitQ[image_Image] := LessEqual @@ ImageDimensions[image] -ImagePortraitQ[___] := False - -ImageStrictlyLandscapeQ[image_Image] := Greater @@ ImageDimensions[image] -ImageStrictlyLandscapeQ[___] := False - -ImageLandscapeQ[image_Image] := GreaterEqual @@ ImageDimensions[image] -ImageLandscapeQ[___] := False - -ImageSquareQ[image_Image] := Equal @@ ImageDimensions[image] -ImageSquareQ[___] := False - -Image3DCubeQ[image_Image3D] := Equal @@ ImageDimensions[image] -Image3DCubeQ[___] := False - -ImageCropResize[image_Image, dims_List] := First[ ConformImages[ {image}, dims, "Fill"]] -ImageCropResize[___] := $Failed - -AlphaChannelQ[image_Image] := If[RemoveAlphaChannel[image] == image, False, True] -AlphaChannelQ[image_Image3D] := If[RemoveAlphaChannel[image] == image, False, True] -AlphaChannelQ[___] := False (* date *) @@ -193,11 +169,10 @@ Round[d_DateObject, q_Quantity] ^:= DateObject[ Round[AbsoluteTime[d], Quantit Uniconize[icon_IconizedObject] := First[icon] -(* paclet build utilities *) -PacletInformationDataset[paclet_String] := Dataset @ Association @ PacletInformation[paclet] -(* gihub utilities *) + +(* github utilities *) BuildWikiDocumentation[directory_String, context_String] := Module[{names, file}, diff --git a/Prototypes/String.wl b/Prototypes/String.wl new file mode 100644 index 0000000..eef022a --- /dev/null +++ b/Prototypes/String.wl @@ -0,0 +1,5 @@ +(* strings *) + +StringRest[string_String] := StringTake[string,{2,-1}] + +StringMost[string_String] := StringTake[string,{1,-2}]