diff --git a/.editorconfig b/.editorconfig index af1e5b44..f579ff5d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -161,6 +161,9 @@ csharp_style_deconstructed_variable_declaration = true:warning csharp_style_prefer_index_operator = true:warning csharp_style_prefer_range_operator = true:warning csharp_style_implicit_object_creation_when_type_is_apparent = true:error +# ReSharper inspection severities +resharper_arrange_object_creation_when_type_evident_highlighting = error +resharper_arrange_object_creation_when_type_not_evident_highlighting = error # "Null" checking preferences csharp_style_throw_expression = true:warning csharp_style_conditional_delegate_call = true:warning @@ -174,6 +177,9 @@ csharp_using_directive_placement = outside_namespace:warning csharp_prefer_static_local_function = true:warning # Primary constructor preferences csharp_style_prefer_primary_constructors = false:none +# Collection preferences +dotnet_style_prefer_collection_expression = true:error +resharper_use_collection_expression_highlighting =true:error ########################################## # Unnecessary Code Rules diff --git a/samples/DrawShapesWithImageSharp/ImageSharpLogo.cs b/samples/DrawShapesWithImageSharp/ImageSharpLogo.cs index 00bd3114..fd92011b 100644 --- a/samples/DrawShapesWithImageSharp/ImageSharpLogo.cs +++ b/samples/DrawShapesWithImageSharp/ImageSharpLogo.cs @@ -17,10 +17,10 @@ public static void SaveLogo(float size, string path) // the point are based on a 1206x1206 shape so size requires scaling from there float scalingFactor = size / 1206; - var center = new Vector2(603); + Vector2 center = new(603); // segment whose center of rotation should be - var segmentOffset = new Vector2(301.16968f, 301.16974f); + Vector2 segmentOffset = new(301.16968f, 301.16974f); IPath segment = new Polygon( new LinearLineSegment(new Vector2(230.54f, 361.0261f), new Vector2(5.8641942f, 361.46031f)), new CubicBezierLineSegment( @@ -30,7 +30,7 @@ public static void SaveLogo(float size, string path) new Vector2(78.26f, 97.0461f))).Translate(center - segmentOffset); // we need to create 6 of theses all rotated about the center point - var segments = new List(); + List segments = []; for (int i = 0; i < 6; i++) { float angle = i * ((float)Math.PI / 3); @@ -38,20 +38,20 @@ public static void SaveLogo(float size, string path) segments.Add(s); } - var colors = new List() - { + List colors = + [ Color.ParseHex("35a849"), Color.ParseHex("fcee21"), Color.ParseHex("ed7124"), Color.ParseHex("cb202d"), Color.ParseHex("5f2c83"), - Color.ParseHex("085ba7"), - }; + Color.ParseHex("085ba7") + ]; - var scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero); + Matrix3x2 scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero); int dimensions = (int)Math.Ceiling(size); - using (var img = new Image(dimensions, dimensions)) + using (Image img = new(dimensions, dimensions)) { img.Mutate(i => i.Fill(Color.Black)); img.Mutate(i => i.Fill(Color.ParseHex("e1e1e1ff"), new EllipsePolygon(center, 600f).Transform(scaler))); diff --git a/samples/DrawShapesWithImageSharp/Program.cs b/samples/DrawShapesWithImageSharp/Program.cs index 1ef095fd..ed838547 100644 --- a/samples/DrawShapesWithImageSharp/Program.cs +++ b/samples/DrawShapesWithImageSharp/Program.cs @@ -59,7 +59,7 @@ private static void OutputStars() private static void DrawText(string text) { FontFamily fam = SystemFonts.Get("Arial"); - var font = new Font(fam, 30); + Font font = new(fam, 30); TextOptions textOptions = new(font); IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions); @@ -87,7 +87,7 @@ private static void DrawText(string text, IPath path) private static void DrawFatL() { - var shape = new Polygon(new LinearLineSegment( + Polygon shape = new(new LinearLineSegment( new Vector2(8, 8), new Vector2(64, 8), new Vector2(64, 64), @@ -99,12 +99,12 @@ private static void DrawFatL() private static void DrawSerializedOPenSansLetterShape_a() { - const string path = @"36.57813x49.16406 35.41797x43.67969 35.41797x43.67969 35.13672x43.67969 35.13672x43.67969 34.41629x44.54843 33.69641x45.34412 32.97708x46.06674 32.2583x46.71631 31.54007x47.29282 30.82239x47.79626 30.10526x48.22665 29.38867x48.58398 29.38867x48.58398 28.65012x48.88474 27.86707x49.14539 27.03952x49.36594 26.16748x49.54639 25.25095x49.68674 24.28992x49.78699 23.28439x49.84714 22.23438x49.86719 22.23438x49.86719 21.52775x49.85564 20.84048x49.82104 20.17258x49.76337 19.52405x49.68262 18.28506x49.4519 17.12354x49.12891 16.03946x48.71362 15.03284x48.20605 14.10367x47.6062 13.25195x46.91406 13.25195x46.91406 12.48978x46.13678 11.82922x45.28149 11.27029x44.34821 10.81299x43.33691 10.45731x42.24762 10.20325x41.08032 10.05081x39.83502 10.0127x39.18312 10x38.51172 10x38.51172 10.01823x37.79307 10.07292x37.09613 10.16407x36.42088 10.29169x35.76733 10.6563x34.52533 11.16675x33.37012 11.82304x32.3017 12.62518x31.32007 13.57317x30.42523 14.10185x30.01036 14.66699x29.61719 15.2686x29.24571 15.90666x28.89594 16.58119x28.56786 17.29218x28.26147 18.03962x27.97679 18.82353x27.71381 19.6439x27.47252 20.50073x27.25293 22.32378x26.87885 24.29266x26.59155 26.40739x26.39105 28.66797x26.27734 28.66797x26.27734 35.20703x26.06641 35.20703x26.06641 35.20703x23.67578 35.20703x23.67578 35.17654x22.57907 35.08508x21.55652 34.93265x20.60812 34.71924x19.73389 34.44485x18.93381 34.1095x18.20789 33.71317x17.55612 33.25586x16.97852 33.25586x16.97852 32.73154x16.47177 32.13416x16.03259 31.46371x15.66098 30.72021x15.35693 29.90366x15.12045 29.01404x14.95154 28.05136x14.85019 27.01563x14.81641 27.01563x14.81641 25.79175x14.86255 24.52832x15.00098 23.88177x15.1048 23.22534x15.23169 21.88281x15.55469 20.50073x15.96997 19.0791x16.47754 17.61792x17.07739 16.11719x17.76953 16.11719x17.76953 14.32422x13.30469 14.32422x13.30469 15.04465x12.92841 15.7821x12.573 17.30811x11.9248 18.90222x11.36011 20.56445x10.87891 20.56445x10.87891 22.26184x10.49438 23.96143x10.21973 24.81204x10.1236 25.66321x10.05493 26.51492x10.01373 27.36719x10 27.36719x10 29.03409x10.04779 29.82572x10.10753 30.58948x10.19116 31.32536x10.29869 32.03336x10.43011 32.71348x10.58543 33.36572x10.76465 34.58658x11.19476 35.69592x11.72046 36.69376x12.34174 37.58008x13.05859 37.58008x13.05859 38.35873x13.88092 39.03357x14.8186 39.60458x15.87164 40.07178x17.04004 40.26644x17.6675 40.43515x18.32379 40.5779x19.00893 40.6947x19.7229 40.78555x20.46571 40.85043x21.23737 40.88937x22.03786 40.90234x22.86719 40.90234x22.86719 40.90234x49.16406 + const string path = @"36.57813x49.16406 35.41797x43.67969 35.41797x43.67969 35.13672x43.67969 35.13672x43.67969 34.41629x44.54843 33.69641x45.34412 32.97708x46.06674 32.2583x46.71631 31.54007x47.29282 30.82239x47.79626 30.10526x48.22665 29.38867x48.58398 29.38867x48.58398 28.65012x48.88474 27.86707x49.14539 27.03952x49.36594 26.16748x49.54639 25.25095x49.68674 24.28992x49.78699 23.28439x49.84714 22.23438x49.86719 22.23438x49.86719 21.52775x49.85564 20.84048x49.82104 20.17258x49.76337 19.52405x49.68262 18.28506x49.4519 17.12354x49.12891 16.03946x48.71362 15.03284x48.20605 14.10367x47.6062 13.25195x46.91406 13.25195x46.91406 12.48978x46.13678 11.82922x45.28149 11.27029x44.34821 10.81299x43.33691 10.45731x42.24762 10.20325x41.08032 10.05081x39.83502 10.0127x39.18312 10x38.51172 10x38.51172 10.01823x37.79307 10.07292x37.09613 10.16407x36.42088 10.29169x35.76733 10.6563x34.52533 11.16675x33.37012 11.82304x32.3017 12.62518x31.32007 13.57317x30.42523 14.10185x30.01036 14.66699x29.61719 15.2686x29.24571 15.90666x28.89594 16.58119x28.56786 17.29218x28.26147 18.03962x27.97679 18.82353x27.71381 19.6439x27.47252 20.50073x27.25293 22.32378x26.87885 24.29266x26.59155 26.40739x26.39105 28.66797x26.27734 28.66797x26.27734 35.20703x26.06641 35.20703x26.06641 35.20703x23.67578 35.20703x23.67578 35.17654x22.57907 35.08508x21.55652 34.93265x20.60812 34.71924x19.73389 34.44485x18.93381 34.1095x18.20789 33.71317x17.55612 33.25586x16.97852 33.25586x16.97852 32.73154x16.47177 32.13416x16.03259 31.46371x15.66098 30.72021x15.35693 29.90366x15.12045 29.01404x14.95154 28.05136x14.85019 27.01563x14.81641 27.01563x14.81641 25.79175x14.86255 24.52832x15.00098 23.88177x15.1048 23.22534x15.23169 21.88281x15.55469 20.50073x15.96997 19.0791x16.47754 17.61792x17.07739 16.11719x17.76953 16.11719x17.76953 14.32422x13.30469 14.32422x13.30469 15.04465x12.92841 15.7821x12.573 17.30811x11.9248 18.90222x11.36011 20.56445x10.87891 20.56445x10.87891 22.26184x10.49438 23.96143x10.21973 24.81204x10.1236 25.66321x10.05493 26.51492x10.01373 27.36719x10 27.36719x10 29.03409x10.04779 29.82572x10.10753 30.58948x10.19116 31.32536x10.29869 32.03336x10.43011 32.71348x10.58543 33.36572x10.76465 34.58658x11.19476 35.69592x11.72046 36.69376x12.34174 37.58008x13.05859 37.58008x13.05859 38.35873x13.88092 39.03357x14.8186 39.60458x15.87164 40.07178x17.04004 40.26644x17.6675 40.43515x18.32379 40.5779x19.00893 40.6947x19.7229 40.78555x20.46571 40.85043x21.23737 40.88937x22.03786 40.90234x22.86719 40.90234x22.86719 40.90234x49.16406 23.39453x45.05078 24.06655x45.03911 24.72031x45.00409 25.97302x44.86401 27.15268x44.63055 28.25928x44.30371 29.29282x43.88348 30.2533x43.36987 31.14072x42.76288 31.95508x42.0625 31.95508x42.0625 32.6843x41.27808 33.31628x40.41895 33.85104x39.48511 34.28857x38.47656 34.62888x37.39331 34.87195x36.23535 35.01779x35.00269 35.06641x33.69531 35.06641x33.69531 35.06641x30.21484 35.06641x30.21484 29.23047x30.46094 29.23047x30.46094 27.55093x30.54855 25.9928x30.68835 24.55606x30.88034 23.24072x31.12451 22.04678x31.42087 20.97424x31.76941 20.0231x32.17014 19.19336x32.62305 19.19336x32.62305 18.47238x33.13528 17.84753x33.71399 17.31882x34.35916 16.88623x35.0708 16.54977x35.84891 16.30945x36.69348 16.16525x37.60452 16.11719x38.58203 16.11719x38.58203 16.14713x39.34943 16.23694x40.06958 16.38663x40.74249 16.59619x41.36816 17.19495x42.47778 18.0332x43.39844 18.0332x43.39844 19.08679x44.12134 19.68527x44.40533 20.33154x44.6377 21.0256x44.81842 21.76746x44.94751 22.5571x45.02496 23.39453x45.05078"; - string[] paths = path.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + string[] paths = path.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries); Polygon[] polys = paths.Select(line => { - string[] pl = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + string[] pl = line.Split([' '], StringSplitOptions.RemoveEmptyEntries); PointF[] points = pl.Select(p => p.Split('x')) .Select(p => new PointF(float.Parse(p[0]), float.Parse(p[1]))) @@ -112,18 +112,18 @@ private static void DrawSerializedOPenSansLetterShape_a() return new Polygon(points); }).ToArray(); - var complex = new ComplexPolygon(polys); + ComplexPolygon complex = new(polys); complex.SaveImage("letter", "a.png"); } private static void DrawSerializedOPenSansLetterShape_o() { - const string path = @"45.40234x29.93359 45.3838x31.09519 45.32819x32.22452 45.23549x33.32157 45.10571x34.38635 44.93886x35.41886 44.73492x36.4191 44.49391x37.38706 44.21582x38.32275 43.90065x39.22617 43.5484x40.09732 43.15907x40.9362 42.73267x41.7428 42.26918x42.51713 41.76862x43.25919 41.23097x43.96897 40.65625x44.64648 40.65625x44.64648 40.04884x45.28719 39.41315x45.88657 38.74916x46.4446 38.05688x46.9613 37.33632x47.43667 36.58746x47.8707 35.81032x48.26339 35.00488x48.61475 34.17116x48.92477 33.30914x49.19345 32.41884x49.4208 31.50024x49.60681 30.55336x49.75149 29.57819x49.85483 28.57472x49.91683 27.54297x49.9375 27.54297x49.9375 26.2691x49.8996 25.03149x49.78589 23.83014x49.59637 22.66504x49.33105 21.53619x48.98993 20.4436x48.573 19.38727x48.08026 18.36719x47.51172 18.36719x47.51172 17.3938x46.87231 16.47754x46.16699 15.61841x45.39575 14.81641x44.55859 14.07153x43.65552 13.38379x42.68652 12.75317x41.65161 12.17969x40.55078 12.17969x40.55078 11.66882x39.39282 11.22607x38.18652 10.85144x36.93188 10.54492x35.62891 10.30652x34.27759 10.13623x32.87793 10.03406x31.42993 10x29.93359 10x29.93359 10.0184x28.77213 10.07361x27.64322 10.16562x26.54685 10.29443x25.48303 10.46005x24.45176 10.66248x23.45303 10.9017x22.48685 11.17773x21.55322 11.49057x20.65214 11.84021x19.7836 12.22665x18.94761 12.6499x18.14417 13.10995x17.37327 13.60681x16.63492 14.14047x15.92912 14.71094x15.25586 14.71094x15.25586 15.31409x14.61941 15.9458x14.02402 16.60608x13.46969 17.29492x12.95642 18.01233x12.48421 18.7583x12.05307 19.53284x11.66299 20.33594x11.31396 21.1676x11.006 22.02783x10.73911 22.91663x10.51327 23.83398x10.32849 24.77991x10.18478 25.75439x10.08212 26.75745x10.02053 27.78906x10 27.78906x10 28.78683x10.02101 29.75864x10.08405 30.70449x10.1891 31.62439x10.33618 32.51833x10.52528 33.38632x10.75641 34.22836x11.02956 35.04443x11.34473 35.83456x11.70192 36.59872x12.10114 37.33694x12.54237 38.04919x13.02563 38.7355x13.55092 39.39584x14.11823 40.03024x14.72755 40.63867x15.37891 40.63867x15.37891 41.21552x16.0661 41.75516x16.78296 42.25757x17.52948 42.72278x18.30566 43.15077x19.11151 43.54153x19.94702 43.89509x20.81219 44.21143x21.70703 44.49055x22.63153 44.73245x23.58569 44.93714x24.56952 45.10461x25.58301 45.23487x26.62616 45.32791x27.69897 45.38374x28.80145 45.40234x29.93359 + const string path = @"45.40234x29.93359 45.3838x31.09519 45.32819x32.22452 45.23549x33.32157 45.10571x34.38635 44.93886x35.41886 44.73492x36.4191 44.49391x37.38706 44.21582x38.32275 43.90065x39.22617 43.5484x40.09732 43.15907x40.9362 42.73267x41.7428 42.26918x42.51713 41.76862x43.25919 41.23097x43.96897 40.65625x44.64648 40.65625x44.64648 40.04884x45.28719 39.41315x45.88657 38.74916x46.4446 38.05688x46.9613 37.33632x47.43667 36.58746x47.8707 35.81032x48.26339 35.00488x48.61475 34.17116x48.92477 33.30914x49.19345 32.41884x49.4208 31.50024x49.60681 30.55336x49.75149 29.57819x49.85483 28.57472x49.91683 27.54297x49.9375 27.54297x49.9375 26.2691x49.8996 25.03149x49.78589 23.83014x49.59637 22.66504x49.33105 21.53619x48.98993 20.4436x48.573 19.38727x48.08026 18.36719x47.51172 18.36719x47.51172 17.3938x46.87231 16.47754x46.16699 15.61841x45.39575 14.81641x44.55859 14.07153x43.65552 13.38379x42.68652 12.75317x41.65161 12.17969x40.55078 12.17969x40.55078 11.66882x39.39282 11.22607x38.18652 10.85144x36.93188 10.54492x35.62891 10.30652x34.27759 10.13623x32.87793 10.03406x31.42993 10x29.93359 10x29.93359 10.0184x28.77213 10.07361x27.64322 10.16562x26.54685 10.29443x25.48303 10.46005x24.45176 10.66248x23.45303 10.9017x22.48685 11.17773x21.55322 11.49057x20.65214 11.84021x19.7836 12.22665x18.94761 12.6499x18.14417 13.10995x17.37327 13.60681x16.63492 14.14047x15.92912 14.71094x15.25586 14.71094x15.25586 15.31409x14.61941 15.9458x14.02402 16.60608x13.46969 17.29492x12.95642 18.01233x12.48421 18.7583x12.05307 19.53284x11.66299 20.33594x11.31396 21.1676x11.006 22.02783x10.73911 22.91663x10.51327 23.83398x10.32849 24.77991x10.18478 25.75439x10.08212 26.75745x10.02053 27.78906x10 27.78906x10 28.78683x10.02101 29.75864x10.08405 30.70449x10.1891 31.62439x10.33618 32.51833x10.52528 33.38632x10.75641 34.22836x11.02956 35.04443x11.34473 35.83456x11.70192 36.59872x12.10114 37.33694x12.54237 38.04919x13.02563 38.7355x13.55092 39.39584x14.11823 40.03024x14.72755 40.63867x15.37891 40.63867x15.37891 41.21552x16.0661 41.75516x16.78296 42.25757x17.52948 42.72278x18.30566 43.15077x19.11151 43.54153x19.94702 43.89509x20.81219 44.21143x21.70703 44.49055x22.63153 44.73245x23.58569 44.93714x24.56952 45.10461x25.58301 45.23487x26.62616 45.32791x27.69897 45.38374x28.80145 45.40234x29.93359 16.04688x29.93359 16.09302x31.72437 16.23145x33.40527 16.33527x34.20453 16.46216x34.97632 16.61212x35.72064 16.78516x36.4375 16.98126x37.12689 17.20044x37.78882 17.44269x38.42328 17.70801x39.03027 18.30786x40.16187 19x41.18359 19x41.18359 19.78168x42.08997 20.65015x42.87549 21.60541x43.54016 22.64746x44.08398 23.77631x44.50696 24.99194x44.80908 26.29437x44.99036 26.97813x45.03568 27.68359x45.05078 27.68359x45.05078 28.38912x45.03575 29.07309x44.99063 30.37634x44.81018 31.59335x44.50943 32.72412x44.08838 33.76865x43.54703 34.72693x42.88538 35.59897x42.10342 36.38477x41.20117 36.38477x41.20117 37.08102x40.18301 37.68445x39.05334 37.95135x38.44669 38.19504x37.81216 38.41552x37.14976 38.61279x36.45947 38.78686x35.74131 38.93771x34.99527 39.06536x34.22135 39.1698x33.41956 39.30905x31.73233 39.35547x29.93359 39.35547x29.93359 39.30905x28.15189 39.1698x26.48059 39.06536x25.68635 38.93771x24.91971 38.78686x24.18067 38.61279x23.46924 38.41552x22.78541 38.19504x22.12918 37.95135x21.50056 37.68445x20.89954 37.08102x19.7803 36.38477x18.77148 36.38477x18.77148 35.59787x17.87747 34.72253x17.10266 33.75876x16.44705 32.70654x15.91064 31.56589x15.49344 30.33679x15.19543 29.68908x15.09113 29.01926x15.01663 28.32732x14.97193 27.61328x14.95703 27.61328x14.95703 26.90796x14.97173 26.22461x15.01581 24.92383x15.19214 23.71094x15.48602 22.58594x15.89746 21.54883x16.42645 20.59961x17.073 19.73828x17.8371 18.96484x18.71875 18.96484x18.71875 18.28094x19.71686 17.68823x20.83032 17.42607x21.43031 17.18671x22.05914 16.97014x22.71681 16.77637x23.40332 16.60539x24.11867 16.45721x24.86285 16.33183x25.63588 16.22925x26.43774 16.09247x28.12799 16.04688x29.93359 "; - string[] paths = path.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + string[] paths = path.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries); Polygon[] polys = paths.Select(line => { - string[] pl = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + string[] pl = line.Split([' '], StringSplitOptions.RemoveEmptyEntries); PointF[] points = pl.Select(p => p.Split('x')) .Select(p => new PointF(float.Parse(p[0]), float.Parse(p[1]))) @@ -132,7 +132,7 @@ private static void DrawSerializedOPenSansLetterShape_o() return new Polygon(points); }).ToArray(); - var complex = new ComplexPolygon(polys); + ComplexPolygon complex = new(polys); complex.SaveImage("letter", "o.png"); } @@ -140,18 +140,17 @@ private static void DrawOval() => new EllipsePolygon(0, 0, 10, 20).Scale(5).SaveImage("Curves", "Ellipse.png"); private static void DrawArc() => new Polygon(new CubicBezierLineSegment( - new PointF[] - { - new PointF(10, 400), - new PointF(30, 10), - new PointF(240, 30), - new PointF(300, 400), - })).SaveImage(500, 500, "Curves", "Arc.png"); + [ + new(10, 400), + new(30, 10), + new(240, 30), + new(300, 400) + ])).SaveImage(500, 500, "Curves", "Arc.png"); private static void OutputDrawnShape() { // center the shape outerRadii + 10 px away from edges - var sb = new PathBuilder(); + PathBuilder sb = new(); // draw a 'V' sb.AddLines(new Vector2(10, 10), new Vector2(20, 20), new Vector2(30, 10)); @@ -168,7 +167,7 @@ private static void OutputDrawnShape() private static void OutputDrawnShapeHourGlass() { // center the shape outerRadii + 10 px away from edges - var sb = new PathBuilder(); + PathBuilder sb = new(); // draw a 'V' sb.AddLines(new Vector2(10, 10), new Vector2(20, 20), new Vector2(30, 10)); @@ -187,7 +186,7 @@ private static void OutputStarOutline(int points, float inner = 10, float outer // center the shape outerRadii + 10 px away from edges float offset = outer + 10; - var star = new Star(offset, offset, points, inner, outer); + Star star = new(offset, offset, points, inner, outer); IPath outline = star.GenerateOutline(width, jointStyle, EndCapStyle.Butt); outline.SaveImage("Stars", $"StarOutline_{points}_{jointStyle}.png"); } @@ -197,8 +196,8 @@ private static void OutputStarOutlineDashed(int points, float inner = 10, float // center the shape outerRadii + 10 px away from edges float offset = outer + 10; - var star = new Star(offset, offset, points, inner, outer); - IPath outline = star.GenerateOutline(width, new float[] { 3, 3 }, jointStyle, cap); + Star star = new(offset, offset, points, inner, outer); + IPath outline = star.GenerateOutline(width, [3, 3], jointStyle, cap); outline.SaveImage("Stars", $"StarOutlineDashed_{points}_{jointStyle}_{cap}.png"); } @@ -207,14 +206,14 @@ private static void OutputStar(int points, float inner = 10, float outer = 20) // center the shape outerRadii + 10 px away from edges float offset = outer + 10; - var star = new Star(offset, offset, points, inner, outer); + Star star = new(offset, offset, points, inner, outer); star.SaveImage("Stars", $"Star_{points}.png"); } private static void OutputClippedRectangle() { - var rect1 = new RectangularPolygon(10, 10, 40, 40); - var rect2 = new RectangularPolygon(20, 0, 20, 20); + RectangularPolygon rect1 = new(10, 10, 40, 40); + RectangularPolygon rect2 = new(20, 0, 20, 20); IPath paths = rect1.Clip(rect2); paths.SaveImage("Clipping", "RectangleWithTopClipped.png"); @@ -230,7 +229,7 @@ public static void SaveImage(this IPathCollection collection, params string[] pa int width = (int)(collection.Bounds.Left + collection.Bounds.Right); int height = (int)(collection.Bounds.Top + collection.Bounds.Bottom); - using var img = new Image(width, height); + using Image img = new(width, height); // Fill the canvas background and draw our shape img.Mutate(i => i.Fill(Color.DarkBlue)); @@ -251,11 +250,11 @@ public static void SaveImageWithPath(this IPathCollection collection, IPath shap shape = shape.Translate(-collection.Bounds.Location); collection = collection.Translate(-collection.Bounds.Location); - var bounds = RectangleF.Union(shape.Bounds, collection.Bounds); + RectangleF bounds = RectangleF.Union(shape.Bounds, collection.Bounds); int width = (int)(bounds.Left + bounds.Right); int height = (int)(bounds.Top + bounds.Bottom); - using var img = new Image(width, height); + using Image img = new(width, height); // Fill the canvas background and draw our shape img.Mutate(i => i.Fill(Color.DarkBlue).Fill(Color.White.WithAlpha(.25F), shape)); @@ -274,7 +273,7 @@ public static void SaveImage(this IPath shape, int width, int height, params str public static void SaveImage(this IPathCollection shape, int width, int height, params string[] path) { - using var img = new Image(width, height); + using Image img = new(width, height); img.Mutate(i => i.Fill(Color.DarkBlue)); img.Mutate(i => i.Fill(Color.HotPink, shape)); diff --git a/shared-infrastructure b/shared-infrastructure index 5e13cde8..d0f141ba 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit 5e13cde851a3d6e95d0dfdde2a57071f1efda9c3 +Subproject commit d0f141bad2baf7e256aa38ef18129c31cfb857a5 diff --git a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs index 1c40dd18..1629bdfa 100644 --- a/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Extensions/FillPathBuilderExtensions.cs @@ -67,7 +67,7 @@ public static IImageProcessingContext Fill( Brush brush, Action region) { - var pb = new PathBuilder(); + PathBuilder pb = new(); region(pb); return source.Fill(options, brush, pb.Build()); diff --git a/src/ImageSharp.Drawing/Processing/PatternBrush.cs b/src/ImageSharp.Drawing/Processing/PatternBrush.cs index 008add9d..60145fe5 100644 --- a/src/ImageSharp.Drawing/Processing/PatternBrush.cs +++ b/src/ImageSharp.Drawing/Processing/PatternBrush.cs @@ -54,8 +54,8 @@ public PatternBrush(Color foreColor, Color backColor, bool[,] pattern) /// The pattern. internal PatternBrush(Color foreColor, Color backColor, in DenseMatrix pattern) { - var foreColorVector = foreColor.ToScaledVector4(); - var backColorVector = backColor.ToScaledVector4(); + Vector4 foreColorVector = foreColor.ToScaledVector4(); + Vector4 backColorVector = backColor.ToScaledVector4(); this.pattern = new DenseMatrix(pattern.Columns, pattern.Rows); this.patternVector = new DenseMatrix(pattern.Columns, pattern.Rows); for (int i = 0; i < pattern.Data.Length; i++) diff --git a/src/ImageSharp.Drawing/Processing/Pens.cs b/src/ImageSharp.Drawing/Processing/Pens.cs index b2042ab3..b266b201 100644 --- a/src/ImageSharp.Drawing/Processing/Pens.cs +++ b/src/ImageSharp.Drawing/Processing/Pens.cs @@ -8,11 +8,11 @@ namespace SixLabors.ImageSharp.Drawing.Processing; /// public static class Pens { - private static readonly float[] DashDotPattern = { 3f, 1f, 1f, 1f }; - private static readonly float[] DashDotDotPattern = { 3f, 1f, 1f, 1f, 1f, 1f }; - private static readonly float[] DottedPattern = { 1f, 1f }; - private static readonly float[] DashedPattern = { 3f, 1f }; - internal static readonly float[] EmptyPattern = Array.Empty(); + private static readonly float[] DashDotPattern = [3f, 1f, 1f, 1f]; + private static readonly float[] DashDotDotPattern = [3f, 1f, 1f, 1f, 1f, 1f]; + private static readonly float[] DottedPattern = [1f, 1f]; + private static readonly float[] DashedPattern = [3f, 1f]; + internal static readonly float[] EmptyPattern = []; /// /// Create a solid pen without any drawing patterns diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/ClipPathProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/ClipPathProcessor{TPixel}.cs index c3ef3961..65aecbaf 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/ClipPathProcessor{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/ClipPathProcessor{TPixel}.cs @@ -41,8 +41,8 @@ public void Execute() RectangleF bounds = this.definition.Region.Bounds; // add some clamping offsets to the brush to account for the target drawing location due to the cloned image not fill the image as expected - var offsetX = 0; - var offsetY = 0; + int offsetX = 0; + int offsetY = 0; if (bounds.X < 0) { offsetX = -(int)MathF.Floor(bounds.X); @@ -53,10 +53,10 @@ public void Execute() offsetY = -(int)MathF.Floor(bounds.Y); } - var brush = new ImageBrush(clone, bounds, new Point(offsetX, offsetY)); + ImageBrush brush = new(clone, bounds, new Point(offsetX, offsetY)); // Grab hold of an image processor that can fill paths with a brush to allow it to do the hard pixel pushing for us - var processor = new FillPathProcessor(this.definition.Options, brush, this.definition.Region); + FillPathProcessor processor = new(this.definition.Options, brush, this.definition.Region); using IImageProcessor p = processor.CreatePixelSpecificProcessor(this.configuration, this.source, this.sourceRectangle); // Fill the shape using the image brush diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillPathProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillPathProcessor.cs index 63c11d64..477c3325 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillPathProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillPathProcessor.cs @@ -52,8 +52,8 @@ public IImageProcessor CreatePixelSpecificProcessor(Configuratio if (shape is RectangularPolygon rectPoly) { - var rectF = new RectangleF(rectPoly.Location, rectPoly.Size); - var rect = (Rectangle)rectF; + RectangleF rectF = new(rectPoly.Location, rectPoly.Size); + Rectangle rect = (Rectangle)rectF; if (!this.Options.GraphicsOptions.Antialias || rectF == rect) { // Cast as in and back are the same or we are using anti-aliasing @@ -63,7 +63,7 @@ public IImageProcessor CreatePixelSpecificProcessor(Configuratio } // Clone the definition so we can pass the transformed path. - var definition = new FillPathProcessor(this.Options, this.Brush, shape); + FillPathProcessor definition = new(this.Options, this.Brush, shape); return new FillPathProcessor(configuration, definition, source, sourceRectangle); } } diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs index 11b28ca3..65421276 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs @@ -118,7 +118,7 @@ private static RichTextOptions ConfigureOptions(RichTextOptions options) // and not adjust the origin. Any translation should be applied to the path. if (options.Path is not null && options.Origin != Vector2.Zero) { - return new(options) + return new RichTextOptions(options) { Origin = Vector2.Zero, Path = options.Path.Translate(options.Origin) diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs index db1fd377..bbecff60 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/RichTextGlyphRenderer.cs @@ -60,7 +60,7 @@ public RichTextGlyphRenderer( this.memoryAllocator = memoryAllocator; this.defaultPen = pen; this.defaultBrush = brush; - this.DrawingOperations = new List(); + this.DrawingOperations = []; IPath? path = textOptions.Path; if (path is not null) @@ -115,7 +115,7 @@ protected override void BeginGlyph(in FontRectangle bounds, in GlyphRendererPara // We need to apply the default transform to the bounds to get the correct size // for comparison with future glyphs. We can use this cached glyph anywhere in the text block. RectangleF currentBounds = RectangleF.Transform( - new RectangleF(bounds.Location, new(bounds.Width, bounds.Height)), + new RectangleF(bounds.Location, new SizeF(bounds.Width, bounds.Height)), this.drawingOptions.Transform); PointF currentBoundsDelta = currentBounds.Location - ClampToPixel(currentBounds.Location); @@ -233,12 +233,12 @@ public override void SetDecoration(TextDecorations textDecorations, Vector2 star if (textDecorations == TextDecorations.Overline) { // CSS overline is drawn above the position, so we need to move it up. - offset = rotated ? new(thickness * .5F, 0) : new(0, -(thickness * .5F)); + offset = rotated ? new Vector2(thickness * .5F, 0) : new Vector2(0, -(thickness * .5F)); } else if (textDecorations == TextDecorations.Underline) { // CSS underline is drawn below the position, so we need to move it down. - offset = rotated ? new(-(thickness * .5F), 0) : new(0, thickness * .5F); + offset = rotated ? new Vector2(-(thickness * .5F), 0) : new Vector2(0, thickness * .5F); } // We clamp the start and end points to the pixel grid to avoid anti-aliasing. @@ -421,7 +421,7 @@ private void FinalizeDecoration(ref TextDecorationDetails? decoration) // Calculate the transform for this path. // We cannot use the path builder transform as this path is rendered independently. - FontRectangle rectangle = new(outline.Bounds.Location, new(outline.Bounds.Width, outline.Bounds.Height)); + FontRectangle rectangle = new(outline.Bounds.Location, new Vector2(outline.Bounds.Width, outline.Bounds.Height)); Matrix3x2 pathTransform = this.ComputeTransform(in rectangle); Matrix3x2 defaultTransform = this.drawingOptions.Transform; outline = outline.Transform(pathTransform * defaultTransform); diff --git a/src/ImageSharp.Drawing/Processing/RecolorBrush.cs b/src/ImageSharp.Drawing/Processing/RecolorBrush.cs index 6e889ff7..6ad6a7dd 100644 --- a/src/ImageSharp.Drawing/Processing/RecolorBrush.cs +++ b/src/ImageSharp.Drawing/Processing/RecolorBrush.cs @@ -116,7 +116,7 @@ public RecolorBrushApplicator( { // Offset the requested pixel by the value in the rectangle (the shapes position) TPixel result = this.Target[x, y]; - var background = result.ToVector4(); + Vector4 background = result.ToVector4(); float distance = Vector4.DistanceSquared(background, this.sourceColor); if (distance <= this.threshold) { diff --git a/src/ImageSharp.Drawing/Processing/RichTextOptions.cs b/src/ImageSharp.Drawing/Processing/RichTextOptions.cs index e547e4bb..268592a6 100644 --- a/src/ImageSharp.Drawing/Processing/RichTextOptions.cs +++ b/src/ImageSharp.Drawing/Processing/RichTextOptions.cs @@ -16,7 +16,7 @@ public class RichTextOptions : TextOptions /// The font. public RichTextOptions(Font font) : base(font) - => this.TextRuns = Array.Empty(); + => this.TextRuns = []; /// /// Initializes a new instance of the class from properties diff --git a/src/ImageSharp.Drawing/Shapes/ArcLineSegment.cs b/src/ImageSharp.Drawing/Shapes/ArcLineSegment.cs index 2d4eed66..6e0b8d54 100644 --- a/src/ImageSharp.Drawing/Shapes/ArcLineSegment.cs +++ b/src/ImageSharp.Drawing/Shapes/ArcLineSegment.cs @@ -132,7 +132,7 @@ private static PointF[] EllipticArcFromEndParams( if (EllipticArcOutOfRange(from, to, radius)) { - return new[] { from, to }; + return [from, to]; } EndpointToCenterArcParams(from, to, ref absRadius, rotation, largeArc, sweep, out Vector2 center, out Vector2 angles); @@ -172,7 +172,7 @@ private static Vector2 EllipticArcPoint(Vector2 c, Vector2 r, float xAngle, floa private static PointF[] EllipticArcToBezierCurve(Vector2 from, Vector2 center, Vector2 radius, float xAngle, float startAngle, float sweepAngle) { - List points = new(); + List points = []; float s = startAngle; float e = s + sweepAngle; diff --git a/src/ImageSharp.Drawing/Shapes/ClipPathExtensions.cs b/src/ImageSharp.Drawing/Shapes/ClipPathExtensions.cs index fcd0c998..690d2291 100644 --- a/src/ImageSharp.Drawing/Shapes/ClipPathExtensions.cs +++ b/src/ImageSharp.Drawing/Shapes/ClipPathExtensions.cs @@ -43,7 +43,7 @@ public static IPath Clip( /// The clipped . /// Thrown when an error occurred while attempting to clip the polygon. public static IPath Clip(this IPath subjectPath, IEnumerable clipPaths) - => subjectPath.Clip(new(), clipPaths); + => subjectPath.Clip(new ShapeOptions(), clipPaths); /// /// Clips the specified subject path with the provided clipping paths. diff --git a/src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs b/src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs index 568165e0..1918e271 100644 --- a/src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs +++ b/src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs @@ -130,7 +130,7 @@ public IPath Transform(Matrix3x2 matrix) /// public IEnumerable Flatten() { - List paths = new(); + List paths = []; foreach (IPath path in this.Paths) { paths.AddRange(path.Flatten()); diff --git a/src/ImageSharp.Drawing/Shapes/CubicBezierLineSegment.cs b/src/ImageSharp.Drawing/Shapes/CubicBezierLineSegment.cs index 613a3e85..da898e2f 100644 --- a/src/ImageSharp.Drawing/Shapes/CubicBezierLineSegment.cs +++ b/src/ImageSharp.Drawing/Shapes/CubicBezierLineSegment.cs @@ -79,7 +79,7 @@ public CubicBezierLineSegment Transform(Matrix3x2 matrix) return this; } - var transformedPoints = new PointF[this.controlPoints.Length]; + PointF[] transformedPoints = new PointF[this.controlPoints.Length]; for (int i = 0; i < this.controlPoints.Length; i++) { @@ -94,7 +94,7 @@ public CubicBezierLineSegment Transform(Matrix3x2 matrix) private static PointF[] GetDrawingPoints(PointF[] controlPoints) { - var drawingPoints = new List(); + List drawingPoints = []; int curveCount = (controlPoints.Length - 1) / 3; for (int curveIndex = 0; curveIndex < curveCount; curveIndex++) @@ -115,7 +115,7 @@ private static PointF[] GetDrawingPoints(PointF[] controlPoints) private static List FindDrawingPoints(int curveIndex, PointF[] controlPoints) { - var pointList = new List(); + List pointList = []; Vector2 left = CalculateBezierPoint(curveIndex, 0, controlPoints); Vector2 right = CalculateBezierPoint(curveIndex, 1, controlPoints); @@ -154,8 +154,8 @@ private static int FindDrawingPoints( float midT = (t0 + t1) / 2; Vector2 mid = CalculateBezierPoint(curveIndex, midT, controlPoints); - var leftDirection = Vector2.Normalize(left - mid); - var rightDirection = Vector2.Normalize(right - mid); + Vector2 leftDirection = Vector2.Normalize(left - mid); + Vector2 rightDirection = Vector2.Normalize(right - mid); if (Vector2.Dot(leftDirection, rightDirection) > DivisionThreshold || Math.Abs(midT - 0.5f) < 0.0001f) { diff --git a/src/ImageSharp.Drawing/Shapes/EllipsePolygon.cs b/src/ImageSharp.Drawing/Shapes/EllipsePolygon.cs index 9d6588b8..fbdec0c6 100644 --- a/src/ImageSharp.Drawing/Shapes/EllipsePolygon.cs +++ b/src/ImageSharp.Drawing/Shapes/EllipsePolygon.cs @@ -95,7 +95,7 @@ SegmentInfo IPathInternals.PointAlongPath(float distance) /// IReadOnlyList IInternalPathOwner.GetRingsAsInternalPath() - => new[] { this.innerPath }; + => [this.innerPath]; private static CubicBezierLineSegment CreateSegment(Vector2 location, SizeF size) { @@ -116,7 +116,7 @@ private static CubicBezierLineSegment CreateSegment(Vector2 location, SizeF size Vector2 pointMplusO = pointM + pointO; PointF[] points = - { + [ new Vector2(rootLocation.X, pointM.Y), new Vector2(rootLocation.X, pointMminusO.Y), @@ -133,8 +133,8 @@ private static CubicBezierLineSegment CreateSegment(Vector2 location, SizeF size new Vector2(pointMminusO.X, pointE.Y), new Vector2(rootLocation.X, pointMplusO.Y), - new Vector2(rootLocation.X, pointM.Y), - }; + new Vector2(rootLocation.X, pointM.Y) + ]; return new CubicBezierLineSegment(points); } diff --git a/src/ImageSharp.Drawing/Shapes/EmptyPath.cs b/src/ImageSharp.Drawing/Shapes/EmptyPath.cs index fad40301..6789db39 100644 --- a/src/ImageSharp.Drawing/Shapes/EmptyPath.cs +++ b/src/ImageSharp.Drawing/Shapes/EmptyPath.cs @@ -15,12 +15,12 @@ public sealed class EmptyPath : IPath /// /// Gets the closed path instance of the empty path /// - public static EmptyPath ClosedPath { get; } = new EmptyPath(PathTypes.Closed); + public static EmptyPath ClosedPath { get; } = new(PathTypes.Closed); /// /// Gets the open path instance of the empty path /// - public static EmptyPath OpenPath { get; } = new EmptyPath(PathTypes.Open); + public static EmptyPath OpenPath { get; } = new(PathTypes.Open); /// public PathTypes PathType { get; } @@ -32,7 +32,7 @@ public sealed class EmptyPath : IPath public IPath AsClosedPath() => ClosedPath; /// - public IEnumerable Flatten() => Array.Empty(); + public IEnumerable Flatten() => []; /// public IPath Transform(Matrix3x2 matrix) => this; diff --git a/src/ImageSharp.Drawing/Shapes/Helpers/ArrayExtensions.cs b/src/ImageSharp.Drawing/Shapes/Helpers/ArrayExtensions.cs index 7ef7162b..1039818a 100644 --- a/src/ImageSharp.Drawing/Shapes/Helpers/ArrayExtensions.cs +++ b/src/ImageSharp.Drawing/Shapes/Helpers/ArrayExtensions.cs @@ -22,7 +22,7 @@ public static T[] Merge(this T[] source1, T[] source2) return source1; } - var target = new T[source1.Length + source2.Length]; + T[] target = new T[source1.Length + source2.Length]; for (int i = 0; i < source1.Length; i++) { diff --git a/src/ImageSharp.Drawing/Shapes/Helpers/VectorExtensions.cs b/src/ImageSharp.Drawing/Shapes/Helpers/VectorExtensions.cs index 0938fa06..849c93e7 100644 --- a/src/ImageSharp.Drawing/Shapes/Helpers/VectorExtensions.cs +++ b/src/ImageSharp.Drawing/Shapes/Helpers/VectorExtensions.cs @@ -21,7 +21,7 @@ internal static class VectorExtensions /// public static bool Equivalent(this PointF source1, PointF source2, float threshold) { - var abs = Vector2.Abs(source1 - source2); + Vector2 abs = Vector2.Abs(source1 - source2); return abs.X < threshold && abs.Y < threshold; } @@ -37,7 +37,7 @@ public static bool Equivalent(this PointF source1, PointF source2, float thresho /// public static bool Equivalent(this Vector2 source1, Vector2 source2, float threshold) { - var abs = Vector2.Abs(source1 - source2); + Vector2 abs = Vector2.Abs(source1 - source2); return abs.X < threshold && abs.Y < threshold; } diff --git a/src/ImageSharp.Drawing/Shapes/InternalPath.cs b/src/ImageSharp.Drawing/Shapes/InternalPath.cs index ac19097a..c3a26575 100644 --- a/src/ImageSharp.Drawing/Shapes/InternalPath.cs +++ b/src/ImageSharp.Drawing/Shapes/InternalPath.cs @@ -22,7 +22,7 @@ internal class InternalPath /// /// The maximum vector /// - private static readonly Vector2 MaxVector = new Vector2(float.MaxValue); + private static readonly Vector2 MaxVector = new(float.MaxValue); /// /// The points. @@ -82,7 +82,7 @@ private InternalPath(PointData[] points, bool isClosedPath) minX = minY = float.MaxValue; maxX = maxY = float.MinValue; - foreach (var point in this.points) + foreach (PointData point in this.points) { length += point.Length; minX = Math.Min(point.Point.X, minX); @@ -152,7 +152,7 @@ internal SegmentInfo PointAlongPath(float distanceAlongPath) if (distanceAlongPath < this.points[next].Length) { float t = distanceAlongPath / this.points[next].Length; - var point = Vector2.Lerp(this.points[i].Point, this.points[next].Point, t); + Vector2 point = Vector2.Lerp(this.points[i].Point, this.points[next].Point, t); Vector2 diff = this.points[i].Point - this.points[next].Point; return new SegmentInfo @@ -242,7 +242,7 @@ private static PointOrientation CalulateOrientation(Vector2 qp, Vector2 rq) /// private static PointData[] Simplify(IReadOnlyList segments, bool isClosed, bool removeCloseAndCollinear) { - var simplified = new List(); + List simplified = []; foreach (ILineSegment seg in segments) { @@ -260,10 +260,10 @@ private static PointData[] Simplify(ReadOnlyMemory vectors, bool isClose int polyCorners = points.Length; if (polyCorners == 0) { - return Array.Empty(); + return []; } - var results = new List(); + List results = []; Vector2 lastPoint = points[0]; if (!isClosed) diff --git a/src/ImageSharp.Drawing/Shapes/LinearLineSegment.cs b/src/ImageSharp.Drawing/Shapes/LinearLineSegment.cs index 44f4c642..b6b72ff2 100644 --- a/src/ImageSharp.Drawing/Shapes/LinearLineSegment.cs +++ b/src/ImageSharp.Drawing/Shapes/LinearLineSegment.cs @@ -22,7 +22,7 @@ public sealed class LinearLineSegment : ILineSegment /// The start. /// The end. public LinearLineSegment(PointF start, PointF end) - : this(new[] { start, end }) + : this([start, end]) { } @@ -81,7 +81,7 @@ public LinearLineSegment Transform(Matrix3x2 matrix) return this; } - var transformedPoints = new PointF[this.points.Length]; + PointF[] transformedPoints = new PointF[this.points.Length]; for (int i = 0; i < this.points.Length; i++) { diff --git a/src/ImageSharp.Drawing/Shapes/OutlinePathExtensions.cs b/src/ImageSharp.Drawing/Shapes/OutlinePathExtensions.cs index 21e499a3..d8560abc 100644 --- a/src/ImageSharp.Drawing/Shapes/OutlinePathExtensions.cs +++ b/src/ImageSharp.Drawing/Shapes/OutlinePathExtensions.cs @@ -140,7 +140,7 @@ public static IPath GenerateOutline(this IPath path, float width, ReadOnlySpan paths = path.Transform(scaleUpMartrix).Flatten(); ClipperOffset offset = new(MiterOffsetDelta); - List buffer = new(); + List buffer = []; foreach (ISimplePath p in paths) { bool online = !startOff; diff --git a/src/ImageSharp.Drawing/Shapes/Path.cs b/src/ImageSharp.Drawing/Shapes/Path.cs index b7ab77d4..434ac1b0 100644 --- a/src/ImageSharp.Drawing/Shapes/Path.cs +++ b/src/ImageSharp.Drawing/Shapes/Path.cs @@ -131,7 +131,7 @@ SegmentInfo IPathInternals.PointAlongPath(float distance) => this.InnerPath.PointAlongPath(distance); /// - IReadOnlyList IInternalPathOwner.GetRingsAsInternalPath() => new[] { this.InnerPath }; + IReadOnlyList IInternalPathOwner.GetRingsAsInternalPath() => [this.InnerPath]; /// /// Converts an SVG path string into an . diff --git a/src/ImageSharp.Drawing/Shapes/PathBuilder.cs b/src/ImageSharp.Drawing/Shapes/PathBuilder.cs index 520366c1..f09a02b0 100644 --- a/src/ImageSharp.Drawing/Shapes/PathBuilder.cs +++ b/src/ImageSharp.Drawing/Shapes/PathBuilder.cs @@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Drawing; /// public class PathBuilder { - private readonly List
figures = new(); + private readonly List
figures = []; private readonly Matrix3x2 defaultTransform; private Figure currentFigure; private Matrix3x2 currentTransform; @@ -277,7 +277,7 @@ public PathBuilder ArcTo(float radiusX, float radiusY, float rotation, bool larg /// The end point of the arc. /// The . public PathBuilder AddArc(PointF startPoint, float radiusX, float radiusY, float rotation, bool largeArc, bool sweep, PointF endPoint) - => this.AddSegment(new ArcLineSegment(startPoint, endPoint, new(radiusX, radiusY), rotation, largeArc, sweep)); + => this.AddSegment(new ArcLineSegment(startPoint, endPoint, new SizeF(radiusX, radiusY), rotation, largeArc, sweep)); /// /// Adds an elliptical arc to the current figure. @@ -349,7 +349,7 @@ public PathBuilder AddArc(Point center, int radiusX, int radiusY, int rotation, /// The angle between and the end of the arc. /// The . public PathBuilder AddArc(int x, int y, int radiusX, int radiusY, int rotation, int startAngle, int sweepAngle) - => this.AddSegment(new ArcLineSegment(new(x, y), new(radiusX, radiusY), rotation, startAngle, sweepAngle)); + => this.AddSegment(new ArcLineSegment(new PointF(x, y), new SizeF(radiusX, radiusY), rotation, startAngle, sweepAngle)); /// /// Adds an elliptical arc to the current figure. @@ -365,7 +365,7 @@ public PathBuilder AddArc(int x, int y, int radiusX, int radiusY, int rotation, /// The angle between and the end of the arc. /// The . public PathBuilder AddArc(float x, float y, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle) - => this.AddSegment(new ArcLineSegment(new(x, y), new(radiusX, radiusY), rotation, startAngle, sweepAngle)); + => this.AddSegment(new ArcLineSegment(new PointF(x, y), new SizeF(radiusX, radiusY), rotation, startAngle, sweepAngle)); /// /// Starts a new figure but leaves the previous one open. @@ -455,7 +455,7 @@ public void Clear() private class Figure { - private readonly List segments = new(); + private readonly List segments = []; public bool IsClosed { get; set; } diff --git a/src/ImageSharp.Drawing/Shapes/Polygon.cs b/src/ImageSharp.Drawing/Shapes/Polygon.cs index 0d78d8fc..19435d72 100644 --- a/src/ImageSharp.Drawing/Shapes/Polygon.cs +++ b/src/ImageSharp.Drawing/Shapes/Polygon.cs @@ -66,7 +66,7 @@ public override IPath Transform(Matrix3x2 matrix) return this; } - var segments = new ILineSegment[this.LineSegments.Count]; + ILineSegment[] segments = new ILineSegment[this.LineSegments.Count]; int i = 0; foreach (ILineSegment s in this.LineSegments) { diff --git a/src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs b/src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs index d02b9d6e..47f090a1 100644 --- a/src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs +++ b/src/ImageSharp.Drawing/Shapes/PolygonClipper/Clipper.cs @@ -24,8 +24,8 @@ public Clipper() /// The . public IPath[] GenerateClippedShapes(ClippingOperation operation, IntersectionRule rule) { - PathsF closedPaths = new(); - PathsF openPaths = new(); + PathsF closedPaths = []; + PathsF openPaths = []; FillRule fillRule = rule == IntersectionRule.EvenOdd ? FillRule.EvenOdd : FillRule.NonZero; this.polygonClipper.Execute(operation, fillRule, closedPaths, openPaths); diff --git a/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperOffset.cs b/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperOffset.cs index 1ebcc51c..8f1367c1 100644 --- a/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperOffset.cs +++ b/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperOffset.cs @@ -16,7 +16,7 @@ internal class ClipperOffset /// meter limit /// arc tolerance public ClipperOffset(float meterLimit = 2F, float arcTolerance = .25F) - => this.polygonClipperOffset = new(meterLimit, arcTolerance); + => this.polygonClipperOffset = new PolygonOffsetter(meterLimit, arcTolerance); /// /// Calculates an offset polygon based on the given path and width. @@ -25,7 +25,7 @@ public ClipperOffset(float meterLimit = 2F, float arcTolerance = .25F) /// path offset public ComplexPolygon Execute(float width) { - PathsF solution = new(); + PathsF solution = []; this.polygonClipperOffset.Execute(width, solution); Polygon[] polygons = new Polygon[solution.Count]; diff --git a/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperUtils.cs b/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperUtils.cs index 9da5b3f3..fc0b7064 100644 --- a/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperUtils.cs +++ b/src/ImageSharp.Drawing/Shapes/PolygonClipper/ClipperUtils.cs @@ -69,7 +69,7 @@ public static PathF Ellipse(Vector2 center, float radiusX, float radiusY = 0, in { if (radiusX <= 0) { - return new(); + return []; } if (radiusY <= 0) diff --git a/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonClipper.cs b/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonClipper.cs index 0772b740..6f4e3724 100644 --- a/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonClipper.cs +++ b/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonClipper.cs @@ -34,13 +34,13 @@ internal sealed class PolygonClipper public PolygonClipper() { - this.minimaList = new List(); - this.intersectList = new List(); - this.vertexList = new List(); - this.outrecList = new List(); - this.scanlineList = new List(); - this.horzSegList = new List(); - this.horzJoinList = new List(); + this.minimaList = []; + this.intersectList = []; + this.vertexList = []; + this.outrecList = []; + this.scanlineList = []; + this.horzSegList = []; + this.horzJoinList = []; this.PreserveCollinear = true; } @@ -72,7 +72,7 @@ public void AddPaths(PathsF paths, ClippingType polytype, bool isOpen = false) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Execute(ClippingOperation clipType, FillRule fillRule, PathsF solutionClosed) - => this.Execute(clipType, fillRule, solutionClosed, new PathsF()); + => this.Execute(clipType, fillRule, solutionClosed, []); public void Execute(ClippingOperation clipType, FillRule fillRule, PathsF solutionClosed, PathsF solutionOpen) { @@ -413,7 +413,7 @@ private bool BuildPaths(PathsF solutionClosed, PathsF solutionOpen) continue; } - PathF path = new(); + PathF path = []; if (outrec.IsOpen) { if (BuildPath(outrec.Pts, this.ReverseSolution, true, path)) @@ -3284,7 +3284,7 @@ private class OutRec public BoundsF Bounds { get; set; } - public PathF Path { get; set; } = new PathF(); + public PathF Path { get; set; } = []; public bool IsOpen { get; set; } @@ -3358,7 +3358,7 @@ private class Active internal class PolyPathF : IEnumerable { private readonly PolyPathF parent; - private readonly List items = new(); + private readonly List items = []; public PolyPathF(PolyPathF parent = null) => this.parent = parent; diff --git a/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonOffsetter.cs b/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonOffsetter.cs index 501ba036..4670ddfc 100644 --- a/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonOffsetter.cs +++ b/src/ImageSharp.Drawing/Shapes/PolygonClipper/PolygonOffsetter.cs @@ -14,9 +14,9 @@ namespace SixLabors.ImageSharp.Drawing.Shapes.PolygonClipper; internal sealed class PolygonOffsetter { private const float Tolerance = 1.0E-6F; - private readonly List groupList = new(); - private readonly PathF normals = new(); - private readonly PathsF solution = new(); + private readonly List groupList = []; + private readonly PathF normals = []; + private readonly PathsF solution = []; private float groupDelta; // *0.5 for open paths; *-1.0 for negative areas private float delta; private float absGroupDelta; @@ -207,7 +207,7 @@ private void DoGroupOffset(Group group) if (cnt == 1) { - group.OutPath = new PathF(); + group.OutPath = []; // Single vertex so build a circle or square. if (group.EndType == EndCapStyle.Round) @@ -324,7 +324,7 @@ private void OffsetOpenJoined(Group group, PathF path) private void OffsetOpenPath(Group group, PathF path) { - group.OutPath = new(path.Count); + group.OutPath = new PathF(path.Count); int highI = path.Count - 1; // Further reduced extraneous vertices in solutions (#499) @@ -400,14 +400,14 @@ private static Vector2 GetUnitNormal(Vector2 pt1, Vector2 pt2) } dxy *= 1F / MathF.Sqrt(ClipperUtils.DotProduct(dxy, dxy)); - return new(dxy.Y, -dxy.X); + return new Vector2(dxy.Y, -dxy.X); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void OffsetPolygon(Group group, PathF path) { // Dereference the current outpath. - group.OutPath = new(path.Count); + group.OutPath = new PathF(path.Count); int cnt = path.Count, prev = cnt - 1; for (int i = 0; i < cnt; i++) { @@ -562,7 +562,7 @@ private void DoRound(Group group, PathF path, int j, int k, float angle) // ie 1 less than steps for (int i = 1; i < steps; i++) { - offsetVec = new((offsetVec.X * this.stepCos) - (this.stepSin * offsetVec.Y), (offsetVec.X * this.stepSin) + (offsetVec.Y * this.stepCos)); + offsetVec = new Vector2((offsetVec.X * this.stepCos) - (this.stepSin * offsetVec.Y), (offsetVec.X * this.stepSin) + (offsetVec.Y * this.stepCos)); group.OutPath.Add(pt + offsetVec); } @@ -646,8 +646,8 @@ public Group(PathsF paths, JointStyle joinType, EndCapStyle endType = EndCapStyl this.InPaths = new PathsF(paths); this.JoinType = joinType; this.EndType = endType; - this.OutPath = new PathF(); - this.OutPaths = new PathsF(); + this.OutPath = []; + this.OutPaths = []; this.PathsReversed = false; } diff --git a/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs b/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs index 32e4ba54..5ef039bc 100644 --- a/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs +++ b/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs @@ -96,9 +96,9 @@ public static PolygonScanner Create( IntersectionRule intersectionRule, MemoryAllocator allocator) { - using var multipolygon = TessellatedMultipolygon.Create(polygon, allocator); - var edges = ScanEdgeCollection.Create(multipolygon, allocator, subsampling); - var scanner = new PolygonScanner(edges, multipolygon.TotalVertexCount * 2, minY, maxY, subsampling, intersectionRule, allocator); + using TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, allocator); + ScanEdgeCollection edges = ScanEdgeCollection.Create(multipolygon, allocator, subsampling); + PolygonScanner scanner = new(edges, multipolygon.TotalVertexCount * 2, minY, maxY, subsampling, intersectionRule, allocator); scanner.Init(); return scanner; } diff --git a/src/ImageSharp.Drawing/Shapes/RectangularPolygon.cs b/src/ImageSharp.Drawing/Shapes/RectangularPolygon.cs index 32382878..aec7e31e 100644 --- a/src/ImageSharp.Drawing/Shapes/RectangularPolygon.cs +++ b/src/ImageSharp.Drawing/Shapes/RectangularPolygon.cs @@ -45,13 +45,13 @@ public RectangularPolygon(PointF topLeft, PointF bottomRight) this.bottomRight = bottomRight; this.Size = new SizeF(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y); - this.points = new PointF[4] - { + this.points = + [ this.topLeft, new Vector2(this.bottomRight.X, this.topLeft.Y), this.bottomRight, new Vector2(this.topLeft.X, this.bottomRight.Y) - }; + ]; this.halfLength = this.Size.Width + this.Size.Height; this.length = this.halfLength * 2; diff --git a/src/ImageSharp.Drawing/Shapes/RegularPolygon.cs b/src/ImageSharp.Drawing/Shapes/RegularPolygon.cs index 4a3cafea..b914d538 100644 --- a/src/ImageSharp.Drawing/Shapes/RegularPolygon.cs +++ b/src/ImageSharp.Drawing/Shapes/RegularPolygon.cs @@ -63,14 +63,14 @@ private static LinearLineSegment CreateSegment(PointF location, float radius, in Guard.MustBeGreaterThan(vertices, 2, nameof(vertices)); Guard.MustBeGreaterThan(radius, 0, nameof(radius)); - var distanceVector = new PointF(0, radius); + PointF distanceVector = new(0, radius); float anglePerSegments = (float)(2 * Math.PI / vertices); float current = angle; - var points = new PointF[vertices]; + PointF[] points = new PointF[vertices]; for (int i = 0; i < vertices; i++) { - var rotated = PointF.Transform(distanceVector, Matrix3x2.CreateRotation(current)); + PointF rotated = PointF.Transform(distanceVector, Matrix3x2.CreateRotation(current)); points[i] = rotated + location; diff --git a/src/ImageSharp.Drawing/Shapes/Star.cs b/src/ImageSharp.Drawing/Shapes/Star.cs index 5855a3b8..ba5a261c 100644 --- a/src/ImageSharp.Drawing/Shapes/Star.cs +++ b/src/ImageSharp.Drawing/Shapes/Star.cs @@ -68,13 +68,13 @@ private static LinearLineSegment CreateSegment(Vector2 location, float innerRadi Guard.MustBeGreaterThan(innerRadii, 0, nameof(innerRadii)); Guard.MustBeGreaterThan(outerRadii, 0, nameof(outerRadii)); - var distanceVectorInner = new Vector2(0, innerRadii); - var distanceVectorOuter = new Vector2(0, outerRadii); + Vector2 distanceVectorInner = new(0, innerRadii); + Vector2 distanceVectorOuter = new(0, outerRadii); int vertices = prongs * 2; float anglePerSegments = (float)(2 * Math.PI / vertices); float current = angle; - var points = new PointF[vertices]; + PointF[] points = new PointF[vertices]; Vector2 distance = distanceVectorInner; for (int i = 0; i < vertices; i++) { @@ -87,7 +87,7 @@ private static LinearLineSegment CreateSegment(Vector2 location, float innerRadi distance = distanceVectorInner; } - var rotated = Vector2.Transform(distance, Matrix3x2.CreateRotation(current)); + Vector2 rotated = Vector2.Transform(distance, Matrix3x2.CreateRotation(current)); points[i] = rotated + location; diff --git a/src/ImageSharp.Drawing/Shapes/Text/BaseGlyphBuilder.cs b/src/ImageSharp.Drawing/Shapes/Text/BaseGlyphBuilder.cs index ba6762d4..ab1333ee 100644 --- a/src/ImageSharp.Drawing/Shapes/Text/BaseGlyphBuilder.cs +++ b/src/ImageSharp.Drawing/Shapes/Text/BaseGlyphBuilder.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Drawing.Text; /// internal class BaseGlyphBuilder : IGlyphRenderer { - private readonly List paths = new(); + private readonly List paths = []; private Vector2 currentPoint; private GlyphRendererParameters parameters; @@ -146,11 +146,11 @@ public virtual void SetDecoration(TextDecorations textDecorations, Vector2 start } thickness = MathF.Max(1F, (float)Math.Round(thickness)); - var renderer = (IGlyphRenderer)this; + IGlyphRenderer renderer = (IGlyphRenderer)this; // Expand the points to create a rectangle centered around the line. bool rotated = this.parameters.LayoutMode is GlyphLayoutMode.Vertical or GlyphLayoutMode.VerticalRotated; - Vector2 pad = rotated ? new(thickness * .5F, 0) : new(0, thickness * .5F); + Vector2 pad = rotated ? new Vector2(thickness * .5F, 0) : new Vector2(0, thickness * .5F); // Clamp the line to the pixel grid. start = ClampToPixel(start, (int)thickness, rotated); @@ -167,12 +167,12 @@ public virtual void SetDecoration(TextDecorations textDecorations, Vector2 start if (textDecorations == TextDecorations.Overline) { // CSS overline is drawn above the position, so we need to move it up. - offset = rotated ? new(thickness * .5F, 0) : new(0, -(thickness * .5F)); + offset = rotated ? new Vector2(thickness * .5F, 0) : new Vector2(0, -(thickness * .5F)); } else if (textDecorations == TextDecorations.Underline) { // CSS underline is drawn below the position, so we need to move it down. - offset = rotated ? new(-(thickness * .5F), 0) : new(0, thickness * .5F); + offset = rotated ? new Vector2(-(thickness * .5F), 0) : new Vector2(0, thickness * .5F); } renderer.BeginFigure(); diff --git a/src/ImageSharp.Drawing/Utilities/NumericUtilities.cs b/src/ImageSharp.Drawing/Utilities/NumericUtilities.cs index b70a94f3..b2401ddf 100644 --- a/src/ImageSharp.Drawing/Utilities/NumericUtilities.cs +++ b/src/ImageSharp.Drawing/Utilities/NumericUtilities.cs @@ -20,7 +20,7 @@ public static void AddToAllElements(this Span span, float value) ref Vector currentVec = ref Unsafe.As>(ref current); ref Vector maxVec = ref Unsafe.Add(ref currentVec, n); - var vecVal = new Vector(value); + Vector vecVal = new(value); while (Unsafe.IsAddressLessThan(ref currentVec, ref maxVec)) { currentVec += vecVal; diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawBeziers.cs index 412b9a82..6ff49426 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawBeziers.cs @@ -9,6 +9,7 @@ using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; +using Pen = System.Drawing.Pen; using SDPointF = System.Drawing.PointF; namespace SixLabors.ImageSharp.Drawing.Benchmarks.Drawing; @@ -18,20 +19,20 @@ public class DrawBeziers [Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")] public void DrawPathSystemDrawing() { - using (var destination = new Bitmap(800, 800)) - using (var graphics = Graphics.FromImage(destination)) + using (Bitmap destination = new(800, 800)) + using (Graphics graphics = Graphics.FromImage(destination)) { graphics.InterpolationMode = InterpolationMode.Default; graphics.SmoothingMode = SmoothingMode.AntiAlias; - using (var pen = new System.Drawing.Pen(System.Drawing.Color.HotPink, 10)) + using (Pen pen = new(System.Drawing.Color.HotPink, 10)) { graphics.DrawBeziers( pen, - new[] { new SDPointF(10, 500), new SDPointF(30, 10), new SDPointF(240, 30), new SDPointF(300, 500) }); + [new SDPointF(10, 500), new SDPointF(30, 10), new SDPointF(240, 30), new SDPointF(300, 500)]); } - using (var stream = new MemoryStream()) + using (MemoryStream stream = new()) { destination.Save(stream, ImageFormat.Bmp); } @@ -41,7 +42,7 @@ public void DrawPathSystemDrawing() [Benchmark(Description = "ImageSharp Draw Beziers")] public void DrawLinesCore() { - using (var image = new Image(800, 800)) + using (Image image = new(800, 800)) { image.Mutate(x => x.DrawBeziers( Color.HotPink, @@ -51,7 +52,7 @@ public void DrawLinesCore() new Vector2(240, 30), new Vector2(300, 500))); - using (var stream = new MemoryStream()) + using (MemoryStream stream = new()) { image.SaveAsBmp(stream); } diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawPolygon.cs index d0c85bf8..380ce246 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawPolygon.cs @@ -12,6 +12,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SkiaSharp; +using Pen = System.Drawing.Pen; using SDPointF = System.Drawing.PointF; namespace SixLabors.ImageSharp.Drawing.Benchmarks.Drawing; @@ -81,7 +82,7 @@ public void Cleanup() [Benchmark] public void SystemDrawing() { - using var pen = new System.Drawing.Pen(System.Drawing.Color.White, this.Thickness); + using Pen pen = new(System.Drawing.Color.White, this.Thickness); foreach (SDPointF[] loop in this.sdPoints) { @@ -103,7 +104,7 @@ public void ImageSharp() [Benchmark(Baseline = true)] public void SkiaSharp() { - using var paint = new SKPaint + using SKPaint paint = new() { Style = SKPaintStyle.Stroke, Color = SKColors.White, diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawText.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawText.cs index df7ce130..21dedf41 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawText.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawText.cs @@ -90,7 +90,7 @@ public void ImageSharp() [Benchmark(Baseline = true)] public void SkiaSharp() { - using var paint = new SKPaint + using SKPaint paint = new() { Color = SKColors.HotPink, IsAntialias = true, diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawTextOutline.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawTextOutline.cs index 505636c3..29f47d7e 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawTextOutline.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/DrawTextOutline.cs @@ -9,6 +9,7 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using Brush = SixLabors.ImageSharp.Drawing.Processing.Brush; +using Font = System.Drawing.Font; using Pen = SixLabors.ImageSharp.Drawing.Processing.Pen; using SDRectangleF = System.Drawing.RectangleF; @@ -27,14 +28,14 @@ public class DrawTextOutline [Benchmark(Baseline = true, Description = "System.Drawing Draw Text Outline")] public void DrawTextSystemDrawing() { - using var destination = new Bitmap(800, 800); - using var graphics = Graphics.FromImage(destination); + using Bitmap destination = new(800, 800); + using Graphics graphics = Graphics.FromImage(destination); graphics.InterpolationMode = InterpolationMode.Default; graphics.SmoothingMode = SmoothingMode.AntiAlias; - using var pen = new System.Drawing.Pen(System.Drawing.Color.HotPink, 10); - using var font = new System.Drawing.Font("Arial", 12, GraphicsUnit.Point); - using var gp = new GraphicsPath(); + using System.Drawing.Pen pen = new(System.Drawing.Color.HotPink, 10); + using Font font = new("Arial", 12, GraphicsUnit.Point); + using GraphicsPath gp = new(); gp.AddString( this.TextToRender, @@ -50,7 +51,7 @@ public void DrawTextSystemDrawing() [Benchmark(Description = "ImageSharp Draw Text Outline - Cached Glyphs")] public void DrawTextCore() { - using var image = new Image(800, 800); + using Image image = new(800, 800); Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 12); RichTextOptions textOptions = new(font) { @@ -67,7 +68,7 @@ public void DrawTextCore() [Benchmark(Description = "ImageSharp Draw Text Outline - Naive")] public void DrawTextCoreOld() { - using (var image = new Image(800, 800)) + using (Image image = new(800, 800)) { Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 12); TextOptions textOptions = new(font) @@ -96,7 +97,7 @@ static IImageProcessingContext DrawTextOldVersion( { IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions); - var pathOptions = new DrawingOptions() { GraphicsOptions = options.GraphicsOptions }; + DrawingOptions pathOptions = new() { GraphicsOptions = options.GraphicsOptions }; if (brush != null) { source.Fill(pathOptions, brush, glyphs); diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs index f30390f7..acac46b0 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs @@ -21,15 +21,15 @@ public class FillPathGradientBrush [Benchmark] public void FillGradientBrush_ImageSharp() { - var star = new Star(50, 50, 5, 20, 45); + Star star = new(50, 50, 5, 20, 45); PointF[] points = star.Points.ToArray(); Color[] colors = - { + [ Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple, Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple - }; + ]; - var brush = new PathGradientBrush(points, colors, Color.White); + PathGradientBrush brush = new(points, colors, Color.White); this.image.Mutate(x => x.Fill(brush)); } diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPolygon.cs index 85d7f550..60ba9b19 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPolygon.cs @@ -14,6 +14,7 @@ using SkiaSharp; using SDBitmap = System.Drawing.Bitmap; using SDPointF = System.Drawing.PointF; +using SolidBrush = System.Drawing.SolidBrush; namespace SixLabors.ImageSharp.Drawing.Benchmarks.Drawing; @@ -51,10 +52,10 @@ public void Setup() this.sdPoints = this.points.Select(pts => pts.Select(p => new SDPointF(p.X, p.Y)).ToArray()).ToArray(); - this.skPaths = new List(); + this.skPaths = []; foreach (PointF[] ptArr in this.points.Where(pts => pts.Length > 2)) { - var skPath = new SKPath(); + SKPath skPath = new(); skPath.MoveTo(ptArr[0].X, ptArr[1].Y); for (int i = 1; i < ptArr.Length; i++) { @@ -91,7 +92,7 @@ public void Cleanup() [Benchmark] public void SystemDrawing() { - using var brush = new System.Drawing.SolidBrush(System.Drawing.Color.White); + using SolidBrush brush = new(System.Drawing.Color.White); foreach (SDPointF[] loop in this.sdPoints) { @@ -115,7 +116,7 @@ public void SkiaSharp() foreach (SKPath path in this.skPaths) { // Emulate using different color for each polygon: - using var paint = new SKPaint + using SKPaint paint = new() { Style = SKPaintStyle.Fill, Color = SKColors.White, diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillRectangle.cs index 91cf5e07..b5d04ec2 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillRectangle.cs @@ -18,8 +18,8 @@ public class FillRectangle [Benchmark(Baseline = true, Description = "System.Drawing Fill Rectangle")] public SDSize FillRectangleSystemDrawing() { - using (var destination = new Bitmap(800, 800)) - using (var graphics = Graphics.FromImage(destination)) + using (Bitmap destination = new(800, 800)) + using (Graphics graphics = Graphics.FromImage(destination)) { graphics.InterpolationMode = InterpolationMode.Default; graphics.SmoothingMode = SmoothingMode.AntiAlias; @@ -32,7 +32,7 @@ public SDSize FillRectangleSystemDrawing() [Benchmark(Description = "ImageSharp Fill Rectangle")] public Size FillRectangleCore() { - using (var image = new Image(800, 800)) + using (Image image = new(800, 800)) { image.Mutate(x => x.Fill(Color.HotPink, new Rectangle(10, 10, 190, 140))); @@ -43,7 +43,7 @@ public Size FillRectangleCore() [Benchmark(Description = "ImageSharp Fill Rectangle - As Polygon")] public Size FillPolygonCore() { - using (var image = new Image(800, 800)) + using (Image image = new(800, 800)) { image.Mutate(x => x.FillPolygon( Color.HotPink, diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillWithPattern.cs index d3ced417..63fc8bcc 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillWithPattern.cs @@ -17,17 +17,17 @@ public class FillWithPattern [Benchmark(Baseline = true, Description = "System.Drawing Fill with Pattern")] public void DrawPatternPolygonSystemDrawing() { - using (var destination = new Bitmap(800, 800)) - using (var graphics = Graphics.FromImage(destination)) + using (Bitmap destination = new(800, 800)) + using (Graphics graphics = Graphics.FromImage(destination)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; - using (var brush = new HatchBrush(HatchStyle.BackwardDiagonal, System.Drawing.Color.HotPink)) + using (HatchBrush brush = new(HatchStyle.BackwardDiagonal, System.Drawing.Color.HotPink)) { graphics.FillRectangle(brush, new SDRectangle(0, 0, 800, 800)); // can't find a way to flood fill with a brush } - using (var stream = new MemoryStream()) + using (MemoryStream stream = new()) { destination.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); } @@ -37,11 +37,11 @@ public void DrawPatternPolygonSystemDrawing() [Benchmark(Description = "ImageSharp Fill with Pattern")] public void DrawPatternPolygon3Core() { - using (var image = new Image(800, 800)) + using (Image image = new(800, 800)) { image.Mutate(x => x.Fill(CoreBrushes.BackwardDiagonal(Color.HotPink))); - using (var stream = new MemoryStream()) + using (MemoryStream stream = new()) { image.SaveAsBmp(stream); } diff --git a/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs b/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs index 85f1efd5..d118ab7e 100644 --- a/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Drawing.Tests/ConfigurationTests.cs @@ -56,7 +56,7 @@ public void TestDefaultConfigurationMaxDegreeOfParallelism() { Assert.True(this.DefaultConfiguration.MaxDegreeOfParallelism == Environment.ProcessorCount); - var cfg = new Configuration(); + Configuration cfg = new(); Assert.True(cfg.MaxDegreeOfParallelism == Environment.ProcessorCount); } @@ -69,7 +69,7 @@ public void TestDefaultConfigurationMaxDegreeOfParallelism() [InlineData(5, false)] public void MaxDegreeOfParallelism_CompatibleWith_ParallelOptions(int maxDegreeOfParallelism, bool throws) { - var cfg = new Configuration(); + Configuration cfg = new(); if (throws) { Assert.Throws( @@ -85,8 +85,8 @@ public void MaxDegreeOfParallelism_CompatibleWith_ParallelOptions(int maxDegreeO [Fact] public void ConstructorCallConfigureOnFormatProvider() { - var provider = new Mock(); - var config = new Configuration(provider.Object); + Mock provider = new(); + Configuration config = new(provider.Object); provider.Verify(x => x.Configure(config)); } @@ -94,8 +94,8 @@ public void ConstructorCallConfigureOnFormatProvider() [Fact] public void AddFormatCallsConfig() { - var provider = new Mock(); - var config = new Configuration(); + Mock provider = new(); + Configuration config = new(); config.Configure(provider.Object); provider.Verify(x => x.Configure(config)); @@ -116,7 +116,7 @@ public void ConfigurationCannotAddDuplicates() [Fact] public void DefaultConfigurationHasCorrectFormatCount() { - var config = Configuration.CreateDefaultInstance(); + Configuration config = Configuration.CreateDefaultInstance(); Assert.Equal(this.expectedDefaultConfigurationCount, config.ImageFormats.Count()); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/ClearSolidBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/ClearSolidBrushTests.cs index 53769d6e..cc2fc17f 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/ClearSolidBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/ClearSolidBrushTests.cs @@ -99,7 +99,7 @@ public void FillRegion(TestImageProvider provider, int x0, int y where TPixel : unmanaged, IPixel { FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; - var region = new RectangleF(x0, y0, w, h); + RectangleF region = new(x0, y0, w, h); Color color = TestUtils.GetColorByName("Blue"); provider.RunValidatingProcessorTest(c => c.Clear(color, region), testDetails, ImageComparer.Exact); @@ -117,7 +117,7 @@ public void FillRegion_WorksOnWrappedMemoryImage( where TPixel : unmanaged, IPixel { FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; - var region = new RectangleF(x0, y0, w, h); + RectangleF region = new(x0, y0, w, h); Color color = TestUtils.GetColorByName("Blue"); provider.RunValidatingProcessorTestOnWrappedMemoryImage( @@ -128,8 +128,8 @@ public void FillRegion_WorksOnWrappedMemoryImage( } public static readonly TheoryData BlendData = - new TheoryData - { + new() + { { false, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f }, { false, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, { false, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f }, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/ClipTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/ClipTests.cs index 8a38699c..55b66494 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/ClipTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/ClipTests.cs @@ -26,9 +26,9 @@ public void Clip(TestImageProvider provider, float dx, float dy, { Size size = x.GetCurrentSize(); int outerRadii = (int)(Math.Min(size.Width, size.Height) * sizeMult); - var star = new Star(new PointF(size.Width / 2, size.Height / 2), 5, outerRadii / 2, outerRadii); + Star star = new(new PointF(size.Width / 2, size.Height / 2), 5, outerRadii / 2, outerRadii); - var builder = Matrix3x2.CreateTranslation(new Vector2(dx, dy)); + Matrix3x2 builder = Matrix3x2.CreateTranslation(new Vector2(dx, dy)); x.Clip(star.Transform(builder), x => x.DetectEdges()); }, testOutputDetails: testDetails, @@ -39,10 +39,10 @@ public void Clip(TestImageProvider provider, float dx, float dy, [Fact] public void Issue250_Vertical_Horizontal_Count_Should_Match() { - var clip = new PathCollection(new RectangularPolygon(new PointF(24, 16), new PointF(777, 385))); + PathCollection clip = new(new RectangularPolygon(new PointF(24, 16), new PointF(777, 385))); - var vert = new Path(new LinearLineSegment(new PointF(26, 384), new PointF(26, 163))); - var horiz = new Path(new LinearLineSegment(new PointF(26, 163), new PointF(176, 163))); + Path vert = new(new LinearLineSegment(new PointF(26, 384), new PointF(26, 163))); + Path horiz = new(new LinearLineSegment(new PointF(26, 163), new PointF(176, 163))); IPath reverse = vert.Clip(clip); IEnumerable> result1 = vert.Clip(reverse).Flatten().Select(x => x.Points); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/DrawBezierTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/DrawBezierTests.cs index daf6781c..f2a7c2e4 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/DrawBezierTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/DrawBezierTests.cs @@ -11,8 +11,8 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing; public class DrawBezierTests { public static readonly TheoryData DrawPathData - = new TheoryData - { + = new() + { { "White", 255, 1.5f }, { "Red", 255, 3 }, { "HotPink", 255, 5 }, @@ -25,13 +25,13 @@ public static readonly TheoryData DrawPathData public void DrawBeziers(TestImageProvider provider, string colorName, byte alpha, float thickness) where TPixel : unmanaged, IPixel { - var points = new PointF[] - { + PointF[] points = + [ new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }; + ]; Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha / 255F); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/DrawComplexPolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/DrawComplexPolygonTests.cs index 8197b9ed..95252213 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/DrawComplexPolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/DrawComplexPolygonTests.cs @@ -18,12 +18,12 @@ public class DrawComplexPolygonTests public void DrawComplexPolygon(TestImageProvider provider, bool overlap, bool transparent, bool dashed) where TPixel : unmanaged, IPixel { - var simplePath = new Polygon(new LinearLineSegment( + Polygon simplePath = new(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - var hole1 = new Polygon(new LinearLineSegment( + Polygon hole1 = new(new LinearLineSegment( new Vector2(37, 85), overlap ? new Vector2(130, 40) : new Vector2(93, 85), new Vector2(65, 137))); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/DrawLinesTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/DrawLinesTests.cs index 382af441..375fb2d5 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/DrawLinesTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/DrawLinesTests.cs @@ -33,7 +33,7 @@ public void DrawLinesInvalidPoints(TestImageProvider provider, f where TPixel : unmanaged, IPixel { SolidPen pen = new(Color.Black, thickness); - PointF[] path = { new Vector2(15f, 15f), new Vector2(15f, 15f) }; + PointF[] path = [new Vector2(15f, 15f), new Vector2(15f, 15f)]; GraphicsOptions options = new() { @@ -99,7 +99,7 @@ public void DrawLines_EndCapRound(TestImageProvider provider, st where TPixel : unmanaged, IPixel { Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - PatternPen pen = new(new PenOptions(color, thickness, new float[] { 3f, 3f }) { EndCapStyle = EndCapStyle.Round }); + PatternPen pen = new(new PenOptions(color, thickness, [3f, 3f]) { EndCapStyle = EndCapStyle.Round }); DrawLinesImpl(provider, colorName, alpha, thickness, antialias, pen); } @@ -110,7 +110,7 @@ public void DrawLines_EndCapButt(TestImageProvider provider, str where TPixel : unmanaged, IPixel { Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - PatternPen pen = new(new PenOptions(color, thickness, new float[] { 3f, 3f }) { EndCapStyle = EndCapStyle.Butt }); + PatternPen pen = new(new PenOptions(color, thickness, [3f, 3f]) { EndCapStyle = EndCapStyle.Butt }); DrawLinesImpl(provider, colorName, alpha, thickness, antialias, pen); } @@ -121,7 +121,7 @@ public void DrawLines_EndCapSquare(TestImageProvider provider, s where TPixel : unmanaged, IPixel { Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - PatternPen pen = new(new PenOptions(color, thickness, new float[] { 3f, 3f }) { EndCapStyle = EndCapStyle.Square }); + PatternPen pen = new(new PenOptions(color, thickness, [3f, 3f]) { EndCapStyle = EndCapStyle.Square }); DrawLinesImpl(provider, colorName, alpha, thickness, antialias, pen); } @@ -168,7 +168,7 @@ private static void DrawLinesImpl( Pen pen) where TPixel : unmanaged, IPixel { - PointF[] simplePath = { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) }; + PointF[] simplePath = [new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300)]; GraphicsOptions options = new() { Antialias = antialias }; diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/DrawPathTests.cs index a2303ad8..b01b83c1 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/DrawPathTests.cs @@ -37,7 +37,7 @@ public void DrawPath(TestImageProvider provider, string colorNam new Vector2(10, 400)); ArcLineSegment ellipticArcSegment1 = new(new Vector2(10, 400), new Vector2(150, 450), new SizeF((float)Math.Sqrt(5525), 40), GeometryUtilities.RadianToDegree((float)Math.Atan2(25, 70)), true, true); - ArcLineSegment ellipticArcSegment2 = new(new(150, 450), new(149F, 450), new SizeF(140, 70), 0, true, true); + ArcLineSegment ellipticArcSegment2 = new(new PointF(150, 450), new PointF(149F, 450), new SizeF(140, 70), 0, true, true); Path path = new(linearSegment, bezierSegment, ellipticArcSegment1, ellipticArcSegment2); @@ -65,7 +65,7 @@ public void PathExtendingOffEdgeOfImageShouldNotBeCropped(TestImageProvi { for (int i = 0; i < 300; i += 20) { - PointF[] points = new PointF[] { new Vector2(100, 2), new Vector2(-10, i) }; + PointF[] points = [new Vector2(100, 2), new Vector2(-10, i)]; x.DrawLine(pen, points); } }, @@ -79,11 +79,11 @@ public void DrawPathClippedOnTop(TestImageProvider provider) where TPixel : unmanaged, IPixel { PointF[] points = - { - new PointF(10f, -10f), - new PointF(20f, 20f), - new PointF(30f, -30f) - }; + [ + new(10f, -10f), + new(20f, 20f), + new(30f, -30f) + ]; IPath path = new PathBuilder().AddLines(points).Build(); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/DrawPolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/DrawPolygonTests.cs index 2c822ff4..425bdba8 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/DrawPolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/DrawPolygonTests.cs @@ -19,12 +19,12 @@ public void DrawPolygon(TestImageProvider provider, string color where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }; + [ + new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) + ]; Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - var options = new GraphicsOptions { Antialias = antialias }; + GraphicsOptions options = new() { Antialias = antialias }; string aa = antialias ? string.Empty : "_NoAntialias"; FormattableString outputDetails = $"{colorName}_A({alpha})_T({thickness}){aa}"; @@ -41,9 +41,9 @@ public void DrawPolygon_Transformed(TestImageProvider provider) where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }; + [ + new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) + ]; provider.RunValidatingProcessorTest( c => c.SetDrawingTransform(Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(-15), 0, new Vector2(200, 200))) @@ -55,7 +55,7 @@ public void DrawPolygon_Transformed(TestImageProvider provider) public void DrawRectangularPolygon_Transformed(TestImageProvider provider) where TPixel : unmanaged, IPixel { - var polygon = new RectangularPolygon(25, 25, 50, 50); + RectangularPolygon polygon = new(25, 25, 50, 50); provider.RunValidatingProcessorTest( c => c.SetDrawingTransform(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))) diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/DrawingRobustnessTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/DrawingRobustnessTests.cs index 1295d6f3..6b21ae62 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/DrawingRobustnessTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/DrawingRobustnessTests.cs @@ -20,7 +20,7 @@ public class DrawingRobustnessTests [WithSolidFilledImages(32, 32, "Black", PixelTypes.Rgba32)] public void CompareToSkiaResults_SmallCircle(TestImageProvider provider) { - var circle = new EllipsePolygon(16, 16, 10); + EllipsePolygon circle = new(16, 16, 10); CompareToSkiaResultsImpl(provider, circle); } @@ -29,8 +29,8 @@ public void CompareToSkiaResults_SmallCircle(TestImageProvider provider) [WithSolidFilledImages(64, 64, "Black", PixelTypes.Rgba32)] public void CompareToSkiaResults_StarCircle(TestImageProvider provider) { - var circle = new EllipsePolygon(32, 32, 30); - var star = new Star(32, 32, 7, 10, 27); + EllipsePolygon circle = new(32, 32, 30); + Star star = new(32, 32, 7, 10, 27); IPath shape = circle.Clip(star); CompareToSkiaResultsImpl(provider, shape); @@ -42,9 +42,9 @@ private static void CompareToSkiaResultsImpl(TestImageProvider provider, image.Mutate(c => c.Fill(Color.White, shape)); image.DebugSave(provider, "ImageSharp", appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); - using var bitmap = new SKBitmap(new SKImageInfo(image.Width, image.Height)); + using SKBitmap bitmap = new(new SKImageInfo(image.Width, image.Height)); - using var skPath = new SKPath(); + using SKPath skPath = new(); foreach (ISimplePath loop in shape.Flatten()) { @@ -52,18 +52,18 @@ private static void CompareToSkiaResultsImpl(TestImageProvider provider, skPath.AddPoly(points.ToArray()); } - using var paint = new SKPaint + using SKPaint paint = new() { Style = SKPaintStyle.Fill, Color = SKColors.White, IsAntialias = true, }; - using var canvas = new SKCanvas(bitmap); + using SKCanvas canvas = new(bitmap); canvas.Clear(new SKColor(0, 0, 0)); canvas.DrawPath(skPath, paint); - using var skResultImage = + using Image skResultImage = Image.LoadPixelData(bitmap.GetPixelSpan(), image.Width, image.Height); skResultImage.DebugSave( provider, @@ -84,7 +84,7 @@ public void LargeGeoJson_Lines(TestImageProvider provider, string geoJso PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(sx, sy)); using Image image = provider.GetImage(); - var options = new DrawingOptions() + DrawingOptions options = new() { GraphicsOptions = new GraphicsOptions() { Antialias = aa > 0, AntialiasSubpixelDepth = aa }, }; @@ -107,7 +107,7 @@ public void LargeGeoJson_Lines(TestImageProvider provider, string geoJso public void LargeGeoJson_States_Fill(TestImageProvider provider) { using Image image = this.FillGeoJsonPolygons(provider, TestImages.GeoJson.States, 16, new Vector2(60), new Vector2(0, -1000)); - var comparer = ImageComparer.TolerantPercentage(0.001f); + ImageComparer comparer = ImageComparer.TolerantPercentage(0.001f); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); image.CompareToReferenceOutput(comparer, provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -120,17 +120,17 @@ private Image FillGeoJsonPolygons(TestImageProvider provider, st PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation(pixelOffset)); Image image = provider.GetImage(); - var options = new DrawingOptions() + DrawingOptions options = new() { GraphicsOptions = new GraphicsOptions() { Antialias = aa > 0, AntialiasSubpixelDepth = aa }, }; - var rnd = new Random(42); + Random rnd = new(42); byte[] rgb = new byte[3]; foreach (PointF[] loop in points) { rnd.NextBytes(rgb); - var color = Color.FromPixel(new(rgb[0], rgb[1], rgb[2])); + Color color = Color.FromPixel(new Rgb24(rgb[0], rgb[1], rgb[2])); image.Mutate(c => c.FillPolygon(options, color, loop)); } @@ -185,7 +185,7 @@ public void Missisippi_Skia(int offset) * Matrix3x2.CreateTranslation(offset, offset); IReadOnlyList points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform); - var path = new SKPath(); + SKPath path = new(); foreach (PointF[] pts in points.Where(p => p.Length > 2)) { @@ -199,9 +199,9 @@ public void Missisippi_Skia(int offset) path.LineTo(pts[0].X, pts[0].Y); } - var imageInfo = new SKImageInfo(10000, 10000); + SKImageInfo imageInfo = new(10000, 10000); - using var paint = new SKPaint + using SKPaint paint = new() { Style = SKPaintStyle.Stroke, Color = SKColors.White, @@ -209,7 +209,7 @@ public void Missisippi_Skia(int offset) IsAntialias = true, }; - using var surface = SKSurface.Create(imageInfo); + using SKSurface surface = SKSurface.Create(imageInfo); SKCanvas canvas = surface.Canvas; canvas.Clear(new SKColor(0, 0, 0)); canvas.DrawPath(path, paint); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillComplexPolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillComplexPolygonTests.cs index 44b02a63..81d77075 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillComplexPolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillComplexPolygonTests.cs @@ -17,12 +17,12 @@ public class FillComplexPolygonTests public void ComplexPolygon_SolidFill(TestImageProvider provider, bool overlap, bool transparent) where TPixel : unmanaged, IPixel { - var simplePath = new Polygon(new LinearLineSegment( + Polygon simplePath = new(new LinearLineSegment( new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300))); - var hole1 = new Polygon(new LinearLineSegment( + Polygon hole1 = new(new LinearLineSegment( new Vector2(37, 85), overlap ? new Vector2(130, 40) : new Vector2(93, 85), new Vector2(65, 137))); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillEllipticGradientBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillEllipticGradientBrushTests.cs index 8ac13d24..0bedd4d3 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillEllipticGradientBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillEllipticGradientBrushTests.cs @@ -23,8 +23,8 @@ public void WithEqualColorsReturnsUnicolorImage( using (Image image = provider.GetImage()) { - var unicolorLinearGradientBrush = - new EllipticGradientBrush( + EllipticGradientBrush unicolorLinearGradientBrush = + new( new Point(0, 0), new Point(10, 0), 1.0f, @@ -62,7 +62,7 @@ public void AxisParallelEllipsesWithDifferentRatio( TolerantComparer, image => { - var unicolorLinearGradientBrush = new EllipticGradientBrush( + EllipticGradientBrush unicolorLinearGradientBrush = new( new Point(image.Width / 2, image.Height / 2), new Point(image.Width / 2, image.Width * 2 / 3), ratio, @@ -114,7 +114,7 @@ public void RotatedEllipsesWithDifferentRatio( Color red = Color.Red; Color black = Color.Black; - var center = new Point(image.Width / 2, image.Height / 2); + Point center = new(image.Width / 2, image.Height / 2); double rotation = Math.PI * rotationInDegree / 180.0; double cos = Math.Cos(rotation); @@ -124,7 +124,7 @@ public void RotatedEllipsesWithDifferentRatio( int axisX = center.X + (int)-(offsetY * sin); int axisY = center.Y + (int)(offsetY * cos); - var unicolorLinearGradientBrush = new EllipticGradientBrush( + EllipticGradientBrush unicolorLinearGradientBrush = new( center, new Point(axisX, axisY), ratio, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillImageBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillImageBrushTests.cs index eb8211a0..7afd37a4 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillImageBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillImageBrushTests.cs @@ -74,7 +74,7 @@ public void CanDrawPortraitImage(TestImageProvider provider) overlay.Mutate(c => c.Crop(new Rectangle(0, 0, 90, 125))); - var brush = new ImageBrush(overlay); + ImageBrush brush = new(overlay); background.Mutate(c => c.Fill(brush)); background.DebugSave(provider, appendSourceFileOrDescription: false); @@ -90,7 +90,7 @@ public void CanOffsetImage(TestImageProvider provider) using Image background = provider.GetImage(); using Image overlay = Image.Load(data); - var brush = new ImageBrush(overlay); + ImageBrush brush = new(overlay); background.Mutate(c => c.Fill(brush, new RectangularPolygon(0, 0, 400, 200))); background.Mutate(c => c.Fill(brush, new RectangularPolygon(-100, 200, 500, 200))); @@ -107,8 +107,8 @@ public void CanOffsetViaBrushImage(TestImageProvider provider) using Image background = provider.GetImage(); using Image overlay = Image.Load(data); - var brush = new ImageBrush(overlay); - var brushOffset = new ImageBrush(overlay, new Point(100, 0)); + ImageBrush brush = new(overlay); + ImageBrush brushOffset = new(overlay, new Point(100, 0)); background.Mutate(c => c.Fill(brush, new RectangularPolygon(0, 0, 400, 200))); background.Mutate(c => c.Fill(brushOffset, new RectangularPolygon(0, 200, 400, 200))); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillLinearGradientBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillLinearGradientBrushTests.cs index ee4e6ad7..fcac011c 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillLinearGradientBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillLinearGradientBrushTests.cs @@ -25,7 +25,7 @@ public void WithEqualColorsReturnsUnicolorImage(TestImageProvider(TestImageProvider pro TolerantComparer, image => { - var unicolorLinearGradientBrush = new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = new( new Point(0, 0), new Point(image.Width, 0), GradientRepetitionMode.None, @@ -73,7 +73,7 @@ public void HorizontalReturnsUnicolorColumns(TestImageProvider p Color red = Color.Red; Color yellow = Color.Yellow; - var unicolorLinearGradientBrush = new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = new( new Point(0, 0), new Point(image.Width, 0), GradientRepetitionMode.None, @@ -101,7 +101,7 @@ public void HorizontalGradientWithRepMode( Color red = Color.Red; Color yellow = Color.Yellow; - var unicolorLinearGradientBrush = new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = new( new Point(0, 0), new Point(image.Width / 10, 0), repetitionMode, @@ -147,8 +147,8 @@ public void WithDoubledStopsProduceDashedPatterns( using (Image image = provider.GetImage()) { - var unicolorLinearGradientBrush = - new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = + new( new Point(0, 0), new Point(image.Width, 0), GradientRepetitionMode.None, @@ -189,7 +189,7 @@ public void VerticalBrushReturnsUnicolorRows( Color red = Color.Red; Color yellow = Color.Yellow; - var unicolorLinearGradientBrush = new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = new( new Point(0, 0), new Point(0, image.Height), GradientRepetitionMode.None, @@ -247,8 +247,8 @@ public void DiagonalReturnsCorrectImages( Color red = Color.Red; Color yellow = Color.Yellow; - var unicolorLinearGradientBrush = - new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = + new( new Point(startX, startY), new Point(endX, endY), GradientRepetitionMode.None, @@ -303,13 +303,13 @@ public void ArbitraryGradients( where TPixel : unmanaged, IPixel { Color[] colors = - { + [ Color.Navy, Color.LightGreen, Color.Yellow, Color.Red - }; + ]; - var coloringVariant = new StringBuilder(); - var colorStops = new ColorStop[stopPositions.Length]; + StringBuilder coloringVariant = new(); + ColorStop[] colorStops = new ColorStop[stopPositions.Length]; for (int i = 0; i < stopPositions.Length; i++) { @@ -324,7 +324,7 @@ public void ArbitraryGradients( provider.VerifyOperation( image => { - var unicolorLinearGradientBrush = new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = new( new Point(startX, startY), new Point(endX, endY), GradientRepetitionMode.None, @@ -350,13 +350,13 @@ public void MultiplePointGradients( where TPixel : unmanaged, IPixel { Color[] colors = - { + [ Color.Black, Color.Blue, Color.Red, Color.White, Color.Lime - }; + ]; - var coloringVariant = new StringBuilder(); - var colorStops = new ColorStop[stopPositions.Length]; + StringBuilder coloringVariant = new(); + ColorStop[] colorStops = new ColorStop[stopPositions.Length]; for (int i = 0; i < stopPositions.Length; i++) { @@ -371,7 +371,7 @@ public void MultiplePointGradients( provider.VerifyOperation( image => { - var unicolorLinearGradientBrush = new LinearGradientBrush( + LinearGradientBrush unicolorLinearGradientBrush = new( new Point(startX, startY), new Point(endX, endY), GradientRepetitionMode.None, @@ -400,19 +400,19 @@ void ApplyGloss(IImageProcessingContext ctx) { Size size = ctx.GetCurrentSize(); IPathCollection glossPath = BuildGloss(size.Width, size.Height); - var graphicsOptions = new GraphicsOptions + GraphicsOptions graphicsOptions = new() { Antialias = true, ColorBlendingMode = PixelColorBlendingMode.Normal, AlphaCompositionMode = PixelAlphaCompositionMode.SrcAtop }; - var linearGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, size.Height / 2), GradientRepetitionMode.Repeat, new ColorStop(0, Color.White.WithAlpha(0.5f)), new ColorStop(1, Color.White.WithAlpha(0.25f))); + LinearGradientBrush linearGradientBrush = new(new Point(0, 0), new Point(0, size.Height / 2), GradientRepetitionMode.Repeat, new ColorStop(0, Color.White.WithAlpha(0.5f)), new ColorStop(1, Color.White.WithAlpha(0.25f))); ctx.SetGraphicsOptions(graphicsOptions).Fill(linearGradientBrush, glossPath); } IPathCollection BuildGloss(int imageWidth, int imageHeight) { - var pathBuilder = new PathBuilder(); + PathBuilder pathBuilder = new(); pathBuilder.AddLine(new PointF(0, 0), new PointF(imageWidth, 0)); pathBuilder.AddLine(new PointF(imageWidth, 0), new PointF(imageWidth, imageHeight * 0.4f)); pathBuilder.AddQuadraticBezier(new PointF(imageWidth, imageHeight * 0.4f), new PointF(imageWidth / 2, imageHeight * 0.6f), new PointF(0, imageHeight * 0.4f)); @@ -429,9 +429,9 @@ public void BrushApplicatorIsThreadSafeIssue1044(TestImageProvider { - var brush = new PathGradientBrush( - new[] { new PointF(0, 0), new PointF(200, 0), new PointF(200, 200), new PointF(0, 200), new PointF(0, 0) }, - new[] { Color.Red, Color.Yellow, Color.Green, Color.DarkCyan, Color.Red }); + PathGradientBrush brush = new( + [new PointF(0, 0), new PointF(200, 0), new PointF(200, 200), new PointF(0, 200), new PointF(0, 0)], + [Color.Red, Color.Yellow, Color.Green, Color.DarkCyan, Color.Red]); img.Mutate(m => m.Fill(brush)); }, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillOutsideBoundsTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillOutsideBoundsTests.cs index f3109f66..bdbd43e0 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillOutsideBoundsTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillOutsideBoundsTests.cs @@ -20,15 +20,15 @@ public void DrawRectactangleOutsideBoundsDrawingArea(int xpos) int width = 100; int height = 100; - using (var image = new Image(width, height, Color.Red.ToPixel())) + using (Image image = new(width, height, Color.Red.ToPixel())) { - var rectangle = new Rectangle(xpos, 0, width, height); + Rectangle rectangle = new(xpos, 0, width, height); image.Mutate(x => x.Fill(Color.Black, rectangle)); } } - public static TheoryData CircleCoordinates { get; } = new TheoryData() + public static TheoryData CircleCoordinates { get; } = new() { { -110, -60 }, { 0, -60 }, { 110, -60 }, { -110, -50 }, { 0, -50 }, { 110, -50 }, @@ -46,7 +46,7 @@ public void DrawCircleOutsideBoundsDrawingArea(TestImageProvider provide int height = 100; using Image image = provider.GetImage(); - var circle = new EllipsePolygon(xpos, ypos, width, height); + EllipsePolygon circle = new(xpos, ypos, width, height); provider.RunValidatingProcessorTest( x => x.Fill(Color.Black, circle), diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillPathGradientBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillPathGradientBrushTests.cs index 172e00be..15750e4c 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillPathGradientBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillPathGradientBrushTests.cs @@ -21,10 +21,10 @@ public void FillRectangleWithDifferentColors(TestImageProvider p TolerantComparer, image => { - PointF[] points = { new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10) }; - Color[] colors = { Color.Black, Color.Red, Color.Yellow, Color.Green }; + PointF[] points = [new(0, 0), new(10, 0), new(10, 10), new(0, 10)]; + Color[] colors = [Color.Black, Color.Red, Color.Yellow, Color.Green]; - var brush = new PathGradientBrush(points, colors); + PathGradientBrush brush = new(points, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -38,10 +38,10 @@ public void FillTriangleWithDifferentColors(TestImageProvider pr TolerantComparer, image => { - PointF[] points = { new PointF(10, 0), new PointF(20, 20), new PointF(0, 20) }; - Color[] colors = { Color.Red, Color.Green, Color.Blue }; + PointF[] points = [new(10, 0), new(20, 20), new(0, 20)]; + Color[] colors = [Color.Red, Color.Green, Color.Blue]; - var brush = new PathGradientBrush(points, colors); + PathGradientBrush brush = new(points, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -55,15 +55,15 @@ public void FillTriangleWithGreyscale(TestImageProvider provider ImageComparer.TolerantPercentage(0.02f), image => { - PointF[] points = { new PointF(10, 0), new PointF(20, 20), new PointF(0, 20) }; + PointF[] points = [new(10, 0), new(20, 20), new(0, 20)]; Color c1 = Color.FromPixel(new HalfSingle(-1)); Color c2 = Color.FromPixel(new HalfSingle(0)); Color c3 = Color.FromPixel(new HalfSingle(1)); - Color[] colors = { c1, c2, c3 }; + Color[] colors = [c1, c2, c3]; - var brush = new PathGradientBrush(points, colors); + PathGradientBrush brush = new(points, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -77,10 +77,10 @@ public void FillTriangleWithDifferentColorsCenter(TestImageProvider { - PointF[] points = { new PointF(10, 0), new PointF(20, 20), new PointF(0, 20) }; - Color[] colors = { Color.Red, Color.Green, Color.Blue }; + PointF[] points = [new(10, 0), new(20, 20), new(0, 20)]; + Color[] colors = [Color.Red, Color.Green, Color.Blue]; - var brush = new PathGradientBrush(points, colors, Color.White); + PathGradientBrush brush = new(points, colors, Color.White); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -93,10 +93,10 @@ public void FillRectangleWithSingleColor(TestImageProvider provi { using (Image image = provider.GetImage()) { - PointF[] points = { new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10) }; - Color[] colors = { Color.Red }; + PointF[] points = [new(0, 0), new(10, 0), new(10, 10), new(0, 10)]; + Color[] colors = [Color.Red]; - var brush = new PathGradientBrush(points, colors); + PathGradientBrush brush = new(points, colors); image.Mutate(x => x.Fill(brush)); @@ -112,10 +112,10 @@ public void ShouldRotateTheColorsWhenThereAreMorePoints(TestImageProvide TolerantComparer, image => { - PointF[] points = { new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10) }; - Color[] colors = { Color.Red, Color.Yellow }; + PointF[] points = [new(0, 0), new(10, 0), new(10, 10), new(0, 10)]; + Color[] colors = [Color.Red, Color.Yellow]; - var brush = new PathGradientBrush(points, colors); + PathGradientBrush brush = new(points, colors); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -129,10 +129,10 @@ public void FillWithCustomCenterColor(TestImageProvider provider TolerantComparer, image => { - PointF[] points = { new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10) }; - Color[] colors = { Color.Black, Color.Red, Color.Yellow, Color.Green }; + PointF[] points = [new(0, 0), new(10, 0), new(10, 10), new(0, 10)]; + Color[] colors = [Color.Black, Color.Red, Color.Yellow, Color.Green]; - var brush = new PathGradientBrush(points, colors, Color.White); + PathGradientBrush brush = new(points, colors, Color.White); image.Mutate(x => x.Fill(brush)); image.DebugSave(provider, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); @@ -141,9 +141,9 @@ public void FillWithCustomCenterColor(TestImageProvider provider [Fact] public void ShouldThrowArgumentNullExceptionWhenLinesAreNull() { - Color[] colors = { Color.Black, Color.Red, Color.Yellow, Color.Green }; + Color[] colors = [Color.Black, Color.Red, Color.Yellow, Color.Green]; - PathGradientBrush Create() => new PathGradientBrush(null, colors, Color.White); + PathGradientBrush Create() => new(null, colors, Color.White); Assert.Throws(Create); } @@ -151,10 +151,10 @@ public void ShouldThrowArgumentNullExceptionWhenLinesAreNull() [Fact] public void ShouldThrowArgumentOutOfRangeExceptionWhenLessThan3PointsAreGiven() { - PointF[] points = { new PointF(0, 0), new PointF(10, 0) }; - Color[] colors = { Color.Black, Color.Red, Color.Yellow, Color.Green }; + PointF[] points = [new(0, 0), new(10, 0)]; + Color[] colors = [Color.Black, Color.Red, Color.Yellow, Color.Green]; - PathGradientBrush Create() => new PathGradientBrush(points, colors, Color.White); + PathGradientBrush Create() => new(points, colors, Color.White); Assert.Throws(Create); } @@ -162,9 +162,9 @@ public void ShouldThrowArgumentOutOfRangeExceptionWhenLessThan3PointsAreGiven() [Fact] public void ShouldThrowArgumentNullExceptionWhenColorsAreNull() { - PointF[] points = { new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10) }; + PointF[] points = [new(0, 0), new(10, 0), new(10, 10), new(0, 10)]; - PathGradientBrush Create() => new PathGradientBrush(points, null, Color.White); + PathGradientBrush Create() => new(points, null, Color.White); Assert.Throws(Create); } @@ -172,11 +172,11 @@ public void ShouldThrowArgumentNullExceptionWhenColorsAreNull() [Fact] public void ShouldThrowArgumentOutOfRangeExceptionWhenEmptyColorArrayIsGiven() { - PointF[] points = { new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10) }; + PointF[] points = [new(0, 0), new(10, 0), new(10, 10), new(0, 10)]; - var colors = new Color[0]; + Color[] colors = []; - PathGradientBrush Create() => new PathGradientBrush(points, colors, Color.White); + PathGradientBrush Create() => new(points, colors, Color.White); Assert.Throws(Create); } @@ -189,15 +189,15 @@ public void FillComplex(TestImageProvider provider) new TolerantImageComparer(0.2f), image => { - var star = new Star(50, 50, 5, 20, 45); + Star star = new(50, 50, 5, 20, 45); PointF[] points = star.Points.ToArray(); Color[] colors = - { + [ Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple, Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple - }; + ]; - var brush = new PathGradientBrush(points, colors, Color.White); + PathGradientBrush brush = new(points, colors, Color.White); image.Mutate(x => x.Fill(brush)); }, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillPathTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillPathTests.cs index 39061a5d..1a6bcb5e 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillPathTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillPathTests.cs @@ -18,7 +18,7 @@ public class FillPathTests public void FillPathSVGArcs(TestImageProvider provider) where TPixel : unmanaged, IPixel { - var pb = new PathBuilder(); + PathBuilder pb = new(); pb.MoveTo(new Vector2(80, 80)) .ArcTo(45, 45, 0, false, false, new Vector2(125, 125)) @@ -114,7 +114,7 @@ public void FillPathArcToAlternates(TestImageProvider provider) where TPixel : unmanaged, IPixel { // Test alternate syntax. Both should overlap creating an orange arc. - var pb = new PathBuilder(); + PathBuilder pb = new(); pb.MoveTo(new Vector2(50, 50)); pb.ArcTo(20, 50, -72, false, true, new Vector2(200, 200)); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillPatternBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillPatternBrushTests.cs index 2e8451e1..5553faa6 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillPatternBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillPatternBrushTests.cs @@ -13,7 +13,7 @@ public class FillPatternBrushTests private void Test(string name, Color background, Brush brush, Color[,] expectedPattern) { string path = TestEnvironment.CreateOutputDirectory("Drawing", "FillPatternBrushTests"); - using (var image = new Image(20, 20)) + using (Image image = new(20, 20)) { image.Mutate(x => x.Fill(background).Fill(brush)); @@ -22,8 +22,8 @@ private void Test(string name, Color background, Brush brush, Color[,] expectedP Buffer2D sourcePixels = image.GetRootFramePixelBuffer(); // lets pick random spots to start checking - var r = new Random(); - var expectedPatternFast = new DenseMatrix(expectedPattern); + Random r = new(); + DenseMatrix expectedPatternFast = new(expectedPattern); int xStride = expectedPatternFast.Columns; int yStride = expectedPatternFast.Rows; int offsetX = r.Next(image.Width / xStride) * xStride; @@ -51,7 +51,7 @@ private void Test(string name, Color background, Brush brush, Color[,] expectedP [Fact] public void ImageShouldBeFloodFilledWithPercent10() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, @@ -69,7 +69,7 @@ public void ImageShouldBeFloodFilledWithPercent10() [Fact] public void ImageShouldBeFloodFilledWithPercent10Transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.HotPink, Color.Blue, Color.Blue, Color.Blue }, { Color.Blue, Color.Blue, Color.Blue, Color.Blue }, @@ -87,7 +87,7 @@ public void ImageShouldBeFloodFilledWithPercent10Transparent() [Fact] public void ImageShouldBeFloodFilledWithPercent20() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen }, @@ -105,7 +105,7 @@ public void ImageShouldBeFloodFilledWithPercent20() [Fact] public void ImageShouldBeFloodFilledWithPercent20_transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.HotPink, Color.Blue, Color.Blue, Color.Blue }, { Color.Blue, Color.Blue, Color.HotPink, Color.Blue }, @@ -123,7 +123,7 @@ public void ImageShouldBeFloodFilledWithPercent20_transparent() [Fact] public void ImageShouldBeFloodFilledWithHorizontal() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, { Color.HotPink, Color.HotPink, Color.HotPink, Color.HotPink }, @@ -141,7 +141,7 @@ public void ImageShouldBeFloodFilledWithHorizontal() [Fact] public void ImageShouldBeFloodFilledWithHorizontal_transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.Blue, Color.Blue, Color.Blue, Color.Blue }, { Color.HotPink, Color.HotPink, Color.HotPink, Color.HotPink }, @@ -159,7 +159,7 @@ public void ImageShouldBeFloodFilledWithHorizontal_transparent() [Fact] public void ImageShouldBeFloodFilledWithMin() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, @@ -177,7 +177,7 @@ public void ImageShouldBeFloodFilledWithMin() [Fact] public void ImageShouldBeFloodFilledWithMin_transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.Blue, Color.Blue, Color.Blue, Color.Blue }, { Color.Blue, Color.Blue, Color.Blue, Color.Blue }, @@ -195,7 +195,7 @@ public void ImageShouldBeFloodFilledWithMin_transparent() [Fact] public void ImageShouldBeFloodFilledWithVertical() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen }, { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen }, @@ -213,7 +213,7 @@ public void ImageShouldBeFloodFilledWithVertical() [Fact] public void ImageShouldBeFloodFilledWithVertical_transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.Blue, Color.HotPink, Color.Blue, Color.Blue }, { Color.Blue, Color.HotPink, Color.Blue, Color.Blue }, @@ -231,7 +231,7 @@ public void ImageShouldBeFloodFilledWithVertical_transparent() [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.LimeGreen, Color.LimeGreen, Color.LimeGreen, Color.HotPink }, { Color.LimeGreen, Color.LimeGreen, Color.HotPink, Color.LimeGreen }, @@ -249,7 +249,7 @@ public void ImageShouldBeFloodFilledWithForwardDiagonal() [Fact] public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.Blue, Color.Blue, Color.Blue, Color.HotPink }, { Color.Blue, Color.Blue, Color.HotPink, Color.Blue }, @@ -267,7 +267,7 @@ public void ImageShouldBeFloodFilledWithForwardDiagonal_transparent() [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.HotPink, Color.LimeGreen, Color.LimeGreen, Color.LimeGreen }, { Color.LimeGreen, Color.HotPink, Color.LimeGreen, Color.LimeGreen }, @@ -285,7 +285,7 @@ public void ImageShouldBeFloodFilledWithBackwardDiagonal() [Fact] public void ImageShouldBeFloodFilledWithBackwardDiagonal_transparent() { - var expectedPattern = new Color[,] + Color[,] expectedPattern = new Color[,] { { Color.HotPink, Color.Blue, Color.Blue, Color.Blue }, { Color.Blue, Color.HotPink, Color.Blue, Color.Blue }, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillPolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillPolygonTests.cs index 70004cff..bc4963cd 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillPolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillPolygonTests.cs @@ -22,7 +22,7 @@ public void FillPolygon_Solid_Basic(TestImageProvider provider, PointF[] polygon1 = PolygonFactory.CreatePointArray((2, 2), (6, 2), (6, 4), (2, 4)); PointF[] polygon2 = PolygonFactory.CreatePointArray((2, 8), (4, 6), (6, 8), (4, 10)); - var options = new GraphicsOptions { Antialias = antialias > 0, AntialiasSubpixelDepth = antialias }; + GraphicsOptions options = new() { Antialias = antialias > 0, AntialiasSubpixelDepth = antialias }; provider.RunValidatingProcessorTest( c => c.SetGraphicsOptions(options) .FillPolygon(Color.White, polygon1) @@ -41,12 +41,12 @@ public void FillPolygon_Solid(TestImageProvider provider, string where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }; + [ + new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) + ]; Color color = TestUtils.GetColorByName(colorName).WithAlpha(alpha); - var options = new GraphicsOptions { Antialias = antialias }; + GraphicsOptions options = new() { Antialias = antialias }; string aa = antialias ? string.Empty : "_NoAntialias"; FormattableString outputDetails = $"{colorName}_A{alpha}{aa}"; @@ -63,9 +63,9 @@ public void FillPolygon_Solid_Transformed(TestImageProvider prov where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }; + [ + new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) + ]; provider.RunValidatingProcessorTest( c => c.SetDrawingTransform(Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(-15), 0, new Vector2(200, 200))) @@ -77,7 +77,7 @@ public void FillPolygon_Solid_Transformed(TestImageProvider prov public void Fill_RectangularPolygon_Solid_Transformed(TestImageProvider provider) where TPixel : unmanaged, IPixel { - var polygon = new RectangularPolygon(25, 25, 50, 50); + RectangularPolygon polygon = new(25, 25, 50, 50); provider.RunValidatingProcessorTest( c => c.SetDrawingTransform(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))) @@ -89,13 +89,13 @@ public void Fill_RectangularPolygon_Solid_Transformed(TestImageProvider< public void Fill_RectangularPolygon_Solid_TransformedUsingConfiguration(TestImageProvider provider) where TPixel : unmanaged, IPixel { - var polygon = new RectangularPolygon(25, 25, 50, 50); + RectangularPolygon polygon = new(25, 25, 50, 50); provider.Configuration.SetDrawingTransform(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))); provider.RunValidatingProcessorTest(c => c.Fill(Color.White, polygon)); } public static TheoryData FillPolygon_Complex_Data { get; } = - new TheoryData() + new() { { false, IntersectionRule.EvenOdd }, { false, IntersectionRule.NonZero }, @@ -117,7 +117,7 @@ public void FillPolygon_Complex(TestImageProvider provider, bool Array.Reverse(hole); } - var polygon = new ComplexPolygon( + ComplexPolygon polygon = new( new Path(new LinearLineSegment(contour)), new Path(new LinearLineSegment(hole))); @@ -142,15 +142,15 @@ public void FillPolygon_Complex(TestImageProvider provider, bool public void FillPolygon_Concave(TestImageProvider provider, bool reverse) where TPixel : unmanaged, IPixel { - var points = new PointF[] - { - new Vector2(8, 8), + PointF[] points = + [ + new Vector2(8, 8), new Vector2(64, 8), new Vector2(64, 64), new Vector2(120, 64), new Vector2(120, 120), new Vector2(8, 120) - }; + ]; if (reverse) { Array.Reverse(points); @@ -170,8 +170,8 @@ public void FillPolygon_Concave(TestImageProvider provider, bool [WithSolidFilledImages(64, 64, "Black", PixelTypes.Rgba32)] public void FillPolygon_StarCircle(TestImageProvider provider) { - var circle = new EllipsePolygon(32, 32, 30); - var star = new Star(32, 32, 7, 10, 27); + EllipsePolygon circle = new(32, 32, 30); + Star star = new(32, 32, 7, 10, 27); IPath shape = circle.Clip(star); provider.RunValidatingProcessorTest( @@ -186,7 +186,7 @@ public void FillPolygon_StarCircle(TestImageProvider provider) public void FillPolygon_StarCircle_AllOperations(TestImageProvider provider) { IPath circle = new EllipsePolygon(36, 36, 36).Translate(28, 28); - var star = new Star(64, 64, 5, 24, 64); + Star star = new(64, 64, 5, 24, 64); // See http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/ClipType.htm for reference. foreach (ClippingOperation operation in (ClippingOperation[])Enum.GetValues(typeof(ClippingOperation))) @@ -209,9 +209,9 @@ public void FillPolygon_Pattern(TestImageProvider provider) where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }; + [ + new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) + ]; Color color = Color.Yellow; PatternBrush brush = Brushes.Horizontal(color); @@ -228,13 +228,13 @@ public void FillPolygon_ImageBrush(TestImageProvider provider, s where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 50), new Vector2(50, 200) - }; + [ + new Vector2(10, 10), new Vector2(200, 50), new Vector2(50, 200) + ]; - using (var brushImage = Image.Load(TestFile.Create(brushImageName).Bytes)) + using (Image brushImage = Image.Load(TestFile.Create(brushImageName).Bytes)) { - var brush = new ImageBrush(brushImage); + ImageBrush brush = new(brushImage); provider.RunValidatingProcessorTest( c => c.FillPolygon(brush, simplePath), @@ -250,18 +250,18 @@ public void FillPolygon_ImageBrush_Rect(TestImageProvider provid where TPixel : unmanaged, IPixel { PointF[] simplePath = - { - new Vector2(10, 10), new Vector2(200, 50), new Vector2(50, 200) - }; + [ + new Vector2(10, 10), new Vector2(200, 50), new Vector2(50, 200) + ]; - using (var brushImage = Image.Load(TestFile.Create(brushImageName).Bytes)) + using (Image brushImage = Image.Load(TestFile.Create(brushImageName).Bytes)) { float top = brushImage.Height / 4; float left = brushImage.Width / 4; float height = top * 2; float width = left * 2; - var brush = new ImageBrush(brushImage, new RectangleF(left, top, width, height)); + ImageBrush brush = new(brushImage, new RectangleF(left, top, width, height)); provider.RunValidatingProcessorTest( c => c.FillPolygon(brush, simplePath), @@ -275,7 +275,7 @@ public void FillPolygon_ImageBrush_Rect(TestImageProvider provid public void Fill_RectangularPolygon(TestImageProvider provider) where TPixel : unmanaged, IPixel { - var polygon = new RectangularPolygon(10, 10, 190, 140); + RectangularPolygon polygon = new(10, 10, 190, 140); Color color = Color.White; provider.RunValidatingProcessorTest( @@ -293,7 +293,7 @@ public void Fill_RegularPolygon(TestImageProvider provider, int where TPixel : unmanaged, IPixel { float angle = GeometryUtilities.DegreeToRadian(angleDeg); - var polygon = new RegularPolygon(100, 100, vertices, radius, angle); + RegularPolygon polygon = new(100, 100, vertices, radius, angle); Color color = Color.Yellow; FormattableString testOutput = $"V({vertices})_R({radius})_Ang({angleDeg})"; @@ -305,7 +305,7 @@ public void Fill_RegularPolygon(TestImageProvider provider, int } public static readonly TheoryData Fill_EllipsePolygon_Data = - new TheoryData() + new() { { false, IntersectionRule.EvenOdd }, { false, IntersectionRule.NonZero }, @@ -347,7 +347,7 @@ public void Fill_IntersectionRules_OddEven(TestImageProvider pro { using (Image img = provider.GetImage()) { - var poly = new Polygon(new LinearLineSegment( + Polygon poly = new(new LinearLineSegment( new PointF(10, 30), new PointF(10, 20), new PointF(50, 20), @@ -382,7 +382,7 @@ public void Fill_IntersectionRules_Nonzero(TestImageProvider pro Configuration.Default.MaxDegreeOfParallelism = 1; using (Image img = provider.GetImage()) { - var poly = new Polygon(new LinearLineSegment( + Polygon poly = new(new LinearLineSegment( new PointF(10, 30), new PointF(10, 20), new PointF(50, 20), diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillRadialGradientBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillRadialGradientBrushTests.cs index 5ed90eec..3fb5cbf9 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillRadialGradientBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillRadialGradientBrushTests.cs @@ -24,8 +24,8 @@ public void WithEqualColorsReturnsUnicolorImage( { Color red = Color.Red; - var unicolorRadialGradientBrush = - new RadialGradientBrush( + RadialGradientBrush unicolorRadialGradientBrush = + new( new Point(0, 0), 100, GradientRepetitionMode.None, @@ -57,7 +57,7 @@ public void WithDifferentCentersReturnsImage( TolerantComparer, image => { - var brush = new RadialGradientBrush( + RadialGradientBrush brush = new( new Point(centerX, centerY), image.Width / 2f, GradientRepetitionMode.None, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/FillSolidBrushTests.cs index c24e26e4..8ecbdef4 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/FillSolidBrushTests.cs @@ -74,7 +74,7 @@ public void FillRegion(TestImageProvider provider, int x0, int y where TPixel : unmanaged, IPixel { FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; - var region = new RectangleF(x0, y0, w, h); + RectangleF region = new(x0, y0, w, h); Color color = TestUtils.GetColorByName("Blue"); provider.RunValidatingProcessorTest(c => c.Fill(color, region), testDetails, ImageComparer.Exact); @@ -92,7 +92,7 @@ public void FillRegion_WorksOnWrappedMemoryImage( where TPixel : unmanaged, IPixel { FormattableString testDetails = $"(x{x0},y{y0},w{w},h{h})"; - var region = new RectangleF(x0, y0, w, h); + RectangleF region = new(x0, y0, w, h); Color color = TestUtils.GetColorByName("Blue"); provider.RunValidatingProcessorTestOnWrappedMemoryImage( @@ -103,8 +103,8 @@ public void FillRegion_WorksOnWrappedMemoryImage( } public static readonly TheoryData BlendData = - new TheoryData - { + new() + { { false, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f }, { false, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, { false, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f }, @@ -148,7 +148,7 @@ public void BlendFillColorOverBackground( { TPixel bgColor = image[0, 0]; - var options = new DrawingOptions + DrawingOptions options = new() { GraphicsOptions = new GraphicsOptions { @@ -160,7 +160,7 @@ public void BlendFillColorOverBackground( if (triggerFillRegion) { - var path = new RectangularPolygon(0, 0, 16, 16); + RectangularPolygon path = new(0, 0, 16, 16); image.Mutate(c => c.SetGraphicsOptions(options.GraphicsOptions).Fill(new SolidBrush(fillColor), path)); } else diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Clear.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Clear.cs index 99990c6a..c4b54af3 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Clear.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Clear.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class Clear : BaseImageOperationsExtensionTest { - private readonly DrawingOptions nonDefaultOptions = new DrawingOptions() + private readonly DrawingOptions nonDefaultOptions = new() { GraphicsOptions = { diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ClearPath.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ClearPath.cs index 1dab2850..15560240 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ClearPath.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ClearPath.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class ClearPath : BaseImageOperationsExtensionTest { - private readonly DrawingOptions nonDefaultOptions = new DrawingOptions() + private readonly DrawingOptions nonDefaultOptions = new() { GraphicsOptions = { diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ComputeLength.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ComputeLength.cs index d91f8ed6..d7d7bb4a 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ComputeLength.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/ComputeLength.cs @@ -8,7 +8,7 @@ public class ComputeLength [Fact] public void CanComputeUnrolledLength() { - var polygon = new RectangularPolygon(PointF.Empty, new PointF(100, 200)); + RectangularPolygon polygon = new(PointF.Empty, new PointF(100, 200)); Assert.Equal(600, polygon.ComputeLength()); } @@ -16,7 +16,7 @@ public void CanComputeUnrolledLength() [Fact] public void CanComputeUnrolledLengthComplexPath() { - var polygon = new ComplexPolygon( + ComplexPolygon polygon = new( new RectangularPolygon(PointF.Empty, new PointF(100, 200)), new RectangularPolygon(new PointF(1000, 1000), new PointF(1100, 1200))); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawBezier.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawBezier.cs index f8e2d00d..ef268520 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawBezier.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawBezier.cs @@ -10,13 +10,13 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class DrawBezier : BaseImageOperationsExtensionTest { private readonly SolidPen pen = Pens.Solid(Color.HotPink, 2); - private readonly PointF[] points = new PointF[] - { - new PointF(10, 10), - new PointF(20, 20), - new PointF(20, 50), - new PointF(50, 10) - }; + private readonly PointF[] points = + [ + new(10, 10), + new(20, 20), + new(20, 50), + new(50, 10) + ]; private void VerifyPoints(PointF[] expectedPoints, IPath path) { @@ -62,7 +62,7 @@ public void BrushAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -76,7 +76,7 @@ public void BrushAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -91,7 +91,7 @@ public void ColorAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(Color.Red, brush.Color); Assert.Equal(10, processorPen.StrokeWidth); } @@ -106,7 +106,7 @@ public void ColorAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(Color.Red, brush.Color); Assert.Equal(10, processorPen.StrokeWidth); } @@ -120,7 +120,7 @@ public void JointAndEndCapStyle() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } @@ -134,7 +134,7 @@ public void JointAndEndCapStyleDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawLine.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawLine.cs index 2568d753..6cdb5c25 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawLine.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawLine.cs @@ -10,13 +10,13 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class DrawLine : BaseImageOperationsExtensionTest { private readonly SolidPen pen = Pens.Solid(Color.HotPink, 2); - private readonly PointF[] points = new PointF[] - { - new PointF(10, 10), - new PointF(20, 20), - new PointF(20, 50), - new PointF(50, 10) - }; + private readonly PointF[] points = + [ + new(10, 10), + new(20, 20), + new(20, 50), + new(50, 10) + ]; private void VerifyPoints(PointF[] expectedPoints, IPath path) { @@ -58,7 +58,7 @@ public void BrushAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -72,7 +72,7 @@ public void BrushAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -87,7 +87,7 @@ public void ColorAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(Color.Red, brush.Color); Assert.Equal(10, processorPen.StrokeWidth); } @@ -103,7 +103,7 @@ public void ColorAndThicknessDefaultOptions() this.VerifyPoints(this.points, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, brush.Color); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -116,7 +116,7 @@ public void JointAndEndCapStyle() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } @@ -130,7 +130,7 @@ public void JointAndEndCapStyleDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPath.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPath.cs index 61436462..d57bf36d 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPath.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPath.cs @@ -46,7 +46,7 @@ public void BrushAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); Assert.Equal(this.path, processor.Path); Assert.Equal(this.pen.StrokeFill, processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -60,7 +60,7 @@ public void BrushAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); Assert.Equal(this.path, processor.Path); Assert.Equal(this.pen.StrokeFill, processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -75,7 +75,7 @@ public void ColorAndThickness() Assert.Equal(this.path, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, brush.Color); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -90,7 +90,7 @@ public void ColorAndThicknessDefaultOptions() Assert.Equal(this.path, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, brush.Color); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -103,7 +103,7 @@ public void JointAndEndCapStyle() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); Assert.Equal(this.path, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } @@ -117,7 +117,7 @@ public void JointAndEndCapStyleDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); Assert.Equal(this.path, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPathCollection.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPathCollection.cs index c8dfb82a..df0bbf1f 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPathCollection.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPathCollection.cs @@ -10,26 +10,24 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class DrawPathCollection : BaseImageOperationsExtensionTest { - private readonly GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; + private readonly GraphicsOptions nonDefault = new() { Antialias = false }; private readonly Color color = Color.HotPink; private readonly SolidPen pen = Pens.Solid(Color.HotPink, 1); private readonly IPath path1 = new Path(new LinearLineSegment( - new PointF[] - { - new Vector2(10, 10), + [ + new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), - new Vector2(30, 10), - })); + new Vector2(30, 10) + ])); private readonly IPath path2 = new Path(new LinearLineSegment( - new PointF[] - { - new Vector2(10, 10), + [ + new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), - new Vector2(30, 10), - })); + new Vector2(30, 10) + ])); private readonly IPathCollection pathCollection; @@ -82,7 +80,7 @@ public void BrushAndThickness() { Assert.NotEqual(this.shapeOptions, p.Options.ShapeOptions); Assert.Equal(this.pen.StrokeFill, p.Pen.StrokeFill); - var pPen = Assert.IsType(p.Pen); + SolidPen pPen = Assert.IsType(p.Pen); Assert.Equal(10, pPen.StrokeWidth); }); @@ -102,7 +100,7 @@ public void BrushAndThicknessDefaultOptions() { Assert.Equal(this.shapeOptions, p.Options.ShapeOptions); Assert.Equal(this.pen.StrokeFill, p.Pen.StrokeFill); - var pPen = Assert.IsType(p.Pen); + SolidPen pPen = Assert.IsType(p.Pen); Assert.Equal(10, pPen.StrokeWidth); }); @@ -123,7 +121,7 @@ public void ColorAndThickness() Assert.NotEqual(this.shapeOptions, p.Options.ShapeOptions); SolidBrush brush = Assert.IsType(p.Pen.StrokeFill); Assert.Equal(Color.Pink, brush.Color); - var pPen = Assert.IsType(p.Pen); + SolidPen pPen = Assert.IsType(p.Pen); Assert.Equal(10, pPen.StrokeWidth); }); @@ -144,7 +142,7 @@ public void ColorAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, p.Options.ShapeOptions); SolidBrush brush = Assert.IsType(p.Pen.StrokeFill); Assert.Equal(Color.Pink, brush.Color); - var pPen = Assert.IsType(p.Pen); + SolidPen pPen = Assert.IsType(p.Pen); Assert.Equal(10, pPen.StrokeWidth); }); @@ -163,7 +161,7 @@ public void JointAndEndCapStyle() Assert.All(processors, p => { Assert.NotEqual(this.shapeOptions, p.Options.ShapeOptions); - var pPen = Assert.IsType(p.Pen); + SolidPen pPen = Assert.IsType(p.Pen); Assert.Equal(this.pen.JointStyle, pPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, pPen.EndCapStyle); }); @@ -183,7 +181,7 @@ public void JointAndEndCapStyleDefaultOptions() Assert.All(processors, p => { Assert.Equal(this.shapeOptions, p.Options.ShapeOptions); - var pPen = Assert.IsType(p.Pen); + SolidPen pPen = Assert.IsType(p.Pen); Assert.Equal(this.pen.JointStyle, pPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, pPen.EndCapStyle); }); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPolygon.cs index a5f5b481..0b6900cc 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPolygon.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawPolygon.cs @@ -10,14 +10,14 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class DrawPolygon : BaseImageOperationsExtensionTest { private readonly SolidPen pen = Pens.Solid(Color.HotPink, 2); - private readonly PointF[] points = new[] - { + private readonly PointF[] points = + [ new PointF(10, 10), new PointF(10, 20), new PointF(20, 20), new PointF(25, 25), - new PointF(25, 10), - }; + new PointF(25, 10) + ]; private void VerifyPoints(PointF[] expectedPoints, IPath path) { @@ -59,7 +59,7 @@ public void BrushAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -73,7 +73,7 @@ public void BrushAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -88,7 +88,7 @@ public void ColorAndThickness() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(Color.Red, brush.Color); Assert.Equal(10, processorPen.StrokeWidth); } @@ -104,7 +104,7 @@ public void ColorAndThicknessDefaultOptions() this.VerifyPoints(this.points, processor.Path); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, brush.Color); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -117,7 +117,7 @@ public void JointAndEndCapStyle() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } @@ -131,7 +131,7 @@ public void JointAndEndCapStyleDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); this.VerifyPoints(this.points, processor.Path); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawRectangle.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawRectangle.cs index 41979213..b40b41c1 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawRectangle.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/DrawRectangle.cs @@ -11,9 +11,9 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class DrawRectangle : BaseImageOperationsExtensionTest { private readonly SolidPen pen = Pens.Solid(Color.HotPink, 2); - private RectangleF rectangle = new RectangleF(10, 10, 20, 20); + private RectangleF rectangle = new(10, 10, 20, 20); - private RectangularPolygon RectanglePolygon => new RectangularPolygon(this.rectangle); + private RectangularPolygon RectanglePolygon => new(this.rectangle); [Fact] public void CorrectlySetsPenAndPath() @@ -50,7 +50,7 @@ public void BrushAndThickness() Assert.True(RectangularPolygonValueComparer.Equals(this.RectanglePolygon, processor.Path)); Assert.NotEqual(this.pen, processor.Pen); Assert.Equal(this.pen.StrokeFill, processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -64,7 +64,7 @@ public void BrushAndThicknessDefaultOptions() Assert.Equal(this.shapeOptions, processor.Options.ShapeOptions); Assert.True(RectangularPolygonValueComparer.Equals(this.RectanglePolygon, processor.Path)); Assert.NotEqual(this.pen, processor.Pen); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.StrokeFill, processorPen.StrokeFill); Assert.Equal(10, processorPen.StrokeWidth); } @@ -80,7 +80,7 @@ public void ColorAndThickness() Assert.True(RectangularPolygonValueComparer.Equals(this.RectanglePolygon, processor.Path)); Assert.NotEqual(this.pen, processor.Pen); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(Color.Red, brush.Color); Assert.Equal(10, processorPen.StrokeWidth); } @@ -97,7 +97,7 @@ public void ColorAndThicknessDefaultOptions() Assert.NotEqual(this.pen, processor.Pen); SolidBrush brush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, brush.Color); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(10, processorPen.StrokeWidth); } @@ -111,7 +111,7 @@ public void JointAndEndCapStyle() Assert.NotEqual(this.shapeOptions, processor.Options.ShapeOptions); Assert.True(RectangularPolygonValueComparer.Equals(this.RectanglePolygon, processor.Path)); Assert.NotEqual(this.pen, processor.Pen); - var processorPen = Assert.IsType(processor.Pen); + SolidPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(this.pen.JointStyle, processorPen.JointStyle); Assert.Equal(this.pen.EndCapStyle, processorPen.EndCapStyle); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Fill.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Fill.cs index c1c68e41..f4cdcd2b 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Fill.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/Fill.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class Fill : BaseImageOperationsExtensionTest { - private readonly DrawingOptions nonDefaultOptions = new DrawingOptions(); + private readonly DrawingOptions nonDefaultOptions = new(); private readonly Brush brush = new SolidBrush(Color.HotPink); [Fact] diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathBuilder.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathBuilder.cs index 33836fa5..070f2577 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathBuilder.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathBuilder.cs @@ -22,7 +22,7 @@ public class FillPathBuilder : BaseImageOperationsExtensionTest public FillPathBuilder() { - var pb = new PathBuilder(); + PathBuilder pb = new(); this.builder(pb); this.path = pb.Build(); } diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathCollection.cs index 4f56d6dc..aca2d2e0 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPathCollection.cs @@ -13,22 +13,20 @@ public class FillPathCollection : BaseImageOperationsExtensionTest private readonly Color color = Color.HotPink; private readonly SolidBrush brush = Brushes.Solid(Color.HotPink); private readonly IPath path1 = new Path(new LinearLineSegment( - new PointF[] - { - new Vector2(10, 10), + [ + new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), - new Vector2(30, 10), - })); + new Vector2(30, 10) + ])); private readonly IPath path2 = new Path(new LinearLineSegment( - new PointF[] - { - new Vector2(10, 10), + [ + new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), - new Vector2(30, 10), - })); + new Vector2(30, 10) + ])); private readonly IPathCollection pathCollection; diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPolygon.cs index bce3189e..bac4ffb0 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillPolygon.cs @@ -10,14 +10,14 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class FillPolygon : BaseImageOperationsExtensionTest { private readonly Brush brush = Brushes.Solid(Color.HotPink); - private readonly PointF[] path = new[] - { + private readonly PointF[] path = + [ new PointF(10, 10), new PointF(10, 20), new PointF(20, 20), new PointF(25, 25), - new PointF(25, 10), - }; + new PointF(25, 10) + ]; private void VerifyPoints(PointF[] expectedPoints, IPath path) { diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillRectangle.cs index fdc62867..a13537d4 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Paths/FillRectangle.cs @@ -11,9 +11,9 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Paths; public class FillRectangle : BaseImageOperationsExtensionTest { private readonly Brush brush = Brushes.Solid(Color.HotPink); - private RectangleF rectangle = new RectangleF(10, 10, 20, 20); + private RectangleF rectangle = new(10, 10, 20, 20); - private RectangularPolygon RectanglePolygon => new RectangularPolygon(this.rectangle); + private RectangularPolygon RectanglePolygon => new(this.rectangle); [Fact] public void Brush() diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/RecolorImageTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/RecolorImageTests.cs index 32023053..289971c8 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/RecolorImageTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/RecolorImageTests.cs @@ -19,7 +19,7 @@ public void Recolor(TestImageProvider provider, string sourceCol { Color sourceColor = TestUtils.GetColorByName(sourceColorName); Color targetColor = TestUtils.GetColorByName(targetColorName); - var brush = new RecolorBrush(sourceColor, targetColor, threshold); + RecolorBrush brush = new(sourceColor, targetColor, threshold); FormattableString testInfo = $"{sourceColorName}-{targetColorName}-{threshold}"; provider.RunValidatingProcessorTest(x => x.Fill(brush), testInfo); @@ -33,14 +33,14 @@ public void Recolor_InBox(TestImageProvider provider, string sou { Color sourceColor = TestUtils.GetColorByName(sourceColorName); Color targetColor = TestUtils.GetColorByName(targetColorName); - var brush = new RecolorBrush(sourceColor, targetColor, threshold); + RecolorBrush brush = new(sourceColor, targetColor, threshold); FormattableString testInfo = $"{sourceColorName}-{targetColorName}-{threshold}"; provider.RunValidatingProcessorTest( x => { Size size = x.GetCurrentSize(); - var rectangle = new Rectangle(0, (size.Height / 2) - (size.Height / 4), size.Width, size.Height / 2); + Rectangle rectangle = new(0, (size.Height / 2) - (size.Height / 4), size.Width, size.Height / 2); x.Fill(brush, rectangle); }, testInfo); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/SolidBezierTests.cs index dd6a7b0b..11e80c5c 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/SolidBezierTests.cs @@ -17,12 +17,12 @@ public void FilledBezier(TestImageProvider provider) where TPixel : unmanaged, IPixel { PointF[] simplePath = - { + [ new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }; + ]; Color blue = Color.Blue; Color hotPink = Color.HotPink; @@ -42,16 +42,16 @@ public void OverlayByFilledPolygonOpacity(TestImageProvider prov where TPixel : unmanaged, IPixel { PointF[] simplePath = - { + [ new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }; + ]; Color color = Color.HotPink.WithAlpha(150 / 255F); - using (var image = provider.GetImage() as Image) + using (Image image = provider.GetImage() as Image) { image.Mutate(x => x.BackgroundColor(Color.Blue)); image.Mutate(x => x.Fill(color, new Polygon(new CubicBezierLineSegment(simplePath)))); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/SolidFillBlendedShapesTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/SolidFillBlendedShapesTests.cs index ae35048d..f6464394 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/SolidFillBlendedShapesTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/SolidFillBlendedShapesTests.cs @@ -20,7 +20,7 @@ private static IEnumerable GetAllModeCombinations() { foreach (object blending in Enum.GetValues(typeof(PixelColorBlendingMode))) { - yield return new object[] { blending, composition }; + yield return [blending, composition]; } } } @@ -193,7 +193,7 @@ private static void VerifyImage( appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); - var comparer = ImageComparer.TolerantPercentage(0.01f, 3); + ImageComparer comparer = ImageComparer.TolerantPercentage(0.01f, 3); img.CompareFirstFrameToReferenceOutput( comparer, provider, diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawText.cs index 1288ff7b..4355855e 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawText.cs @@ -24,7 +24,7 @@ public DrawText() { this.fontCollection = new FontCollection(); this.font = this.fontCollection.Add(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12); - this.textOptions = new(this.font) { WrappingLength = 99 }; + this.textOptions = new RichTextOptions(this.font) { WrappingLength = 99 }; } [Fact] @@ -146,7 +146,7 @@ public void DrawForEachACharacterWhenPenSetDefaultOptions() Assert.Equal(this.font, processor.TextOptions.Font); SolidBrush penBrush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, penBrush.Color); - var processorPen = Assert.IsType(processor.Pen); + PatternPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(1, processorPen.StrokeWidth); Assert.Equal(PointF.Empty, processor.Location); Assert.Equal(this.textOptions, processor.TextOptions); @@ -173,7 +173,7 @@ public void DrawForEachACharacterWhenPenSetAndFillFroEachWhenBrushSet() Assert.Equal(PointF.Empty, processor.Location); SolidBrush penBrush = Assert.IsType(processor.Pen.StrokeFill); Assert.Equal(Color.Red, penBrush.Color); - var processorPen = Assert.IsType(processor.Pen); + PatternPen processorPen = Assert.IsType(processor.Pen); Assert.Equal(1, processorPen.StrokeWidth); Assert.NotEqual(this.textOptions, processor.TextOptions); Assert.NotEqual(this.graphicsOptions, processor.DrawingOptions.GraphicsOptions); diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs b/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs index 187f0152..4ec2015d 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/Text/DrawTextOnImageTests.cs @@ -51,7 +51,7 @@ public void EmojiFontRendering(TestImageProvider provider, Color HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, - FallbackFontFamilies = new[] { emojiFontFamily }, + FallbackFontFamilies = [emojiFontFamily], ColorFontSupport = colorFontSupport, Origin = new PointF(img.Width / 2, img.Height / 2) }; @@ -67,7 +67,7 @@ public void FallbackFontRendering(TestImageProvider provider) where TPixel : unmanaged, IPixel { // https://github.com/SixLabors/Fonts/issues/171 - var collection = new FontCollection(); + FontCollection collection = new(); Font whitney = CreateFont(TestFonts.WhitneyBook, 25); FontFamily malgun = CreateFont(TestFonts.Malgun, 25).Family; @@ -83,7 +83,7 @@ public void FallbackFontRendering(TestImageProvider provider) HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, - FallbackFontFamilies = new[] { malgun }, + FallbackFontFamilies = [malgun], KerningMode = KerningMode.Standard, Origin = new PointF(img.Width / 2, img.Height / 2) }; @@ -110,7 +110,7 @@ public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688(TestIm float scalingFactor = Math.Min(img.Width / size.Width, img.Height / size.Height); // Create a new font - var scaledFont = new Font(font, scalingFactor * font.Size); + Font scaledFont = new(font, scalingFactor * font.Size); RichTextOptions textOptions = new(scaledFont) { HorizontalAlignment = HorizontalAlignment.Center, @@ -130,7 +130,7 @@ public void DoesntThrowExceptionWhenOverlappingRightEdge_Issue688_2(Test Font font = CreateFont(TestFonts.OpenSans, 39); string text = new('a', 10000); Color color = Color.Black; - var point = new PointF(100, 100); + PointF point = new(100, 100); using Image img = provider.GetImage(); img.Mutate(ctx => ctx.DrawText(text, font, color, point)); @@ -265,7 +265,7 @@ public void FontShapesAreRenderedCorrectly_LargeText( { Font font = CreateFont(TestFonts.OpenSans, 36); - var sb = new StringBuilder(); + StringBuilder sb = new(); string str = Repeat(" ", 78) + "THISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDSTHISISTESTWORDS"; sb.Append(str); @@ -278,7 +278,7 @@ public void FontShapesAreRenderedCorrectly_LargeText( } // Strict comparer, because the image is sparse: - var comparer = ImageComparer.TolerantPercentage(0.0001F); + ImageComparer comparer = ImageComparer.TolerantPercentage(0.0001F); provider.VerifyOperation( comparer, @@ -303,7 +303,7 @@ public void FontShapesAreRenderedCorrectly_WithLineSpacing( { Font font = CreateFont(TestFonts.OpenSans, 16); - var sb = new StringBuilder(); + StringBuilder sb = new(); string str = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna."; for (int i = 0; i < lineCount; i++) @@ -328,7 +328,7 @@ public void FontShapesAreRenderedCorrectly_WithLineSpacing( Color color = Color.Black; // NET472 is 0.0045 different. - var comparer = ImageComparer.TolerantPercentage(0.0046F); + ImageComparer comparer = ImageComparer.TolerantPercentage(0.0046F); provider.VerifyOperation( comparer, @@ -407,7 +407,7 @@ public void TextPositioningIsRobust(TestImageProvider provider, // Based on the reported 0.1755% difference with AccuracyMultiple = 8 // We should avoid quality regressions leading to higher difference! - var comparer = ImageComparer.TolerantPercentage(0.2f); + ImageComparer comparer = ImageComparer.TolerantPercentage(0.2f); provider.RunValidatingProcessorTest( x => x.DrawText(textOptions, text, Color.Black), @@ -428,7 +428,7 @@ public void CanDrawTextWithEmptyPath() Assert.NotEqual(FontRectangle.Empty, textSize); - using var image = new Image(Configuration.Default, (int)textSize.Width + 20, (int)textSize.Height + 20); + using Image image = new(Configuration.Default, (int)textSize.Width + 20, (int)textSize.Height + 20); image.Mutate(x => x.DrawText( text, font, @@ -506,8 +506,8 @@ public void DrawRichText( { Origin = new Vector2(15), WrappingLength = 400, - TextRuns = new[] - { + TextRuns = + [ new RichTextRun { Start = 0, @@ -552,7 +552,7 @@ public void DrawRichText( TextDecorations = TextDecorations.Underline, UnderlinePen = Pens.Solid(Color.White), } - } + ] }; provider.RunValidatingProcessorTest( x => x.DrawText(textOptions, text, Color.White), @@ -577,10 +577,10 @@ public void DrawRichTextArabic( { Origin = new Vector2(15), WrappingLength = 400, - TextRuns = new[] - { + TextRuns = + [ new RichTextRun { Start = 0, End = CodePoint.GetCodePointCount(text.AsSpan()), TextDecorations = TextDecorations.Underline } - } + ] }; provider.RunValidatingProcessorTest( x => x.DrawText(textOptions, text, Color.White), @@ -601,8 +601,8 @@ public void DrawRichTextRainbow( Font font = CreateFont(TestFonts.OpenSans, fontSize); const string text = "The quick brown fox jumps over the lazy dog"; - SolidPen[] colors = new[] - { + SolidPen[] colors = + [ new SolidPen(Color.Red), new SolidPen(Color.Orange), new SolidPen(Color.Yellow), @@ -610,9 +610,9 @@ public void DrawRichTextRainbow( new SolidPen(Color.Blue), new SolidPen(Color.Indigo), new SolidPen(Color.Violet) - }; + ]; - var runs = new List(); + List runs = []; for (int i = 0; i < text.Length; i++) { SolidPen pen = colors[i % colors.Length]; @@ -665,7 +665,7 @@ public void CanDrawRichTextAlongPathHorizontal(TestImageProvider VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Path = path, - TextRuns = new[] { run } + TextRuns = [run] }; provider.RunValidatingProcessorTest( @@ -762,11 +762,11 @@ public void PathAndTextDrawingMatch(TestImageProvider provider) FontRectangle bounds = TextMeasurer.MeasureBounds(text, to); float x = (img.Size.Width - bounds.Width) / 2; - PointF[] pathLine = new[] - { + PointF[] pathLine = + [ new PointF(x, 500), new PointF(x + bounds.Width, 500) - }; + ]; IPath path = new PathBuilder().AddLine(pathLine[0], pathLine[1]).Build(); @@ -799,17 +799,18 @@ public void CanFillTextVertical(TestImageProvider provider) const string text = "한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo"; RichTextOptions textOptions = new(font) { - Origin = new(0, 0), - FallbackFontFamilies = new[] { fallback.Family }, + Origin = new Vector2(0, 0), + FallbackFontFamilies = [fallback.Family], WrappingLength = 300, LayoutMode = LayoutMode.VerticalLeftRight, - TextRuns = new[] { new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } } + TextRuns = [new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } + ] }; IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions); // TODO: This still leaves some holes when overlaying the text (CFF NotoSansKRRegular only). We need to fix this. - DrawingOptions options = new() { ShapeOptions = new() { IntersectionRule = IntersectionRule.NonZero } }; + DrawingOptions options = new() { ShapeOptions = new ShapeOptions { IntersectionRule = IntersectionRule.NonZero } }; provider.RunValidatingProcessorTest( c => c.Fill(Color.White).Fill(options, Color.Black, glyphs), @@ -827,16 +828,17 @@ public void CanFillTextVerticalMixed(TestImageProvider provider) const string text = "한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo"; RichTextOptions textOptions = new(font) { - FallbackFontFamilies = new[] { fallback.Family }, + FallbackFontFamilies = [fallback.Family], WrappingLength = 400, LayoutMode = LayoutMode.VerticalMixedLeftRight, - TextRuns = new[] { new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } } + TextRuns = [new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } + ] }; IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, textOptions); // TODO: This still leaves some holes when overlaying the text (CFF NotoSansKRRegular only). We need to fix this. - DrawingOptions options = new() { ShapeOptions = new() { IntersectionRule = IntersectionRule.NonZero } }; + DrawingOptions options = new() { ShapeOptions = new ShapeOptions { IntersectionRule = IntersectionRule.NonZero } }; provider.RunValidatingProcessorTest( c => c.Fill(Color.White).Fill(options, Color.Black, glyphs), @@ -854,11 +856,12 @@ public void CanDrawTextVertical(TestImageProvider provider) const string text = "한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo"; RichTextOptions textOptions = new(font) { - FallbackFontFamilies = new[] { fallback.Family }, + FallbackFontFamilies = [fallback.Family], WrappingLength = 400, LayoutMode = LayoutMode.VerticalLeftRight, LineSpacing = 1.4F, - TextRuns = new[] { new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } } + TextRuns = [new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } + ] }; provider.RunValidatingProcessorTest( @@ -899,7 +902,7 @@ public void CanDrawTextVerticalMixed(TestImageProvider provider) const string text = "한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo 한국어 hangugeo"; RichTextOptions textOptions = new(font) { - FallbackFontFamilies = new[] { fallback.Family }, + FallbackFontFamilies = [fallback.Family], WrappingLength = 400, LayoutMode = LayoutMode.VerticalMixedLeftRight, LineSpacing = 1.4F, @@ -924,7 +927,8 @@ public void CanDrawTextVerticalMixed2(TestImageProvider provider { LayoutMode = LayoutMode.VerticalMixedLeftRight, LineSpacing = 1.4F, - TextRuns = new[] { new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } } + TextRuns = [new RichTextRun() { Start = 0, End = text.GetGraphemeCount(), TextDecorations = TextDecorations.Underline | TextDecorations.Strikeout | TextDecorations.Overline } + ] }; provider.RunValidatingProcessorTest( diff --git a/tests/ImageSharp.Drawing.Tests/GraphicsOptionsTests.cs b/tests/ImageSharp.Drawing.Tests/GraphicsOptionsTests.cs index 2aa8bbc0..a41be44b 100644 --- a/tests/ImageSharp.Drawing.Tests/GraphicsOptionsTests.cs +++ b/tests/ImageSharp.Drawing.Tests/GraphicsOptionsTests.cs @@ -8,8 +8,8 @@ namespace SixLabors.ImageSharp.Drawing.Tests; public class GraphicsOptionsTests { - private static readonly GraphicsOptionsComparer GraphicsOptionsComparer = new GraphicsOptionsComparer(); - private readonly GraphicsOptions newGraphicsOptions = new GraphicsOptions(); + private static readonly GraphicsOptionsComparer GraphicsOptionsComparer = new(); + private readonly GraphicsOptions newGraphicsOptions = new(); private readonly GraphicsOptions cloneGraphicsOptions = new GraphicsOptions().DeepClone(); [Fact] @@ -57,7 +57,7 @@ public void DefaultGraphicsOptionsAlphaCompositionMode() [Fact] public void NonDefaultClone() { - var expected = new GraphicsOptions + GraphicsOptions expected = new() { AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop, Antialias = false, @@ -74,7 +74,7 @@ public void NonDefaultClone() [Fact] public void CloneIsDeep() { - var expected = new GraphicsOptions(); + GraphicsOptions expected = new(); GraphicsOptions actual = expected.DeepClone(); actual.AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop; diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs index 6a5c767c..1b8b4377 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_28_108.cs @@ -18,7 +18,7 @@ public class Issue_28_108 [InlineData(3F)] public void DrawingLineAtTopShouldDisplay(float stroke) { - using var image = new Image(Configuration.Default, 100, 100, Color.Black.ToPixel()); + using Image image = new(Configuration.Default, 100, 100, Color.Black.ToPixel()); image.Mutate(x => x .SetGraphicsOptions(g => g.Antialias = false) .DrawLine( @@ -38,7 +38,7 @@ public void DrawingLineAtTopShouldDisplay(float stroke) [InlineData(3F)] public void DrawingLineAtBottomShouldDisplay(float stroke) { - using var image = new Image(Configuration.Default, 100, 100, Color.Black.ToPixel()); + using Image image = new(Configuration.Default, 100, 100, Color.Black.ToPixel()); image.Mutate(x => x .SetGraphicsOptions(g => g.Antialias = false) .DrawLine( @@ -58,7 +58,7 @@ public void DrawingLineAtBottomShouldDisplay(float stroke) [InlineData(3F)] public void DrawingLineAtLeftShouldDisplay(float stroke) { - using var image = new Image(Configuration.Default, 100, 100, Color.Black.ToPixel()); + using Image image = new(Configuration.Default, 100, 100, Color.Black.ToPixel()); image.Mutate(x => x .SetGraphicsOptions(g => g.Antialias = false) .DrawLine( @@ -78,7 +78,7 @@ public void DrawingLineAtLeftShouldDisplay(float stroke) [InlineData(3F)] public void DrawingLineAtRightShouldDisplay(float stroke) { - using var image = new Image(Configuration.Default, 100, 100, Color.Black.ToPixel()); + using Image image = new(Configuration.Default, 100, 100, Color.Black.ToPixel()); image.Mutate(x => x .SetGraphicsOptions(g => g.Antialias = false) .DrawLine( diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_323.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_323.cs index af8bae86..631058a5 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_323.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_323.cs @@ -40,7 +40,7 @@ public void DrawPolygonMustDrawoutlineOnly_Pattern(TestImageProvider { Color color = Color.RebeccaPurple; - var pen = Pens.DashDot(color, scale); + PatternPen pen = Pens.DashDot(color, scale); provider.RunValidatingProcessorTest( x => x.DrawPolygon( pen, diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_37.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_37.cs index c2237dce..31e15603 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_37.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_37.cs @@ -17,12 +17,12 @@ public void CanRenderLargeFont() return; } - using (var image = new Image(300, 200)) + using (Image image = new(300, 200)) { string text = "TEST text foiw|\\"; Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 40, Fonts.FontStyle.Regular); - var graphicsOptions = new GraphicsOptions { Antialias = false }; + GraphicsOptions graphicsOptions = new() { Antialias = false }; image.Mutate( x => x.BackgroundColor(Color.White) .DrawLine( diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_46.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_46.cs index 3862d193..41e6d410 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_46.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_46.cs @@ -23,7 +23,7 @@ public void CanRenderCustomFont() const int imageSize = 300; - using var image = new Image(imageSize, imageSize); + using Image image = new(imageSize, imageSize); string iconText = char.ConvertFromUtf32(int.Parse("e926", NumberStyles.HexNumber)); @@ -38,7 +38,7 @@ public void CanRenderCustomFont() private static Font CreateFont(string fontName, int size) { - var fontCollection = new FontCollection(); + FontCollection fontCollection = new(); string fontPath = TestFontUtilities.GetPath(fontName); return fontCollection.Add(fontPath).CreateFont(size); } diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_54.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_54.cs index 74d71dd1..32e594f8 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_54.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_54.cs @@ -18,7 +18,7 @@ public void CanDrawWithoutMemoryException() int height = 438; // Creates a new image with empty pixel data. - using (var image = new Image(width, height)) + using (Image image = new(width, height)) { FontFamily family = SystemFonts.Get("verdana"); Font font = family.CreateFont(48, FontStyle.Bold); @@ -55,7 +55,7 @@ public void PenMustHaveAWidthGreaterThanZero() [Fact] public void ComplexPolygoWithZeroPathsCausesBoundsToBeNonSensicalValue() { - var polygon = new ComplexPolygon(Array.Empty()); + ComplexPolygon polygon = new(Array.Empty()); Assert.NotEqual(float.NegativeInfinity, polygon.Bounds.Width); Assert.NotEqual(float.PositiveInfinity, polygon.Bounds.Width); diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issues_55_59.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issues_55_59.cs index 4101cfda..1e25f761 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issues_55_59.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issues_55_59.cs @@ -14,29 +14,29 @@ public class Issues_55_59 [Fact] public void SimplifyOutOfRangeExceptionDrawLines() { - PointF[] line = new[] - { + PointF[] line = + [ new PointF(1, 48), new PointF(5, 77), new PointF(35, 0), new PointF(33, 8), new PointF(11, 23) - }; + ]; - using var image = new Image(100, 100); + using Image image = new(100, 100); image.Mutate(imageContext => imageContext.DrawLine(Color.FromPixel(new Rgba32(255, 0, 0)), 1, line)); } [Fact] public void SimplifyOutOfRangeExceptionDraw() { - var path = new Path( + Path path = new( new LinearLineSegment(new PointF(592.0153f, 1156.238f), new PointF(592.4992f, 1157.138f)), new LinearLineSegment(new PointF(592.4992f, 1157.138f), new PointF(593.3998f, 1156.654f)), new LinearLineSegment(new PointF(593.3998f, 1156.654f), new PointF(592.916f, 1155.754f)), new LinearLineSegment(new PointF(592.916f, 1155.754f), new PointF(592.0153f, 1156.238f))); - using var image = new Image(2000, 2000); + using Image image = new(2000, 2000); image.Mutate(imageContext => imageContext.Draw(Color.FromPixel(new Rgba32(255, 0, 0)), 1, path)); } } diff --git a/tests/ImageSharp.Drawing.Tests/MemoryAllocatorValidator.cs b/tests/ImageSharp.Drawing.Tests/MemoryAllocatorValidator.cs index da6f7832..a760d29e 100644 --- a/tests/ImageSharp.Drawing.Tests/MemoryAllocatorValidator.cs +++ b/tests/ImageSharp.Drawing.Tests/MemoryAllocatorValidator.cs @@ -38,7 +38,7 @@ private static void MemoryDiagnostics_MemoryAllocated() public static TestMemoryDiagnostics MonitorAllocations() { - var diag = new TestMemoryDiagnostics(); + TestMemoryDiagnostics diag = new(); LocalInstance.Value = diag; return diag; } @@ -56,8 +56,8 @@ public class TestMemoryDiagnostics : IDisposable public void Validate(int expectedAllocationCount) { - var count = this.TotalRemainingAllocated; - var pass = expectedAllocationCount == count; + int count = this.TotalRemainingAllocated; + bool pass = expectedAllocationCount == count; Assert.True(pass, $"Expected a {expectedAllocationCount} undisposed buffers but found {count}"); } diff --git a/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs index ee1a0ecf..926b355c 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/BaseImageOperationsExtensionTest.cs @@ -41,7 +41,7 @@ public BaseImageOperationsExtensionTest() public IEnumerable VerifyAll() { - List items = new(); + List items = []; Assert.All(this.internalOperations.Applied, operation => { if (operation.NonGenericProcessor != null) diff --git a/tests/ImageSharp.Drawing.Tests/Processing/FakeImageOperationsProvider.cs b/tests/ImageSharp.Drawing.Tests/Processing/FakeImageOperationsProvider.cs index 75d5d427..4039ee15 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/FakeImageOperationsProvider.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Processing; internal class FakeImageOperationsProvider : IImageProcessingContextFactory { - private readonly List imageOperators = new List(); + private readonly List imageOperators = []; public bool HasCreated(Image source) where TPixel : unmanaged, IPixel @@ -27,7 +27,7 @@ public IEnumerable> Created(Image so public IInternalImageProcessingContext CreateImageProcessingContext(Configuration configuration, Image source, bool mutate) where TPixel : unmanaged, IPixel { - var op = new FakeImageOperations(configuration, source, mutate); + FakeImageOperations op = new(configuration, source, mutate); this.imageOperators.Add(op); return op; } @@ -43,7 +43,7 @@ public FakeImageOperations(Configuration configuration, Image source, bo public Image Source { get; } - public List Applied { get; } = new List(); + public List Applied { get; } = []; public Configuration Configuration { get; } diff --git a/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs index 832d4adc..48d61f96 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/FillPathProcessorTests.cs @@ -18,28 +18,28 @@ public class FillPathProcessorTests [Fact] public void FillOffCanvas() { - var bounds = new Rectangle(-100, -10, 10, 10); + Rectangle bounds = new(-100, -10, 10, 10); // Specifically not using RectangularPolygon here to ensure the FillPathProcessor is used. - var points = new LinearLineSegment[] - { - new LinearLineSegment(new PointF(bounds.Left, bounds.Top), new PointF(bounds.Right, bounds.Top)), - new LinearLineSegment(new PointF(bounds.Right, bounds.Top), new PointF(bounds.Right, bounds.Bottom)), - new LinearLineSegment(new PointF(bounds.Right, bounds.Bottom), new PointF(bounds.Left, bounds.Bottom)), - new LinearLineSegment(new PointF(bounds.Left, bounds.Bottom), new PointF(bounds.Left, bounds.Top)) - }; - var path = new Path(points); - var brush = new Mock(); - var options = new GraphicsOptions { Antialias = true }; - var processor = new FillPathProcessor(new DrawingOptions() { GraphicsOptions = options }, brush.Object, path); - var img = new Image(10, 10); + LinearLineSegment[] points = + [ + new(new PointF(bounds.Left, bounds.Top), new PointF(bounds.Right, bounds.Top)), + new(new PointF(bounds.Right, bounds.Top), new PointF(bounds.Right, bounds.Bottom)), + new(new PointF(bounds.Right, bounds.Bottom), new PointF(bounds.Left, bounds.Bottom)), + new(new PointF(bounds.Left, bounds.Bottom), new PointF(bounds.Left, bounds.Top)) + ]; + Path path = new(points); + Mock brush = new(); + GraphicsOptions options = new() { Antialias = true }; + FillPathProcessor processor = new(new DrawingOptions() { GraphicsOptions = options }, brush.Object, path); + Image img = new(10, 10); processor.Execute(img.Configuration, img, bounds); } [Fact] public void DrawOffCanvas() { - using (var img = new Image(10, 10)) + using (Image img = new(10, 10)) { img.Mutate(x => x.DrawLine( new SolidPen(Color.Black, 10), @@ -51,9 +51,9 @@ public void DrawOffCanvas() [Fact] public void OtherShape() { - var imageSize = new Rectangle(0, 0, 500, 500); - var path = new EllipsePolygon(1, 1, 23); - var processor = new FillPathProcessor( + Rectangle imageSize = new(0, 0, 500, 500); + EllipsePolygon path = new(1, 1, 23); + FillPathProcessor processor = new( new DrawingOptions() { GraphicsOptions = { Antialias = true } @@ -69,11 +69,11 @@ public void OtherShape() [Fact] public void RectangleFloatAndAntialias() { - var imageSize = new Rectangle(0, 0, 500, 500); - var floatRect = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f); - var expectedRect = new Rectangle(10, 10, 400, 400); - var path = new RectangularPolygon(floatRect); - var processor = new FillPathProcessor( + Rectangle imageSize = new(0, 0, 500, 500); + RectangleF floatRect = new(10.5f, 10.5f, 400.6f, 400.9f); + Rectangle expectedRect = new(10, 10, 400, 400); + RectangularPolygon path = new(floatRect); + FillPathProcessor processor = new( new DrawingOptions() { GraphicsOptions = { Antialias = true } @@ -89,10 +89,10 @@ public void RectangleFloatAndAntialias() [Fact] public void IntRectangle() { - var imageSize = new Rectangle(0, 0, 500, 500); - var expectedRect = new Rectangle(10, 10, 400, 400); - var path = new RectangularPolygon(expectedRect); - var processor = new FillPathProcessor( + Rectangle imageSize = new(0, 0, 500, 500); + Rectangle expectedRect = new(10, 10, 400, 400); + RectangularPolygon path = new(expectedRect); + FillPathProcessor processor = new( new DrawingOptions() { GraphicsOptions = { Antialias = true } @@ -109,11 +109,11 @@ public void IntRectangle() [Fact] public void FloatRectAntialiasingOff() { - var imageSize = new Rectangle(0, 0, 500, 500); - var floatRect = new RectangleF(10.5f, 10.5f, 400.6f, 400.9f); - var expectedRect = new Rectangle(10, 10, 400, 400); - var path = new RectangularPolygon(floatRect); - var processor = new FillPathProcessor( + Rectangle imageSize = new(0, 0, 500, 500); + RectangleF floatRect = new(10.5f, 10.5f, 400.6f, 400.9f); + Rectangle expectedRect = new(10, 10, 400, 400); + RectangularPolygon path = new(floatRect); + FillPathProcessor processor = new( new DrawingOptions() { GraphicsOptions = { Antialias = false } @@ -130,8 +130,8 @@ public void FloatRectAntialiasingOff() [Fact] public void DoesNotThrowForIssue928() { - var rectText = new RectangleF(0, 0, 2000, 2000); - using (var img = new Image((int)rectText.Width, (int)rectText.Height)) + RectangleF rectText = new(0, 0, 2000, 2000); + using (Image img = new((int)rectText.Width, (int)rectText.Height)) { img.Mutate(x => x.Fill(Color.Transparent)); @@ -153,9 +153,9 @@ public void DoesNotThrowForIssue928() [Fact] public void DoesNotThrowFillingTriangle() { - using (var image = new Image(28, 28)) + using (Image image = new(28, 28)) { - var path = new Polygon( + Polygon path = new( new LinearLineSegment(new PointF(17.11f, 13.99659f), new PointF(14.01433f, 27.06201f)), new LinearLineSegment(new PointF(14.01433f, 27.06201f), new PointF(13.79267f, 14.00023f)), new LinearLineSegment(new PointF(13.79267f, 14.00023f), new PointF(17.11f, 13.99659f))); diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ImageOperationTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/ImageOperationTests.cs index 9a5298e1..fb141083 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ImageOperationTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ImageOperationTests.cs @@ -24,7 +24,7 @@ public ImageOperationTests() { this.provider = new FakeImageOperationsProvider(); - var processorMock = new Mock(); + Mock processorMock = new(); this.processorDefinition = processorMock.Object; this.image = new Image( @@ -103,7 +103,7 @@ public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOriginal() [Fact] public void ApplyProcessors_ListOfProcessors_AppliesAllProcessorsToOperation() { - var operations = new FakeImageOperationsProvider.FakeImageOperations(Configuration.Default, null, false); + FakeImageOperationsProvider.FakeImageOperations operations = new(Configuration.Default, null, false); operations.ApplyProcessors(this.processorDefinition); Assert.Contains(this.processorDefinition, operations.Applied.Select(x => x.NonGenericProcessor)); } @@ -152,7 +152,7 @@ private static string GetExpectedExceptionText() { try { - var img = new Image(1, 1); + Image img = new(1, 1); img.Dispose(); img.EnsureNotDisposed(); } diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ImageProcessingContextTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/ImageProcessingContextTests.cs index d1237ac2..f9b1620b 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ImageProcessingContextTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ImageProcessingContextTests.cs @@ -23,7 +23,7 @@ public class ImageProcessingContextTests private readonly Mock> cloningProcessorImpl; - private static readonly Rectangle Bounds = new Rectangle(3, 3, 5, 5); + private static readonly Rectangle Bounds = new(3, 3, 5, 5); public ImageProcessingContextTests() { @@ -34,7 +34,7 @@ public ImageProcessingContextTests() } // bool throwException, bool useBounds - public static readonly TheoryData ProcessorTestData = new TheoryData() + public static readonly TheoryData ProcessorTestData = new() { { false, false }, { false, true }, diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ShapeOptionsDefaultsExtensionsTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/ShapeOptionsDefaultsExtensionsTests.cs index de2b19d9..28a20662 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ShapeOptionsDefaultsExtensionsTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ShapeOptionsDefaultsExtensionsTests.cs @@ -11,9 +11,9 @@ public class ShapeOptionsDefaultsExtensionsTests [Fact] public void SetDefaultOptionsOnProcessingContext() { - var option = new ShapeOptions(); - var config = new Configuration(); - var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); + ShapeOptions option = new(); + Configuration config = new(); + FakeImageOperationsProvider.FakeImageOperations context = new(config, null, true); context.SetShapeOptions(option); @@ -25,13 +25,13 @@ public void SetDefaultOptionsOnProcessingContext() [Fact] public void UpdateDefaultOptionsOnProcessingContext_AlwaysNewInstance() { - var option = new ShapeOptions() + ShapeOptions option = new() { ClippingOperation = ClippingOperation.Intersection, IntersectionRule = IntersectionRule.NonZero }; - var config = new Configuration(); - var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); + Configuration config = new(); + FakeImageOperationsProvider.FakeImageOperations context = new(config, null, true); context.SetShapeOptions(option); context.SetShapeOptions(o => @@ -54,8 +54,8 @@ public void UpdateDefaultOptionsOnProcessingContext_AlwaysNewInstance() [Fact] public void SetDefaultOptionsOnConfiguration() { - var option = new ShapeOptions(); - var config = new Configuration(); + ShapeOptions option = new(); + Configuration config = new(); config.SetShapeOptions(option); @@ -65,12 +65,12 @@ public void SetDefaultOptionsOnConfiguration() [Fact] public void UpdateDefaultOptionsOnConfiguration_AlwaysNewInstance() { - var option = new ShapeOptions() + ShapeOptions option = new() { ClippingOperation = ClippingOperation.Intersection, IntersectionRule = IntersectionRule.NonZero }; - var config = new Configuration(); + Configuration config = new(); config.SetShapeOptions(option); config.SetShapeOptions(o => @@ -91,7 +91,7 @@ public void UpdateDefaultOptionsOnConfiguration_AlwaysNewInstance() [Fact] public void GetDefaultOptionsFromConfiguration_SettingNullThenReturnsNewInstance() { - var config = new Configuration(); + Configuration config = new(); ShapeOptions options = config.GetShapeOptions(); Assert.NotNull(options); @@ -107,7 +107,7 @@ public void GetDefaultOptionsFromConfiguration_SettingNullThenReturnsNewInstance [Fact] public void GetDefaultOptionsFromConfiguration_IgnoreIncorectlyTypesDictionEntry() { - var config = new Configuration(); + Configuration config = new(); config.Properties[typeof(ShapeOptions)] = "wronge type"; ShapeOptions options = config.GetShapeOptions(); @@ -118,7 +118,7 @@ public void GetDefaultOptionsFromConfiguration_IgnoreIncorectlyTypesDictionEntry [Fact] public void GetDefaultOptionsFromConfiguration_AlwaysReturnsInstance() { - var config = new Configuration(); + Configuration config = new(); Assert.DoesNotContain(typeof(ShapeOptions), config.Properties.Keys); ShapeOptions options = config.GetShapeOptions(); @@ -128,7 +128,7 @@ public void GetDefaultOptionsFromConfiguration_AlwaysReturnsInstance() [Fact] public void GetDefaultOptionsFromConfiguration_AlwaysReturnsSameValue() { - var config = new Configuration(); + Configuration config = new(); ShapeOptions options = config.GetShapeOptions(); ShapeOptions options2 = config.GetShapeOptions(); @@ -138,8 +138,8 @@ public void GetDefaultOptionsFromConfiguration_AlwaysReturnsSameValue() [Fact] public void GetDefaultOptionsFromProcessingContext_AlwaysReturnsInstance() { - var config = new Configuration(); - var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); + Configuration config = new(); + FakeImageOperationsProvider.FakeImageOperations context = new(config, null, true); ShapeOptions ctxOptions = context.GetShapeOptions(); Assert.NotNull(ctxOptions); @@ -148,8 +148,8 @@ public void GetDefaultOptionsFromProcessingContext_AlwaysReturnsInstance() [Fact] public void GetDefaultOptionsFromProcessingContext_AlwaysReturnsInstanceEvenIfSetToNull() { - var config = new Configuration(); - var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); + Configuration config = new(); + FakeImageOperationsProvider.FakeImageOperations context = new(config, null, true); context.SetShapeOptions((ShapeOptions)null); ShapeOptions ctxOptions = context.GetShapeOptions(); @@ -159,10 +159,10 @@ public void GetDefaultOptionsFromProcessingContext_AlwaysReturnsInstanceEvenIfSe [Fact] public void GetDefaultOptionsFromProcessingContext_FallbackToConfigsInstance() { - var option = new ShapeOptions(); - var config = new Configuration(); + ShapeOptions option = new(); + Configuration config = new(); config.SetShapeOptions(option); - var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); + FakeImageOperationsProvider.FakeImageOperations context = new(config, null, true); ShapeOptions ctxOptions = context.GetShapeOptions(); Assert.Equal(option, ctxOptions); @@ -171,8 +171,8 @@ public void GetDefaultOptionsFromProcessingContext_FallbackToConfigsInstance() [Fact] public void GetDefaultOptionsFromProcessingContext_IgnoreIncorectlyTypesDictionEntry() { - var config = new Configuration(); - var context = new FakeImageOperationsProvider.FakeImageOperations(config, null, true); + Configuration config = new(); + FakeImageOperationsProvider.FakeImageOperations context = new(config, null, true); context.Properties[typeof(ShapeOptions)] = "wronge type"; ShapeOptions options = context.GetShapeOptions(); Assert.NotNull(options); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/ArcLineSegmentTest.cs b/tests/ImageSharp.Drawing.Tests/Shapes/ArcLineSegmentTest.cs index 25e76282..35887c0b 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/ArcLineSegmentTest.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/ArcLineSegmentTest.cs @@ -8,7 +8,7 @@ public class ArcLineSegmentTest [Fact] public void ContainsStartAndEnd() { - ArcLineSegment segment = new(new(10, 10), new(10, 20), 0, 0, 90); + ArcLineSegment segment = new(new PointF(10, 10), new SizeF(10, 20), 0, 0, 90); ReadOnlySpan points = segment.Flatten().Span; Assert.Equal(20, points[0].X, 5F); Assert.Equal(10, points[0].Y, 5F); @@ -19,9 +19,9 @@ public void ContainsStartAndEnd() [Fact] public void CheckZeroRadii() { - ReadOnlySpan xRadiusZero = new ArcLineSegment(new(20, 10), new(0, 20), 0, 0, 360).Flatten().Span; - ReadOnlySpan yRadiusZero = new ArcLineSegment(new(20, 10), new(30, 0), 0, 0, 360).Flatten().Span; - ReadOnlySpan bothRadiiZero = new ArcLineSegment(new(20, 10), new(0, 0), 0, 0, 360).Flatten().Span; + ReadOnlySpan xRadiusZero = new ArcLineSegment(new PointF(20, 10), new SizeF(0, 20), 0, 0, 360).Flatten().Span; + ReadOnlySpan yRadiusZero = new ArcLineSegment(new PointF(20, 10), new SizeF(30, 0), 0, 0, 360).Flatten().Span; + ReadOnlySpan bothRadiiZero = new ArcLineSegment(new PointF(20, 10), new SizeF(0, 0), 0, 0, 360).Flatten().Span; foreach (PointF point in xRadiusZero) { Assert.Equal(20, point.X); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/BezierLineSegmentTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/BezierLineSegmentTests.cs index 5b3b1860..e86c733a 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/BezierLineSegmentTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/BezierLineSegmentTests.cs @@ -10,7 +10,7 @@ public class BezierLineSegmentTests [Fact] public void SingleSegmentConstructor() { - var segment = new CubicBezierLineSegment(new Vector2(0, 0), new Vector2(10, 0), new Vector2(10, 0), new Vector2(20, 0)); + CubicBezierLineSegment segment = new(new Vector2(0, 0), new Vector2(10, 0), new Vector2(10, 0), new Vector2(20, 0)); IReadOnlyList points = segment.Flatten().ToArray(); Assert.Contains(new Vector2(0, 0), points); Assert.Contains(new Vector2(10, 0), points); @@ -20,6 +20,7 @@ public void SingleSegmentConstructor() [Fact] public void MustHaveAtLeast4Points() { - ArgumentOutOfRangeException error = Assert.Throws(() => new CubicBezierLineSegment(new[] { new PointF(0, 0) })); + ArgumentOutOfRangeException error = Assert.Throws(() => new CubicBezierLineSegment( + [new PointF(0, 0)])); } } diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/EllipseTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/EllipseTests.cs index 46862147..11d5d7f9 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/EllipseTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/EllipseTests.cs @@ -20,7 +20,7 @@ public void WidthMustBeGreaterThan0(float width, bool throws) } else { - var p = new EllipsePolygon(0, 0, width, 99); + EllipsePolygon p = new(0, 0, width, 99); Assert.NotNull(p); } } @@ -40,7 +40,7 @@ public void HeightMustBeGreaterThan0(float height, bool throws) } else { - var p = new EllipsePolygon(0, 0, 99, height); + EllipsePolygon p = new(0, 0, 99, height); Assert.NotNull(p); } } diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/InternalPathTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/InternalPathTests.cs index 7632aa38..3ed57216 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/InternalPathTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/InternalPathTests.cs @@ -11,10 +11,10 @@ public class InternalPathTests [Fact] public void MultipleLineSegmentsSimplePathsAreMerged() { - var seg1 = new LinearLineSegment(new PointF(0, 0), new PointF(2, 2)); - var seg2 = new LinearLineSegment(new PointF(4, 4), new PointF(5, 5)); + LinearLineSegment seg1 = new(new PointF(0, 0), new PointF(2, 2)); + LinearLineSegment seg2 = new(new PointF(4, 4), new PointF(5, 5)); - var path = new InternalPath(new ILineSegment[] { seg1, seg2 }, true); + InternalPath path = new([seg1, seg2], true); Assert.Contains(new PointF(0, 0), path.Points().ToArray()); Assert.DoesNotContain(new PointF(2, 2), path.Points().ToArray()); @@ -25,9 +25,9 @@ public void MultipleLineSegmentsSimplePathsAreMerged() [Fact] public void Length_Closed() { - var seg1 = new LinearLineSegment(new PointF(0, 0), new PointF(0, 2)); + LinearLineSegment seg1 = new(new PointF(0, 0), new PointF(0, 2)); - var path = new InternalPath(seg1, true); + InternalPath path = new(seg1, true); Assert.Equal(4, path.Length); } @@ -35,9 +35,9 @@ public void Length_Closed() [Fact] public void Length_Open() { - var seg1 = new LinearLineSegment(new PointF(0, 0), new PointF(0, 2)); + LinearLineSegment seg1 = new(new PointF(0, 0), new PointF(0, 2)); - var path = new InternalPath(seg1, false); + InternalPath path = new(seg1, false); Assert.Equal(2, path.Length); } @@ -45,10 +45,10 @@ public void Length_Open() [Fact] public void Bounds() { - var seg1 = new LinearLineSegment(new PointF(0, 0), new PointF(2, 2)); - var seg2 = new LinearLineSegment(new PointF(4, 4), new PointF(5, 5)); + LinearLineSegment seg1 = new(new PointF(0, 0), new PointF(2, 2)); + LinearLineSegment seg2 = new(new PointF(4, 4), new PointF(5, 5)); - var path = new InternalPath(new ILineSegment[] { seg1, seg2 }, true); + InternalPath path = new([seg1, seg2], true); Assert.Equal(0, path.Bounds.Left); Assert.Equal(5, path.Bounds.Right); @@ -58,14 +58,14 @@ public void Bounds() private static InternalPath Create(PointF location, SizeF size, bool closed = true) { - var seg1 = new LinearLineSegment(location, location + new PointF(size.Width, 0)); - var seg2 = new LinearLineSegment(location + new PointF(size.Width, size.Height), location + new PointF(0, size.Height)); + LinearLineSegment seg1 = new(location, location + new PointF(size.Width, 0)); + LinearLineSegment seg2 = new(location + new PointF(size.Width, size.Height), location + new PointF(0, size.Height)); - return new InternalPath(new ILineSegment[] { seg1, seg2 }, closed); + return new InternalPath([seg1, seg2], closed); } public static TheoryData PointInPolygonTheoryData { get; } - = new TheoryData + = new() { { new PointF(10, 10), // loc diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_19.cs b/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_19.cs index acc5a5a3..d920fa9d 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_19.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_19.cs @@ -14,8 +14,9 @@ public class Issue_19 [Fact] public void PAthLoosingSelfIntersectingPoint() { - var line1 = new PointF[] { new Vector2(117f, 199f), new Vector2(31f, 210f), new Vector2(35f, 191f), new Vector2(117f, 199f), new Vector2(2f, 9f) }; - var path = new Path(new LinearLineSegment(line1)); + PointF[] line1 = [new Vector2(117f, 199f), new Vector2(31f, 210f), new Vector2(35f, 191f), new Vector2(117f, 199f), new Vector2(2f, 9f) + ]; + Path path = new(new LinearLineSegment(line1)); IReadOnlyList pathPoints = path.Flatten().First().Points.ToArray(); // all points must not be in the outline; @@ -28,8 +29,9 @@ public void PAthLoosingSelfIntersectingPoint() [Fact] public void InternalPathLoosingSelfIntersectingPoint() { - var line1 = new PointF[] { new Vector2(117f, 199f), new Vector2(31f, 210f), new Vector2(35f, 191f), new Vector2(117f, 199f), new Vector2(2f, 9f) }; - var path = new InternalPath(new LinearLineSegment(line1), false); + PointF[] line1 = [new Vector2(117f, 199f), new Vector2(31f, 210f), new Vector2(35f, 191f), new Vector2(117f, 199f), new Vector2(2f, 9f) + ]; + InternalPath path = new(new LinearLineSegment(line1), false); IReadOnlyList pathPoints = path.Points().ToArray(); // all points must not be in the outline; diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_224.cs b/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_224.cs index bd3ac4cb..aa939136 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_224.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/Issues/Issue_224.cs @@ -11,29 +11,29 @@ public class Issue_224 [Fact] public async Task OutliningWithZeroWidth_MultiplePatterns() { - var shape = new RectangularPolygon(10, 10, 10, 10); + RectangularPolygon shape = new(10, 10, 10, 10); await this.CompletesIn(TimeSpan.FromSeconds(1), () => { - _ = shape.GenerateOutline(0, new float[] { 1, 2 }); + _ = shape.GenerateOutline(0, [1, 2]); }); } [Fact] public async Task OutliningWithZeroWidth_SinglePAttern() { - var shape = new RectangularPolygon(10, 10, 10, 10); + RectangularPolygon shape = new(10, 10, 10, 10); await this.CompletesIn(TimeSpan.FromSeconds(1), () => { - _ = shape.GenerateOutline(0, new float[] { 1 }); + _ = shape.GenerateOutline(0, [1]); }); } [Fact] public async Task OutliningWithZeroWidth_NoPattern() { - var shape = new RectangularPolygon(10, 10, 10, 10); + RectangularPolygon shape = new(10, 10, 10, 10); await this.CompletesIn(TimeSpan.FromSeconds(1), () => { @@ -44,29 +44,29 @@ await this.CompletesIn(TimeSpan.FromSeconds(1), () => [Fact] public async Task OutliningWithLessThanZeroWidth_MultiplePatterns() { - var shape = new RectangularPolygon(10, 10, 10, 10); + RectangularPolygon shape = new(10, 10, 10, 10); await this.CompletesIn(TimeSpan.FromSeconds(1), () => { - _ = shape.GenerateOutline(-10, new float[] { 1, 2 }); + _ = shape.GenerateOutline(-10, [1, 2]); }); } [Fact] public async Task OutliningWithLessThanZeroWidth_SinglePAttern() { - var shape = new RectangularPolygon(10, 10, 10, 10); + RectangularPolygon shape = new(10, 10, 10, 10); await this.CompletesIn(TimeSpan.FromSeconds(1), () => { - _ = shape.GenerateOutline(-10, new float[] { 1 }); + _ = shape.GenerateOutline(-10, [1]); }); } [Fact] public async Task OutliningWithLessThanZeroWidth_NoPattern() { - var shape = new RectangularPolygon(10, 10, 10, 10); + RectangularPolygon shape = new(10, 10, 10, 10); await this.CompletesIn(TimeSpan.FromSeconds(1), () => { @@ -76,10 +76,10 @@ await this.CompletesIn(TimeSpan.FromSeconds(1), () => private async Task CompletesIn(TimeSpan span, Action action) { - var task = Task.Run(action); - var timeout = Task.Delay(span); + Task task = Task.Run(action); + Task timeout = Task.Delay(span); - var completed = await Task.WhenAny(task, timeout); + Task completed = await Task.WhenAny(task, timeout); Assert.True(task == completed, $"Failed to compelete in {span}"); } diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/LinearLineSegmentTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/LinearLineSegmentTests.cs index 48f93073..47eb6fda 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/LinearLineSegmentTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/LinearLineSegmentTests.cs @@ -10,7 +10,7 @@ public class LinearLineSegmentTests [Fact] public void SingleSegmentConstructor() { - var segment = new LinearLineSegment(new Vector2(0, 0), new Vector2(10, 10)); + LinearLineSegment segment = new(new Vector2(0, 0), new Vector2(10, 10)); IReadOnlyList flatPath = segment.Flatten().ToArray(); Assert.Equal(2, flatPath.Count); Assert.Equal(new PointF(0, 0), flatPath[0]); @@ -20,7 +20,8 @@ public void SingleSegmentConstructor() [Fact] public void MustHaveAtLeast2Points() { - ArgumentOutOfRangeException error = Assert.Throws(() => new LinearLineSegment(new[] { new PointF(0, 0) })); + ArgumentOutOfRangeException error = Assert.Throws(() => new LinearLineSegment([new PointF(0, 0) + ])); } [Fact] diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs index f6ed5690..1968ec8a 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs @@ -10,7 +10,7 @@ public class PathBuilderTests [Fact] public void DrawLinesClosedFigure() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddLine(10, 10, 10, 90); builder.AddLine(10, 90, 50, 50); @@ -22,7 +22,7 @@ public void DrawLinesClosedFigure() [Fact] public void AddBezier() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddCubicBezier(new Vector2(10, 10), new Vector2(20, 20), new Vector2(20, 30), new Vector2(10, 40)); @@ -32,7 +32,7 @@ public void AddBezier() [Fact] public void AddEllipticArc() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddArc(new PointF(10, 10), 10, 10, 0, 0, 360); @@ -42,7 +42,7 @@ public void AddEllipticArc() [Fact] public void DrawLinesOpenFigure() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddLine(10, 10, 10, 90); builder.AddLine(10, 90, 50, 50); @@ -52,7 +52,7 @@ public void DrawLinesOpenFigure() [Fact] public void DrawLines2OpenFigures() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddLine(10, 10, 10, 90); builder.AddLine(10, 90, 50, 50); @@ -70,7 +70,7 @@ public void DrawLines2OpenFigures() [Fact] public void DrawLinesOpenThenClosedFigures() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddLine(10, 10, 10, 90); builder.AddLine(10, 90, 50, 50); @@ -89,7 +89,7 @@ public void DrawLinesOpenThenClosedFigures() [Fact] public void DrawLinesClosedThenOpenFigures() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddLine(10, 10, 10, 90); builder.AddLine(10, 90, 50, 50); @@ -107,7 +107,7 @@ public void DrawLinesClosedThenOpenFigures() [Fact] public void DrawLinesCloseAllFigures() { - var builder = new PathBuilder(); + PathBuilder builder = new(); builder.AddLine(10, 10, 10, 90); builder.AddLine(10, 90, 50, 50); @@ -133,10 +133,10 @@ public void DrawLinesCloseAllFigures() [Fact] public void EnumerableAddLines() { - var point1 = new Vector2(10, 10); - var point2 = new Vector2(10, 90); - var point3 = new Vector2(50, 50); - var builder = new PathBuilder(); + Vector2 point1 = new(10, 10); + Vector2 point2 = new(10, 90); + Vector2 point3 = new(50, 50); + PathBuilder builder = new(); builder.AddLines(new List { point1, point2, point3 }); Path shape = Assert.IsType(builder.Build()); @@ -146,10 +146,10 @@ public void EnumerableAddLines() [Fact] public void MultipleStartFiguresDoesntCreateEmptyPaths() { - var point1 = new Vector2(10, 10); - var point2 = new Vector2(10, 90); - var point3 = new Vector2(50, 50); - var builder = new PathBuilder(); + Vector2 point1 = new(10, 10); + Vector2 point2 = new(10, 90); + Vector2 point3 = new(50, 50); + PathBuilder builder = new(); builder.StartFigure(); builder.StartFigure(); builder.StartFigure(); @@ -161,11 +161,11 @@ public void MultipleStartFiguresDoesntCreateEmptyPaths() [Fact] public void DefaultTransform() { - var point1 = new Vector2(10, 10); - var point2 = new Vector2(10, 90); - var point3 = new Vector2(50, 50); - var matrix = Matrix3x2.CreateTranslation(new Vector2(5, 5)); - var builder = new PathBuilder(matrix); + Vector2 point1 = new(10, 10); + Vector2 point2 = new(10, 90); + Vector2 point3 = new(50, 50); + Matrix3x2 matrix = Matrix3x2.CreateTranslation(new Vector2(5, 5)); + PathBuilder builder = new(matrix); builder.AddLines(point1, point2, point3); IPath shape = builder.Build(); @@ -175,11 +175,11 @@ public void DefaultTransform() [Fact] public void SetTransform() { - var point1 = new Vector2(10, 10); - var point2 = new Vector2(10, 90); - var point3 = new Vector2(50, 50); - var matrix = Matrix3x2.CreateTranslation(new Vector2(100, 100)); - var builder = new PathBuilder(); + Vector2 point1 = new(10, 10); + Vector2 point2 = new(10, 90); + Vector2 point3 = new(50, 50); + Matrix3x2 matrix = Matrix3x2.CreateTranslation(new Vector2(100, 100)); + PathBuilder builder = new(); builder.AddLines(point1, point2, point3); builder.SetTransform(matrix); @@ -198,11 +198,11 @@ public void SetTransform() [Fact] public void SetOriginLeaveMatrix() { - var point1 = new Vector2(10, 10); - var point2 = new Vector2(10, 90); - var point3 = new Vector2(50, 50); - var origin = new Vector2(-50, -100); - var builder = new PathBuilder(Matrix3x2.CreateScale(10)); + Vector2 point1 = new(10, 10); + Vector2 point2 = new(10, 90); + Vector2 point3 = new(50, 50); + Vector2 origin = new(-50, -100); + PathBuilder builder = new(Matrix3x2.CreateScale(10)); builder.AddLines(point1, point2, point3); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PathExtentionTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PathExtentionTests.cs index aa62f593..77314de9 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PathExtentionTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PathExtentionTests.cs @@ -27,7 +27,7 @@ public void RotateInRadians() .Callback(m => { // validate matrix in here - var targetMatrix = Matrix3x2.CreateRotation(Angle, RectangleF.Center(this.bounds)); + Matrix3x2 targetMatrix = Matrix3x2.CreateRotation(Angle, RectangleF.Center(this.bounds)); Assert.Equal(targetMatrix, m); }).Returns(this.mockPath.Object); @@ -48,7 +48,7 @@ public void RotateInDegrees() // validate matrix in here const float Radians = (float)(Math.PI * Angle / 180.0); - var targetMatrix = Matrix3x2.CreateRotation(Radians, RectangleF.Center(this.bounds)); + Matrix3x2 targetMatrix = Matrix3x2.CreateRotation(Radians, RectangleF.Center(this.bounds)); Assert.Equal(targetMatrix, m); }).Returns(this.mockPath.Object); @@ -61,13 +61,13 @@ public void RotateInDegrees() [Fact] public void TranslateVector() { - var point = new Vector2(98, 120); + Vector2 point = new(98, 120); this.mockPath.Setup(x => x.Transform(It.IsAny())) .Callback(m => { // validate matrix in here - var targetMatrix = Matrix3x2.CreateTranslation(point); + Matrix3x2 targetMatrix = Matrix3x2.CreateTranslation(point); Assert.Equal(targetMatrix, m); }).Returns(this.mockPath.Object); @@ -87,7 +87,7 @@ public void TranslateXY() .Callback(m => { // validate matrix in here - var targetMatrix = Matrix3x2.CreateTranslation(new Vector2(X, Y)); + Matrix3x2 targetMatrix = Matrix3x2.CreateTranslation(new Vector2(X, Y)); Assert.Equal(targetMatrix, m); }).Returns(this.mockPath.Object); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs index 4ac7727c..2785af80 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs @@ -11,10 +11,10 @@ public class PathTests [Fact] public void Bounds() { - var seg1 = new LinearLineSegment(new PointF(0, 0), new PointF(2, 2)); - var seg2 = new LinearLineSegment(new PointF(4, 4), new PointF(5, 5)); + LinearLineSegment seg1 = new(new PointF(0, 0), new PointF(2, 2)); + LinearLineSegment seg2 = new(new PointF(4, 4), new PointF(5, 5)); - var path = new Path(seg1, seg2); + Path path = new(seg1, seg2); Assert.Equal(0, path.Bounds.Left); Assert.Equal(5, path.Bounds.Right); @@ -25,7 +25,7 @@ public void Bounds() [Fact] public void SimplePath() { - var path = new Path(new LinearLineSegment(new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10))); + Path path = new(new LinearLineSegment(new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10))); System.Collections.Generic.IReadOnlyList points = path.Flatten().Single().Points.ToArray(); Assert.Equal(4, points.Count); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PolygonClipper/ClipperTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PolygonClipper/ClipperTests.cs index 4abfe7d8..5d85c26a 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PolygonClipper/ClipperTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PolygonClipper/ClipperTests.cs @@ -27,7 +27,7 @@ public class ClipperTests private IEnumerable Clip(IPath shape, params IPath[] hole) { - var clipper = new Clipper(); + Clipper clipper = new(); clipper.AddPath(shape, ClippingType.Subject); if (hole != null) @@ -44,12 +44,12 @@ private IEnumerable Clip(IPath shape, params IPath[] hole) [Fact] public void OverlappingTriangleCutRightSide() { - var triangle = new Polygon(new LinearLineSegment( + Polygon triangle = new(new LinearLineSegment( new Vector2(0, 50), new Vector2(70, 0), new Vector2(50, 100))); - var cutout = new Polygon(new LinearLineSegment( + Polygon cutout = new(new LinearLineSegment( new Vector2(20, 0), new Vector2(70, 0), new Vector2(70, 100), diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PolygonTests.cs index 0879ba8f..3af46a7a 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PolygonTests.cs @@ -9,21 +9,21 @@ public class PolygonTests new() { { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], // loc new PointF(10, 10), // test true }, // corner is inside { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], // loc new PointF(10, 11), // test true }, // on line { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], // loc new PointF(9, 9), // test @@ -35,22 +35,22 @@ public class PolygonTests new() { { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], new PointF(10, 10), 0 }, { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], new PointF(10, 11), 0 }, { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], new PointF(11, 11), -1 }, { - new TestPoint[] { new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10) }, + [new PointF(10, 10), new PointF(10, 100), new PointF(100, 100), new PointF(100, 10)], new PointF(9, 10), 1 }, @@ -59,7 +59,7 @@ public class PolygonTests [Fact] public void AsSimpleLinearPath() { - var poly = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10), new PointF(5, 5))); + Polygon poly = new(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10), new PointF(5, 5))); IReadOnlyList paths = poly.Flatten().First().Points.ToArray(); Assert.Equal(3, paths.Count); Assert.Equal(new PointF(0, 0), paths[0]); @@ -70,7 +70,7 @@ public void AsSimpleLinearPath() [Fact] public void ReturnsWrapperOfSelfASOwnPath_SingleSegment() { - var poly = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10), new PointF(5, 5))); + Polygon poly = new(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10), new PointF(5, 5))); ISimplePath[] paths = poly.Flatten().ToArray(); Assert.Single(paths); Assert.Equal(poly, paths[0]); @@ -79,7 +79,7 @@ public void ReturnsWrapperOfSelfASOwnPath_SingleSegment() [Fact] public void ReturnsWrapperOfSelfASOwnPath_MultiSegment() { - var poly = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10)), new LinearLineSegment(new PointF(2, 5), new PointF(5, 5))); + Polygon poly = new(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10)), new LinearLineSegment(new PointF(2, 5), new PointF(5, 5))); ISimplePath[] paths = poly.Flatten().ToArray(); Assert.Single(paths); Assert.Equal(poly, paths[0]); @@ -88,7 +88,7 @@ public void ReturnsWrapperOfSelfASOwnPath_MultiSegment() [Fact] public void Bounds() { - var poly = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10), new PointF(5, 5))); + Polygon poly = new(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10), new PointF(5, 5))); RectangleF bounds = poly.Bounds; Assert.Equal(0, bounds.Left); Assert.Equal(0, bounds.Top); @@ -99,7 +99,7 @@ public void Bounds() [Fact] public void MaxIntersections() { - var poly = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10))); + Polygon poly = new(new LinearLineSegment(new PointF(0, 0), new PointF(0, 10))); // with linear polygons its the number of points the segments have Assert.Equal(2, poly.MaxIntersections); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs index 4beac8bd..9ea049e3 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs @@ -68,35 +68,35 @@ public class RectangleTests [Fact] public void Left() { - var shape = new RectangularPolygon(10, 11, 12, 13); + RectangularPolygon shape = new(10, 11, 12, 13); Assert.Equal(10, shape.Left); } [Fact] public void Right() { - var shape = new RectangularPolygon(10, 11, 12, 13); + RectangularPolygon shape = new(10, 11, 12, 13); Assert.Equal(22, shape.Right); } [Fact] public void Top() { - var shape = new RectangularPolygon(10, 11, 12, 13); + RectangularPolygon shape = new(10, 11, 12, 13); Assert.Equal(11, shape.Top); } [Fact] public void Bottom() { - var shape = new RectangularPolygon(10, 11, 12, 13); + RectangularPolygon shape = new(10, 11, 12, 13); Assert.Equal(24, shape.Bottom); } [Fact] public void SizeF() { - var shape = new RectangularPolygon(10, 11, 12, 13); + RectangularPolygon shape = new(10, 11, 12, 13); Assert.Equal(12, shape.Size.Width); Assert.Equal(13, shape.Size.Height); } @@ -163,7 +163,7 @@ public void Transform() [Fact] public void Center() { - var shape = new RectangularPolygon(50, 50, 200, 60); + RectangularPolygon shape = new(50, 50, 200, 60); Assert.Equal(new PointF(150, 80), shape.Center); } @@ -180,7 +180,7 @@ public void Center() [InlineData(620, 150, 50, Pi)] // wrap about end of path public void PointOnPath(float distance, float expectedX, float expectedY, float expectedAngle) { - var shape = new RectangularPolygon(50, 50, 200, 60); + RectangularPolygon shape = new(50, 50, 200, 60); SegmentInfo point = ((IPathInternals)shape).PointAlongPath(distance); Assert.Equal(expectedX, point.Point.X); Assert.Equal(expectedY, point.Point.Y); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/RegularPolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/RegularPolygonTests.cs index e0fe4541..90c74f8c 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/RegularPolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/RegularPolygonTests.cs @@ -23,7 +23,7 @@ public void RequiresAtLeast3Vertices(int points, bool throws) } else { - var p = new RegularPolygon(Vector2.Zero, points, 10f, 0); + RegularPolygon p = new(Vector2.Zero, points, 10f, 0); Assert.NotNull(p); } } @@ -43,7 +43,7 @@ public void RadiusMustBeGreaterThan0(float radius, bool throws) } else { - var p = new RegularPolygon(Vector2.Zero, 3, radius, 0); + RegularPolygon p = new(Vector2.Zero, 3, radius, 0); Assert.NotNull(p); } } @@ -54,7 +54,7 @@ public void GeneratesCorrectPath() const float Radius = 10; int pointsCount = new Random().Next(3, 20); - var poly = new RegularPolygon(Vector2.Zero, pointsCount, Radius, 0); + RegularPolygon poly = new(Vector2.Zero, pointsCount, Radius, 0); IReadOnlyList points = poly.Flatten().ToArray()[0].Points.ToArray(); @@ -83,7 +83,7 @@ public void AngleChangesOnePointToStartAtThatPosition() const float Radius = 10; double anAngle = new Random().NextDouble() * TwoPI; - var poly = new RegularPolygon(Vector2.Zero, 3, Radius, (float)anAngle); + RegularPolygon poly = new(Vector2.Zero, 3, Radius, (float)anAngle); IReadOnlyList points = poly.Flatten().ToArray()[0].Points.ToArray(); IEnumerable allAngles = points.Select(b => Math.Atan2(b.Y, b.X)) diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs index 3abbfddc..479901c4 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/PolygonScannerTests.cs @@ -20,7 +20,7 @@ public PolygonScannerTests(ITestOutputHelper output) private void PrintPoints(ReadOnlySpan points) { - var sb = new StringBuilder(); + StringBuilder sb = new(); foreach (PointF p in points) { @@ -67,7 +67,7 @@ private void TestScan( FuzzyFloat[][] expected, IntersectionRule intersectionRule) { - var scanner = PolygonScanner.Create( + PolygonScanner scanner = PolygonScanner.Create( path, min, max, @@ -104,18 +104,18 @@ public void BasicConcave00() DebugDraw.Polygon(poly, 1f, 50f); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 2, 2 }, - new FuzzyFloat[] { 2, 5 }, - new FuzzyFloat[] { 2, 5 }, - new FuzzyFloat[] { 2, 5 }, - new FuzzyFloat[] { 2, 5, 5, 8 }, - new FuzzyFloat[] { 2, 8 }, - new FuzzyFloat[] { 2.75f, 8 }, - new FuzzyFloat[] { 3.5f, 8 }, - new FuzzyFloat[] { 4.25f, 6.5f }, - new FuzzyFloat[] { 5, 5 }, - }; + [ + [2, 2], + [2, 5], + [2, 5], + [2, 5], + [2, 5, 5, 8], + [2, 8], + [2.75f, 8], + [3.5f, 8], + [4.25f, 6.5f], + [5, 5] + ]; this.TestScan(poly, 2, 11, 1, expected); } @@ -127,29 +127,29 @@ public void BasicConcave01() DebugDraw.Polygon(poly); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 0f, 0f, 20.000000f, 20.000000f, }, - new FuzzyFloat[] { 0f, 1.0000000f, 19.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 2.0000000f, 18.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 3.0000000f, 17.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 4.0000000f, 16.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 5.0000000f, 15.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 6.0000000f, 14.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 7.0000000f, 13.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 8.0000000f, 12.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 9.0000000f, 11.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 10.000000f, 10.000000f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - new FuzzyFloat[] { 0f, 20.000000f }, - }; + [ + [0f, 0f, 20.000000f, 20.000000f], + [0f, 1.0000000f, 19.000000f, 20.000000f], + [0f, 2.0000000f, 18.000000f, 20.000000f], + [0f, 3.0000000f, 17.000000f, 20.000000f], + [0f, 4.0000000f, 16.000000f, 20.000000f], + [0f, 5.0000000f, 15.000000f, 20.000000f], + [0f, 6.0000000f, 14.000000f, 20.000000f], + [0f, 7.0000000f, 13.000000f, 20.000000f], + [0f, 8.0000000f, 12.000000f, 20.000000f], + [0f, 9.0000000f, 11.000000f, 20.000000f], + [0f, 10.000000f, 10.000000f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f], + [0f, 20.000000f] + ]; this.TestScan(poly, 0, 20, 1, expected); } @@ -161,15 +161,15 @@ public void BasicConcave02() DebugDraw.Polygon(poly, 1f, 100f); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 0f, 0f, 3.0000000f, 3.0000000f }, - new FuzzyFloat[] { 0f, 0.50000000f, 2.5000000f, 3.0000000f }, - new FuzzyFloat[] { 0f, 1.0000000f, 2.0000000f, 3.0000000f }, - new FuzzyFloat[] { 0f, 1.0000000f, 1.5000000f, 3.0000000f }, - new FuzzyFloat[] { 0f, 1.0000000f, 1.0000000f, 3.0000000f }, - new FuzzyFloat[] { 0f, 3.0000000f }, - new FuzzyFloat[] { 0f, 3.0000000f }, - }; + [ + [0f, 0f, 3.0000000f, 3.0000000f], + [0f, 0.50000000f, 2.5000000f, 3.0000000f], + [0f, 1.0000000f, 2.0000000f, 3.0000000f], + [0f, 1.0000000f, 1.5000000f, 3.0000000f], + [0f, 1.0000000f, 1.0000000f, 3.0000000f], + [0f, 3.0000000f], + [0f, 3.0000000f] + ]; this.TestScan(poly, 0, 3, 2, expected); } @@ -194,23 +194,22 @@ public void BasicConcave03() DebugDraw.Polygon(poly, 1f, 100f); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 0f, 2.0000000f, 3.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 2.2000000f, 3.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 2.4000000f, 3.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 2.6000000f, 3.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 2.8000000f, 3.0000000f, 6.0000000f }, - new FuzzyFloat[] - { + [ + [0f, 2.0000000f, 3.0000000f, 6.0000000f], + [0f, 2.2000000f, 3.0000000f, 6.0000000f], + [0f, 2.4000000f, 3.0000000f, 6.0000000f], + [0f, 2.6000000f, 3.0000000f, 6.0000000f], + [0f, 2.8000000f, 3.0000000f, 6.0000000f], + [ 0f, 1.0000000f, 1.0000000f, 3.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f, 5.0000000f, 6.0000000f - }, - new FuzzyFloat[] { 0f, 0.80000000f, 1.2000000f, 4.0000000f, 5.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 0.60000000f, 1.4000000f, 4.0000000f, 5.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 0.40000000f, 1.6000000f, 4.0000000f, 5.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 0.20000000f, 1.8000000f, 4.0000000f, 5.0000000f, 6.0000000f }, - new FuzzyFloat[] { 0f, 0f, 2.0000000f, 4.0000000f, 5.0000000f, 6.0000000f }, - }; + ], + [0f, 0.80000000f, 1.2000000f, 4.0000000f, 5.0000000f, 6.0000000f], + [0f, 0.60000000f, 1.4000000f, 4.0000000f, 5.0000000f, 6.0000000f], + [0f, 0.40000000f, 1.6000000f, 4.0000000f, 5.0000000f, 6.0000000f], + [0f, 0.20000000f, 1.8000000f, 4.0000000f, 5.0000000f, 6.0000000f], + [0f, 0f, 2.0000000f, 4.0000000f, 5.0000000f, 6.0000000f] + ]; this.TestScan(poly, 0, 2, 5, expected); } @@ -223,29 +222,29 @@ public void SelfIntersecting01() DebugDraw.Polygon(poly, 10f, 10f); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 0f, 10.000000f }, - new FuzzyFloat[] { 0.50000000f, 9.5000000f }, - new FuzzyFloat[] { 1.0000000f, 9.0000000f }, - new FuzzyFloat[] { 1.5000000f, 8.5000000f }, - new FuzzyFloat[] { 2.0000000f, 8.0000000f }, - new FuzzyFloat[] { 2.5000000f, 7.5000000f }, - new FuzzyFloat[] { 3.0000000f, 7.0000000f }, - new FuzzyFloat[] { 3.5000000f, 6.5000000f }, - new FuzzyFloat[] { 4.0000000f, 6.0000000f }, - new FuzzyFloat[] { 4.5000000f, 5.5000000f }, - new FuzzyFloat[] { 5.0000000f, 5.0000000f }, - new FuzzyFloat[] { 4.5000000f, 5.5000000f }, - new FuzzyFloat[] { 4.0000000f, 6.0000000f }, - new FuzzyFloat[] { 3.5000000f, 6.5000000f }, - new FuzzyFloat[] { 3.0000000f, 7.0000000f }, - new FuzzyFloat[] { 2.5000000f, 7.5000000f }, - new FuzzyFloat[] { 2.0000000f, 8.0000000f }, - new FuzzyFloat[] { 1.5000000f, 8.5000000f }, - new FuzzyFloat[] { 1.0000000f, 9.0000000f }, - new FuzzyFloat[] { 0.50000000f, 9.5000000f }, - new FuzzyFloat[] { 0f, 10.000000f }, - }; + [ + [0f, 10.000000f], + [0.50000000f, 9.5000000f], + [1.0000000f, 9.0000000f], + [1.5000000f, 8.5000000f], + [2.0000000f, 8.0000000f], + [2.5000000f, 7.5000000f], + [3.0000000f, 7.0000000f], + [3.5000000f, 6.5000000f], + [4.0000000f, 6.0000000f], + [4.5000000f, 5.5000000f], + [5.0000000f, 5.0000000f], + [4.5000000f, 5.5000000f], + [4.0000000f, 6.0000000f], + [3.5000000f, 6.5000000f], + [3.0000000f, 7.0000000f], + [2.5000000f, 7.5000000f], + [2.0000000f, 8.0000000f], + [1.5000000f, 8.5000000f], + [1.0000000f, 9.0000000f], + [0.50000000f, 9.5000000f], + [0f, 10.000000f] + ]; this.TestScan(poly, 0, 10, 2, expected); } @@ -256,29 +255,29 @@ public void SelfIntersecting02() DebugDraw.Polygon(poly, 10f, 10f); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 0f, 0f, 10.000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 0.50000000f, 9.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 1.0000000f, 9.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 1.5000000f, 8.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 2.0000000f, 8.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 2.5000000f, 7.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 3.0000000f, 7.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 3.5000000f, 6.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 4.0000000f, 6.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 4.5000000f, 5.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 5.0000000f, 5.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 4.5000000f, 5.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 4.0000000f, 6.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 3.5000000f, 6.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 3.0000000f, 7.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 2.5000000f, 7.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 2.0000000f, 8.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 1.5000000f, 8.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 1.0000000f, 9.0000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 0.50000000f, 9.5000000f, 10.000000f }, - new FuzzyFloat[] { 0f, 0f, 10.000000f, 10.000000f }, - }; + [ + [0f, 0f, 10.000000f, 10.000000f], + [0f, 0.50000000f, 9.5000000f, 10.000000f], + [0f, 1.0000000f, 9.0000000f, 10.000000f], + [0f, 1.5000000f, 8.5000000f, 10.000000f], + [0f, 2.0000000f, 8.0000000f, 10.000000f], + [0f, 2.5000000f, 7.5000000f, 10.000000f], + [0f, 3.0000000f, 7.0000000f, 10.000000f], + [0f, 3.5000000f, 6.5000000f, 10.000000f], + [0f, 4.0000000f, 6.0000000f, 10.000000f], + [0f, 4.5000000f, 5.5000000f, 10.000000f], + [0f, 5.0000000f, 5.0000000f, 10.000000f], + [0f, 4.5000000f, 5.5000000f, 10.000000f], + [0f, 4.0000000f, 6.0000000f, 10.000000f], + [0f, 3.5000000f, 6.5000000f, 10.000000f], + [0f, 3.0000000f, 7.0000000f, 10.000000f], + [0f, 2.5000000f, 7.5000000f, 10.000000f], + [0f, 2.0000000f, 8.0000000f, 10.000000f], + [0f, 1.5000000f, 8.5000000f, 10.000000f], + [0f, 1.0000000f, 9.0000000f, 10.000000f], + [0f, 0.50000000f, 9.5000000f, 10.000000f], + [0f, 0f, 10.000000f, 10.000000f] + ]; this.TestScan(poly, 0, 10, 2, expected); } @@ -305,33 +304,33 @@ public void SelfIntersecting03(IntersectionRule rule) FuzzyFloat[][] expected; if (rule == IntersectionRule.EvenOdd) { - expected = new[] - { - new FuzzyFloat[] { 2.0000000f, 3.0000000f }, - new FuzzyFloat[] { 2.0000000f, 3.0000000f }, - new FuzzyFloat[] { 1.0000000f, 2.0000000f, 3.0000000f, 5.0000000f }, - new FuzzyFloat[] { 1.0000000f, 2.0000000f, 3.0000000f, 5.0000000f }, - new FuzzyFloat[] { 1.0000000f, 2.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 3.0000000f, 4.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 3.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 5.0000000f }, - }; + expected = + [ + [2.0000000f, 3.0000000f], + [2.0000000f, 3.0000000f], + [1.0000000f, 2.0000000f, 3.0000000f, 5.0000000f], + [1.0000000f, 2.0000000f, 3.0000000f, 5.0000000f], + [1.0000000f, 2.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f], + [2.0000000f, 3.0000000f, 4.0000000f, 5.0000000f], + [2.0000000f, 3.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f], + [2.0000000f, 5.0000000f], + [2.0000000f, 5.0000000f] + ]; } else { - expected = new[] - { - new FuzzyFloat[] { 2.0000000f, 3.0000000f }, - new FuzzyFloat[] { 2.0000000f, 3.0000000f }, - new FuzzyFloat[] { 1.0000000f, 5.0000000f }, - new FuzzyFloat[] { 1.0000000f, 5.0000000f }, - new FuzzyFloat[] { 1.0000000f, 4.0000000f, 4.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 3.0000000f, 4.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 3.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 5.0000000f }, - new FuzzyFloat[] { 2.0000000f, 5.0000000f }, - }; + expected = + [ + [2.0000000f, 3.0000000f], + [2.0000000f, 3.0000000f], + [1.0000000f, 5.0000000f], + [1.0000000f, 5.0000000f], + [1.0000000f, 4.0000000f, 4.0000000f, 5.0000000f], + [2.0000000f, 3.0000000f, 4.0000000f, 5.0000000f], + [2.0000000f, 3.0000000f, 3.0000000f, 4.0000000f, 4.0000000f, 5.0000000f], + [2.0000000f, 5.0000000f], + [2.0000000f, 5.0000000f] + ]; } this.TestScan(poly, 1, 5, 2, expected, rule); @@ -364,33 +363,33 @@ public void SelfIntersecting04(IntersectionRule rule) FuzzyFloat[][] expected; if (rule == IntersectionRule.EvenOdd) { - expected = new[] - { - new FuzzyFloat[] { 1, 4 }, - new FuzzyFloat[] { 1, 4 }, - new FuzzyFloat[] { 1, 2, 2, 3, 3, 4 }, - new FuzzyFloat[] { 1, 2, 3, 4 }, - new FuzzyFloat[] { 1, 1, 2, 3, 3, 4 }, - new FuzzyFloat[] { 1, 1, 2, 4 }, - new FuzzyFloat[] { 1, 1, 2, 2, 2, 3, 3, 4 }, - new FuzzyFloat[] { 2, 3 }, - new FuzzyFloat[] { 2, 3 }, - }; + expected = + [ + [1, 4], + [1, 4], + [1, 2, 2, 3, 3, 4], + [1, 2, 3, 4], + [1, 1, 2, 3, 3, 4], + [1, 1, 2, 4], + [1, 1, 2, 2, 2, 3, 3, 4], + [2, 3], + [2, 3] + ]; } else { - expected = new[] - { - new FuzzyFloat[] { 1, 4 }, - new FuzzyFloat[] { 1, 4 }, - new FuzzyFloat[] { 1, 2, 2, 3, 3, 4 }, - new FuzzyFloat[] { 1, 2, 3, 4 }, - new FuzzyFloat[] { 1, 3, 3, 4 }, - new FuzzyFloat[] { 1, 4 }, - new FuzzyFloat[] { 1, 2, 2, 3, 3, 4 }, - new FuzzyFloat[] { 2, 3 }, - new FuzzyFloat[] { 2, 3 }, - }; + expected = + [ + [1, 4], + [1, 4], + [1, 2, 2, 3, 3, 4], + [1, 2, 3, 4], + [1, 3, 3, 4], + [1, 4], + [1, 2, 2, 3, 3, 4], + [2, 3], + [2, 3] + ]; } this.TestScan(poly, 1, 5, 2, expected, rule); @@ -407,18 +406,18 @@ public void NegativeOrientation01(IntersectionRule intersectionRule) // Adding a dummy ring outside the area of interest, so the actual loop is not oriented positively PointF[] dummy = PolygonFactory.CreatePointArray((0, 10), (10, 10), (0, 11)); - var poly = new ComplexPolygon( + ComplexPolygon poly = new( new Polygon(new LinearLineSegment(interest)), new Polygon(new LinearLineSegment(dummy))); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 0, 0, 2, 2 }, - new FuzzyFloat[] { 0, 2 }, - new FuzzyFloat[] { 0, 2 }, - new FuzzyFloat[] { 0, 2 }, - new FuzzyFloat[] { 0, 0, 2, 2 }, - }; + [ + [0, 0, 2, 2], + [0, 2], + [0, 2], + [0, 2], + [0, 0, 2, 2] + ]; this.TestScan(poly, 0, 2, 2, expected, intersectionRule); } @@ -429,15 +428,15 @@ public void OutOfBounds1() IPath poly = PolygonFactory.CreatePolygon((1, -5), (5, -5), (5, -3), (10, -1), (10, 2), (12, 4), (1, 4)); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 1, 10 }, - new FuzzyFloat[] { 1, 10 }, - new FuzzyFloat[] { 1, 10 }, - new FuzzyFloat[] { 1, 10 }, - new FuzzyFloat[] { 1, 10 }, - new FuzzyFloat[] { 1, 10.5 }, - new FuzzyFloat[] { 1, 11 }, - }; + [ + [1, 10], + [1, 10], + [1, 10], + [1, 10], + [1, 10], + [1, 10.5], + [1, 11] + ]; this.TestScan(poly, 0, 3, 2, expected); } @@ -447,11 +446,11 @@ public void OutOfBounds2() { IPath poly = PolygonFactory.CreatePolygon((3, -3), (3, 1), (1, 1), (1, -1), (2, -1.5f), (2, 0.5f), (3, -3)); FuzzyFloat[][] expected = - { - new FuzzyFloat[] { 1, 2, 2.14285707, 3 }, - new FuzzyFloat[] { 1, 2, 2, 3 }, - new FuzzyFloat[] { 1, 3 } - }; + [ + [1, 2, 2.14285707, 3], + [1, 2, 2, 3], + [1, 3] + ]; this.TestScan(poly, 0, 1, 2, expected); } @@ -461,16 +460,16 @@ public void AllOutOfBounds() { IPath poly = PolygonFactory.CreatePolygon((1, -3), (3, -3), (2, -1)); FuzzyFloat[][] expected = - { - Array.Empty(), - Array.Empty(), - Array.Empty(), - }; + [ + [], + [], + [] + ]; this.TestScan(poly, 0, 1, 2, expected); } - private static (float Y, FuzzyFloat[] X) Empty(float y) => (y, Array.Empty()); + private static (float Y, FuzzyFloat[] X) Empty(float y) => (y, []); private static FuzzyFloat F(float x, float eps) => new(x, eps); @@ -478,105 +477,89 @@ public void AllOutOfBounds() new() { { - "A", - new[] - { + "A", [ Empty(2f), Empty(2.25f), - (2.5f, new FuzzyFloat[] { 2, 11 }), - (2.75f, new FuzzyFloat[] { 2, 11 }), - (3f, new FuzzyFloat[] { 2, 8, 8, 11 }), - (3.25f, new FuzzyFloat[] { 11, 11 }), + (2.5f, [2, 11]), + (2.75f, [2, 11]), + (3f, [2, 8, 8, 11]), + (3.25f, [11, 11]), - Empty(3.5f), Empty(3.75f), Empty(4f), - } + Empty(3.5f), Empty(3.75f), Empty(4f) + ] }, { - "B", - new[] - { + "B", [ Empty(2f), Empty(2.25f), - (2.5f, new FuzzyFloat[] { 12, 21 }), - (2.75f, new FuzzyFloat[] { 12, 21 }), - (3f, new FuzzyFloat[] { 12, 15, 15, 21 }), - (3.25f, new FuzzyFloat[] { 18, 21 }), + (2.5f, [12, 21]), + (2.75f, [12, 21]), + (3f, [12, 15, 15, 21]), + (3.25f, [18, 21]), - Empty(3.5f), Empty(3.75f), Empty(4f), - } + Empty(3.5f), Empty(3.75f), Empty(4f) + ] }, { - "C", - new[] - { + "C", [ Empty(3f), Empty(3.25f), - (3.5f, new FuzzyFloat[] { 2, 8 }), - (3.75f, new FuzzyFloat[] { 2, 8 }), - (4f, new FuzzyFloat[] { 2, 8 }), - } + (3.5f, [2, 8]), + (3.75f, [2, 8]), + (4f, [2, 8]) + ] }, { - "D", - new[] - { + "D", [ Empty(3f), - (3.25f, new FuzzyFloat[] { 12, 12 }), - (3.5f, new FuzzyFloat[] { 12, 18 }), - (3.75f, new FuzzyFloat[] { 12, 15, 15, 18 }), - (4f, new FuzzyFloat[] { 12, 12, 18, 18 }), - } + (3.25f, [12, 12]), + (3.5f, [12, 18]), + (3.75f, [12, 15, 15, 18]), + (4f, [12, 12, 18, 18]) + ] }, { - "E", - new[] - { + "E", [ Empty(4f), Empty(4.25f), - (4.5f, new FuzzyFloat[] { 3, 3, 6, 6 }), - (4.75f, new[] { F(2.4166667f, 0.5f), 4, 4, 6 }), - (5f, new FuzzyFloat[] { 2, 6 }), - } + (4.5f, [3, 3, 6, 6]), + (4.75f, [F(2.4166667f, 0.5f), 4, 4, 6]), + (5f, [2, 6]) + ] }, { - "F", - new[] - { + "F", [ Empty(4f), // Eps = 0.01 to address inaccuracies on .NET Framework - (4.25f, new[] { F(13, 0.01f), F(13, 0.01f) }), - (4.5f, new[] { F(12.714286f, 0.5f), F(13.444444f, 0.5f), 16, 16 }), - (4.75f, new[] { F(12.357143f, 0.5f), 14, 14, 16 }), - (5f, new FuzzyFloat[] { 12, 16 }), - } + (4.25f, [F(13, 0.01f), F(13, 0.01f)]), + (4.5f, [F(12.714286f, 0.5f), F(13.444444f, 0.5f), 16, 16]), + (4.75f, [F(12.357143f, 0.5f), 14, 14, 16]), + (5f, [12, 16]) + ] }, { - "G", - new[] - { + "G", [ Empty(1f), Empty(1.25f), Empty(1.5f), - (1.75f, new FuzzyFloat[] { 6, 6 }), - (2f, new[] { F(4.6315789f, 1f), F(7.3684211f, 1f) }), - (2.25f, new FuzzyFloat[] { 2, 10 }), + (1.75f, [6, 6]), + (2f, [F(4.6315789f, 1f), F(7.3684211f, 1f)]), + (2.25f, [2, 10]), - Empty(2.5f), Empty(1.75f), Empty(3f), - } + Empty(2.5f), Empty(1.75f), Empty(3f) + ] }, { - "H", - new[] - { + "H", [ Empty(1f), Empty(1.25f), Empty(1.5f), - (1.75f, new FuzzyFloat[] { 16, 16 }), - (2f, new FuzzyFloat[] { 14, 14, 14, 16 }), // this emits 2 dummy points, but normally it should not corrupt quality too much - (2.25f, new FuzzyFloat[] { 16, 16 }), + (1.75f, [16, 16]), + (2f, [14, 14, 14, 16]), // this emits 2 dummy points, but normally it should not corrupt quality too much + (2.25f, [16, 16]), - Empty(2.5f), Empty(1.75f), Empty(3f), - } + Empty(2.5f), Empty(1.75f), Empty(3f) + ] } }; @@ -595,9 +578,9 @@ public void NumericCornerCases(string name, (float Y, FuzzyFloat[] X)[] expected public static TheoryData NumericCornerCases_Offset_Data() { - var result = new TheoryData(); + TheoryData result = new(); - float[] offsets = { 1e3f, 1e4f, 1e5f }; + float[] offsets = [1e3f, 1e4f, 1e5f]; foreach (float offset in offsets) { diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/RasterizerExtensionsTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/RasterizerExtensionsTests.cs index a9d2fe14..f05412e6 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/RasterizerExtensionsTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/RasterizerExtensionsTests.cs @@ -15,7 +15,7 @@ public class RasterizerExtensionsTests [Fact] public void DoesNotOverwriteIsDirtyFlagWhenOnlyFillingSubpixels() { - var scanner = PolygonScanner.Create(new RectangularPolygon(0.3f, 0.2f, 0.7f, 1.423f), 0, 20, 1, IntersectionRule.EvenOdd, MemoryAllocator.Default); + PolygonScanner scanner = PolygonScanner.Create(new RectangularPolygon(0.3f, 0.2f, 0.7f, 1.423f), 0, 20, 1, IntersectionRule.EvenOdd, MemoryAllocator.Default); float[] buffer = new float[12]; @@ -32,13 +32,13 @@ public void AntialiasingIsAntialiased(TestImageProvider provider where TPixel : unmanaged, IPixel { Font font36 = TestFontUtilities.GetFont(TestFonts.OpenSans, 20); - var textOpt = new RichTextOptions(font36) + RichTextOptions textOpt = new(font36) { Dpi = 96, Origin = new PointF(0, 0) }; - var comparer = ImageComparer.TolerantPercentage(0.001f); + ImageComparer comparer = ImageComparer.TolerantPercentage(0.001f); provider.RunValidatingProcessorTest( x => x .SetGraphicsOptions(o => o.Antialias = false) diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/TessellatedMultipolygonTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/TessellatedMultipolygonTests.cs index 60b31fc4..6dae4fb1 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/Scan/TessellatedMultipolygonTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/Scan/TessellatedMultipolygonTests.cs @@ -44,9 +44,9 @@ public void Create_FromPolygon_Case1(bool reverseOriginal) points.AsSpan().Reverse(); } - var polygon = new Polygon(points); + Polygon polygon = new(points); - using var multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); + using TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); VerifyRing(multipolygon[0], points, reverseOriginal, false); Assert.Equal(6, multipolygon.TotalVertexCount); } @@ -62,9 +62,9 @@ public void Create_FromPolygon_Case2(bool reverseOriginal) points.AsSpan().Reverse(); } - var polygon = new Polygon(points); + Polygon polygon = new(points); - using var multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); + using TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); VerifyRing(multipolygon[0], points, !reverseOriginal, false); } @@ -72,11 +72,11 @@ public void Create_FromPolygon_Case2(bool reverseOriginal) [Fact] public void Create_FromRecangle() { - var polygon = new RectangularPolygon(10, 20, 100, 50); + RectangularPolygon polygon = new(10, 20, 100, 50); PointF[] points = polygon.Flatten().Single().Points.Span.ToArray(); - using var multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); + using TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); VerifyRing(multipolygon[0], points, true, false); Assert.Equal(4, multipolygon.TotalVertexCount); } @@ -84,10 +84,10 @@ public void Create_FromRecangle() [Fact] public void Create_FromStar() { - var polygon = new Star(100, 100, 5, 30, 60); + Star polygon = new(100, 100, 5, 30, 60); PointF[] points = polygon.Flatten().Single().Points.Span.ToArray(); - using var multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); + using TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, MemoryAllocator); VerifyRing(multipolygon[0], points, true, false); } } diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs index bb9cb24b..64c6b2db 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs @@ -23,7 +23,7 @@ public void RequiresAtLeast3Verticies(int points, bool throws) } else { - var p = new Star(Vector2.Zero, points, 10f, 20f, 0); + Star p = new(Vector2.Zero, points, 10f, 20f, 0); Assert.NotNull(p); } } @@ -45,7 +45,7 @@ public void RadiusMustBeGreaterThan0(float radius, bool throws) } else { - var p = new Star(Vector2.Zero, 3, radius, radius, 0); + Star p = new(Vector2.Zero, 3, radius, radius, 0); Assert.NotNull(p); } } @@ -57,7 +57,7 @@ public void GeneratesCorrectPath() const float Radius2 = 30; int pointsCount = new Random().Next(3, 20); - var poly = new Star(Vector2.Zero, pointsCount, Radius, Radius2, 0); + Star poly = new(Vector2.Zero, pointsCount, Radius, Radius2, 0); PointF[] points = poly.Flatten().ToArray()[0].Points.ToArray(); @@ -95,7 +95,7 @@ public void AngleChangesOnePointToStartAtThatPosition() const float Radius2 = 20; double anAngle = new Random().NextDouble() * TwoPI; - var poly = new Star(Vector2.Zero, 3, Radius, Radius2, (float)anAngle); + Star poly = new(Vector2.Zero, 3, Radius, Radius2, (float)anAngle); ISimplePath[] points = poly.Flatten().ToArray(); IEnumerable allAngles = points[0].Points.ToArray().Select(b => Math.Atan2(b.Y, b.X)) diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/TestShapes.cs b/tests/ImageSharp.Drawing.Tests/Shapes/TestShapes.cs index 07f7fb55..a9f82b02 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/TestShapes.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/TestShapes.cs @@ -9,8 +9,8 @@ public static class TestShapes { public static IPath IrisSegment(int rotationPos) { - var center = new Vector2(603); - var segmentRotationCenter = new Vector2(301.16968f, 301.16974f); + Vector2 center = new(603); + Vector2 segmentRotationCenter = new(301.16968f, 301.16974f); IPath segment = new Polygon( new LinearLineSegment(new Vector2(230.54f, 361.0261f), new Vector2(5.8641942f, 361.46031f)), new CubicBezierLineSegment( @@ -27,8 +27,8 @@ public static IPath IrisSegment(float size, int rotationPos) { float scalingFactor = size / 1206; - var center = new Vector2(603); - var segmentRotationCenter = new Vector2(301.16968f, 301.16974f); + Vector2 center = new(603); + Vector2 segmentRotationCenter = new(301.16968f, 301.16974f); IPath segment = new Polygon( new LinearLineSegment(new Vector2(230.54f, 361.0261f), new Vector2(5.8641942f, 361.46031f)), new CubicBezierLineSegment( @@ -41,7 +41,7 @@ public static IPath IrisSegment(float size, int rotationPos) IPath rotated = segment.Transform(Matrix3x2.CreateRotation(angle, center)); - var scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero); + Matrix3x2 scaler = Matrix3x2.CreateScale(scalingFactor, Vector2.Zero); IPath scaled = rotated.Transform(scaler); return scaled; @@ -50,7 +50,7 @@ public static IPath IrisSegment(float size, int rotationPos) public static IPath HourGlass() { // center the shape outerRadii + 10 px away from edges - var sb = new PathBuilder(); + PathBuilder sb = new(); // overlay rectangle sb.AddLine(new Vector2(15, 0), new Vector2(25, 0)); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs index f62647d6..8e394675 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs @@ -12,7 +12,7 @@ public class TextBuilderTests public void TextBuilder_Bounds_AreCorrect() { Vector2 position = new(5, 5); - var options = new TextOptions(TestFontUtilities.GetFont(TestFonts.OpenSans, 16)) + TextOptions options = new(TestFontUtilities.GetFont(TestFonts.OpenSans, 16)) { Origin = position }; @@ -23,7 +23,7 @@ public void TextBuilder_Bounds_AreCorrect() RectangleF builderBounds = glyphs.Bounds; FontRectangle directMeasured = TextMeasurer.MeasureBounds(text, options); - var measuredBounds = new FontRectangle(new(0, 0), directMeasured.Size + directMeasured.Location); + FontRectangle measuredBounds = new(new Vector2(0, 0), directMeasured.Size + directMeasured.Location); Assert.Equal(measuredBounds.X, builderBounds.X); Assert.Equal(measuredBounds.Y, builderBounds.Y); diff --git a/tests/ImageSharp.Drawing.Tests/TestFile.cs b/tests/ImageSharp.Drawing.Tests/TestFile.cs index 3bce1acc..48db7f85 100644 --- a/tests/ImageSharp.Drawing.Tests/TestFile.cs +++ b/tests/ImageSharp.Drawing.Tests/TestFile.cs @@ -118,7 +118,7 @@ public string GetFileNameWithoutExtension(object value) /// The . /// public Image CreateRgba32Image(IImageDecoder decoder) - => this.CreateRgba32Image(decoder, new()); + => this.CreateRgba32Image(decoder, new DecoderOptions()); /// /// Creates a new image. diff --git a/tests/ImageSharp.Drawing.Tests/TestFontUtilities.cs b/tests/ImageSharp.Drawing.Tests/TestFontUtilities.cs index 699bd550..955ea397 100644 --- a/tests/ImageSharp.Drawing.Tests/TestFontUtilities.cs +++ b/tests/ImageSharp.Drawing.Tests/TestFontUtilities.cs @@ -71,13 +71,13 @@ public static FontFamily GetFontFamily(FontCollection collection, string name) /// private static string GetFontsDirectory() { - var directories = new List - { - "TestFonts/", // Here for code coverage tests. - "tests/ImageSharp.Drawing.Tests/TestFonts/", // from travis/build script - "../../../../../ImageSharp.Drawing.Tests/TestFonts/", // from Sandbox46 - "../../../../TestFonts/" - }; + List directories = + [ + "TestFonts/", // Here for code coverage tests. + "tests/ImageSharp.Drawing.Tests/TestFonts/", // from travis/build script + "../../../../../ImageSharp.Drawing.Tests/TestFonts/", // from Sandbox46 + "../../../../TestFonts/" + ]; directories = directories.SelectMany(x => new[] { diff --git a/tests/ImageSharp.Drawing.Tests/TestFormat.cs b/tests/ImageSharp.Drawing.Tests/TestFormat.cs index 2db0b097..49b8d12d 100644 --- a/tests/ImageSharp.Drawing.Tests/TestFormat.cs +++ b/tests/ImageSharp.Drawing.Tests/TestFormat.cs @@ -27,7 +27,7 @@ public TestFormat() this.Decoder = new TestDecoder(this); } - public List DecodeCalls { get; } = new(); + public List DecodeCalls { get; } = []; public TestEncoder Encoder { get; } @@ -37,7 +37,7 @@ public TestFormat() public MemoryStream CreateStream(byte[] marker = null) { - var ms = new MemoryStream(); + MemoryStream ms = new(); byte[] data = this.header; ms.Write(data, 0, data.Length); if (marker != null) @@ -53,7 +53,7 @@ public Stream CreateAsyncSemaphoreStream(SemaphoreSlim notifyWaitPositionReached { byte[] buffer = new byte[size]; this.header.CopyTo(buffer, 0); - var semaphoreStream = new SemaphoreReadMemoryStream(buffer, waitAfterPosition, notifyWaitPositionReachedSemaphore, continueSemaphore); + SemaphoreReadMemoryStream semaphoreStream = new(buffer, waitAfterPosition, notifyWaitPositionReachedSemaphore, continueSemaphore); return seeakable ? semaphoreStream : new AsyncStreamWrapper(semaphoreStream, () => false); } @@ -102,7 +102,7 @@ public Image Sample() public string Extension => "test_ext"; - public IEnumerable SupportedExtensions => new[] { "test_ext" }; + public IEnumerable SupportedExtensions => ["test_ext"]; public int HeaderSize => this.header.Length; @@ -110,7 +110,7 @@ public Image Sample() public string DefaultMimeType => this.MimeType; - public IEnumerable MimeTypes => new[] { this.MimeType }; + public IEnumerable MimeTypes => [this.MimeType]; public IEnumerable FileExtensions => this.SupportedExtensions; @@ -192,7 +192,7 @@ public class TestDecoder : SpecializedImageDecoder public TestDecoder(TestFormat testFormat) => this.testFormat = testFormat; - public IEnumerable MimeTypes => new[] { this.testFormat.MimeType }; + public IEnumerable MimeTypes => [this.testFormat.MimeType]; public IEnumerable FileExtensions => this.testFormat.SupportedExtensions; @@ -204,7 +204,7 @@ protected override ImageInfo Identify(DecoderOptions options, Stream stream, Can { using Image image = this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); ImageMetadata metadata = image.Metadata; - return new(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) + return new ImageInfo(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) { PixelType = metadata.GetDecodedPixelTypeInfo() }; @@ -245,7 +245,7 @@ public class TestEncoder : IImageEncoder public TestEncoder(TestFormat testFormat) => this.testFormat = testFormat; - public IEnumerable MimeTypes => new[] { this.testFormat.MimeType }; + public IEnumerable MimeTypes => [this.testFormat.MimeType]; public IEnumerable FileExtensions => this.testFormat.SupportedExtensions; diff --git a/tests/ImageSharp.Drawing.Tests/TestImages.cs b/tests/ImageSharp.Drawing.Tests/TestImages.cs index 0afbeede..894f9247 100644 --- a/tests/ImageSharp.Drawing.Tests/TestImages.cs +++ b/tests/ImageSharp.Drawing.Tests/TestImages.cs @@ -102,13 +102,13 @@ public static class Bad } public static readonly string[] All = - { + [ P1, Pd, Blur, Splash, Cross, Powerpoint, SplashInterlaced, Interlaced, Filter0, Filter1, Filter2, Filter3, Filter4, FilterVar, VimImage1, VimImage2, VersioningImage1, VersioningImage2, Ratio4x1, Ratio1x4 - }; + ]; } public static class Jpeg @@ -125,7 +125,7 @@ public static class Bad public const string ExifUndefType = "Jpg/progressive/ExifUndefType.jpg"; } - public static readonly string[] All = { Fb, Progress, Festzug }; + public static readonly string[] All = [Fb, Progress, Festzug]; } public static class Baseline @@ -158,12 +158,12 @@ public static class Bad public const string YcckSubsample1222 = "Jpg/baseline/ycck-subsample-1222.jpg"; public static readonly string[] All = - { + [ Cmyk, Ycck, Exif, Floorplan, Calliphora, Turtle, GammaDalaiLamaGray, Hiyamugi, Jpeg400, Jpeg420Exif, Jpeg444, Ratio1x1, Testorig12bit, YcckSubsample1222 - }; + ]; } public static class Issues @@ -310,24 +310,24 @@ public static class Bmp public const string RgbaAlphaBitfields = "Bmp/rgba32abf.bmp"; public static readonly string[] BitFields = - { + [ Rgb32bfdef, Rgb32bf, Rgb16565, Rgb16bfdef, Rgb16565pal, - Issue735, - }; + Issue735 + ]; public static readonly string[] Miscellaneous = - { + [ Car, F, NegHeight - }; + ]; public static readonly string[] Benchmark = - { + [ Car, F, NegHeight, @@ -344,7 +344,7 @@ public static class Bmp Bit16, Bit16Inverted, Bit32Rgb - }; + ]; } public static class Gif @@ -366,7 +366,7 @@ public static class Issues public const string BadDescriptorWidth = "Gif/issues/issue403_baddescriptorwidth.gif"; } - public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 }; + public static readonly string[] All = [Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4]; } public static class Tga diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs index 53011c8f..35e7e044 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs @@ -63,7 +63,7 @@ public override IEnumerable GetData(MethodInfo testMethod) if (!addedRows.Any()) { - addedRows = new[] { new object[0] }; + addedRows = [[]]; } bool firstIsProvider = this.FirstIsProvider(testMethod); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBasicTestPatternImagesAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBasicTestPatternImagesAttribute.cs index c5fa8198..5fb2dd7a 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBasicTestPatternImagesAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBasicTestPatternImagesAttribute.cs @@ -31,5 +31,6 @@ public WithBasicTestPatternImagesAttribute(string memberData, int width, int hei protected override string GetFactoryMethodName(MethodInfo testMethod) => "BasicTestPattern"; - protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => new object[] { this.Width, this.Height }; + protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => [this.Width, this.Height + ]; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs index c517941f..f8a6cc22 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithBlankImageAttribute.cs @@ -46,5 +46,6 @@ public WithBlankImageAttribute(string memberData, int width, int height, PixelTy protected override string GetFactoryMethodName(MethodInfo testMethod) => "Blank"; - protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => new object[] { this.Width, this.Height }; + protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => [this.Width, this.Height + ]; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileAttribute.cs index e4885105..fbde45b2 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileAttribute.cs @@ -33,7 +33,7 @@ public WithFileAttribute(string fileName, PixelTypes pixelTypes, params object[] public WithFileAttribute(string fileName, string dataMemberName, PixelTypes pixelTypes, params object[] additionalParameters) : base(dataMemberName, pixelTypes, additionalParameters) => this.fileName = fileName; - protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => new object[] { this.fileName }; + protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => [this.fileName]; protected override string GetFactoryMethodName(MethodInfo testMethod) => "File"; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs index e78b83c0..9ea41e4d 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithFileCollectionAttribute.cs @@ -52,7 +52,7 @@ protected override IEnumerable GetAllFactoryMethodArgs(MethodInfo test Func accessor = this.GetPropertyAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName); accessor = accessor ?? this.GetFieldAccessor(testMethod.DeclaringType, this.fileEnumeratorMemberName); - var files = (IEnumerable)accessor(); + IEnumerable files = (IEnumerable)accessor(); return files.Select(f => new object[] { f }); } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs index 9d84a594..f52f22f5 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithMemberFactoryAttribute.cs @@ -25,7 +25,7 @@ public WithMemberFactoryAttribute(string memberMethodName, PixelTypes pixelTypes : base(null, pixelTypes, additionalParameters) => this.memberMethodName = memberMethodName; protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) - => new object[] { testMethod.DeclaringType.FullName, this.memberMethodName }; + => [testMethod.DeclaringType.FullName, this.memberMethodName]; protected override string GetFactoryMethodName(MethodInfo testMethod) => "Lambda"; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs index 8cbd1c49..aa731040 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithSolidFilledImagesAttribute.cs @@ -158,7 +158,7 @@ public WithSolidFilledImagesAttribute( public byte A { get; } protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) - => new object[] { this.Width, this.Height, this.R, this.G, this.B, this.A }; + => [this.Width, this.Height, this.R, this.G, this.B, this.A]; protected override string GetFactoryMethodName(MethodInfo testMethod) => "Solid"; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs index 1fac1ff2..124782dd 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Attributes/WithTestPatternImageAttribute.cs @@ -50,5 +50,6 @@ public WithTestPatternImageAttribute(string memberData, int width, int height, P protected override string GetFactoryMethodName(MethodInfo testMethod) => "TestPattern"; - protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => new object[] { this.Width, this.Height }; + protected override object[] GetFactoryMethodArgs(MethodInfo testMethod, Type factoryType) => [this.Width, this.Height + ]; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/DebugDraw.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/DebugDraw.cs index f6e00427..53c15901 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/DebugDraw.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/DebugDraw.cs @@ -39,19 +39,19 @@ public void Polygon(IPath path, float gridSize = 10f, float scale = 10f, [Caller img.SaveAsPng(outFile); } - private static PointF P(float x, float y) => new PointF(x, y); + private static PointF P(float x, float y) => new(x, y); private static void DrawGrid(IImageProcessingContext ctx, RectangleF rect, float gridSize) { for (float x = rect.Left; x <= rect.Right; x += gridSize) { - PointF[] line = { P(x, rect.Top), P(x, rect.Bottom) }; + PointF[] line = [P(x, rect.Top), P(x, rect.Bottom)]; ctx.DrawLine(GridPen, line); } for (float y = rect.Top; y <= rect.Bottom; y += gridSize) { - PointF[] line = { P(rect.Left, y), P(rect.Right, y) }; + PointF[] line = [P(rect.Left, y), P(rect.Right, y)]; ctx.DrawLine(GridPen, line); } } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs index 4b2d9a0c..213cba8e 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/FeatureTesting/FeatureTestRunner.cs @@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.TestUtilities; /// public static class FeatureTestRunner { - private static readonly char[] SplitChars = { ',', ' ' }; + private static readonly char[] SplitChars = [',', ' ']; /// /// Allows the deserialization of parameters passed to the feature test. diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/FuzzyFloat.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/FuzzyFloat.cs index 34e7abff..c769d39e 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/FuzzyFloat.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/FuzzyFloat.cs @@ -32,11 +32,11 @@ public FuzzyFloat(float value, float eps) public static implicit operator float(FuzzyFloat x) => x.value; - public static implicit operator FuzzyFloat(float x) => new FuzzyFloat(x); + public static implicit operator FuzzyFloat(float x) => new(x); - public static implicit operator FuzzyFloat(int x) => new FuzzyFloat(x); + public static implicit operator FuzzyFloat(int x) => new(x); - public static implicit operator FuzzyFloat(double x) => new FuzzyFloat((float)x); + public static implicit operator FuzzyFloat(double x) => new((float)x); public bool Equals(float x) => x >= this.min && x <= this.max; @@ -56,7 +56,7 @@ public void Deserialize(IXunitSerializationInfo info) this.max = this.value + this.eps; } - public static FuzzyFloat operator +(FuzzyFloat a, float b) => new FuzzyFloat(a.value + b, a.eps); + public static FuzzyFloat operator +(FuzzyFloat a, float b) => new(a.value + b, a.eps); - public static FuzzyFloat operator -(FuzzyFloat a, float b) => new FuzzyFloat(a.value - b, a.eps); + public static FuzzyFloat operator -(FuzzyFloat a, float b) => new(a.value - b, a.eps); } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs index 0aad4c3f..4af11a35 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ExactImageComparer.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.TestUtilities.ImageComparison; public class ExactImageComparer : ImageComparer { - public static ExactImageComparer Instance { get; } = new ExactImageComparer(); + public static ExactImageComparer Instance { get; } = new(); public override ImageSimilarityReport CompareImagesOrFrames( int index, @@ -23,10 +23,10 @@ public override ImageSimilarityReport CompareImagesOrFrames(); + List differences = []; Configuration configuration = expected.Configuration; Buffer2D expectedBuffer = expected.PixelBuffer; Buffer2D actualBuffer = actual.PixelBuffer; @@ -46,7 +46,7 @@ public override ImageSimilarityReport CompareImagesOrFrames reports) { - var sb = new StringBuilder(); + StringBuilder sb = new(); sb.Append(Environment.NewLine); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageComparer.cs index 597741e5..d4f13546 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -51,7 +51,7 @@ public static IEnumerable> CompareImages where TPixelA : unmanaged, IPixel where TPixelB : unmanaged, IPixel { - List> result = new(); + List> result = []; int expectedFrameCount = actual.Frames.Count; if (predicate != null) @@ -147,7 +147,7 @@ public static void VerifySimilarityIgnoreRegion( IEnumerable> reports = comparer.CompareImages(expected, actual); if (reports.Any()) { - var cleanedReports = new List>(reports.Count()); + List> cleanedReports = new(reports.Count()); foreach (ImageSimilarityReport r in reports) { IEnumerable outsideChanges = r.Differences.Where( diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs index 409a1fec..40ab8974 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/ImageSimilarityReport.cs @@ -61,7 +61,7 @@ public override string ToString() private string PrintDifference() { - var sb = new StringBuilder(); + StringBuilder sb = new(); if (this.TotalNormalizedDifference.HasValue) { sb.AppendLine(); @@ -103,7 +103,7 @@ public ImageSimilarityReport( } public static ImageSimilarityReport Empty => - new ImageSimilarityReport(0, null, null, Enumerable.Empty(), 0f); + new(0, null, null, [], 0f); public new ImageFrame ExpectedImage => (ImageFrame)base.ExpectedImage; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index eeb257fa..0c0e43d1 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -64,12 +64,12 @@ public override ImageSimilarityReport CompareImagesOrFrames(); + List differences = []; Configuration configuration = expected.Configuration; Buffer2D expectedBuffer = expected.PixelBuffer; Buffer2D actualBuffer = actual.PixelBuffer; @@ -88,7 +88,7 @@ public override ImageSimilarityReport CompareImagesOrFrames this.PerPixelManhattanThreshold) { - var diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]); + PixelDifference diff = new(new Point(x, y), aBuffer[x], bBuffer[x]); differences.Add(diff); totalDifference += d; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs index 87ea2925..e2ed4a94 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs @@ -36,7 +36,7 @@ public BasicTestPatternProvider() public override Image GetImage() { - var result = new Image(this.Configuration, this.Width, this.Height); + Image result = new(this.Configuration, this.Width, this.Height); result.ProcessPixelRows(accessor => { int midY = this.Height / 2; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BlankProvider.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BlankProvider.cs index cb31e3ae..487cb0ea 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BlankProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/BlankProvider.cs @@ -33,7 +33,7 @@ public BlankProvider() protected int Width { get; private set; } - public override Image GetImage() => new Image(this.Configuration, this.Width, this.Height); + public override Image GetImage() => new(this.Configuration, this.Width, this.Height); public override void Deserialize(IXunitSerializationInfo info) { diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/FileProvider.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/FileProvider.cs index 5e3cd321..2eee9796 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/FileProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/FileProvider.cs @@ -46,7 +46,7 @@ private static Dictionary GetDecoderParameters( { Type type = options.GetType(); - var data = new Dictionary(); + Dictionary data = new(); while (type != null && type != typeof(object)) { @@ -194,7 +194,7 @@ public override Image GetImage(IImageDecoder decoder, DecoderOptions opt return this.DecodeImage(decoder, options); } - var key = new Key(this.PixelType, this.FilePath, decoder, options, null); + Key key = new(this.PixelType, this.FilePath, decoder, options, null); Image cachedImage = Cache.GetOrAdd(key, _ => this.DecodeImage(decoder, options)); return cachedImage.Clone(this.Configuration); @@ -225,7 +225,7 @@ public override Image GetImage(ISpecializedImageDecoder decoder, T return this.DecodeImage(decoder, options); } - var key = new Key(this.PixelType, this.FilePath, decoder, options.GeneralOptions, options); + Key key = new(this.PixelType, this.FilePath, decoder, options.GeneralOptions, options); Image cachedImage = Cache.GetOrAdd(key, _ => this.DecodeImage(decoder, options)); return cachedImage.Clone(this.Configuration); @@ -259,7 +259,7 @@ private Image DecodeImage(IImageDecoder decoder, DecoderOptions options) { options.SetConfiguration(this.Configuration); - var testFile = TestFile.Create(this.FilePath); + TestFile testFile = TestFile.Create(this.FilePath); using Stream stream = new MemoryStream(testFile.Bytes); return decoder.Decode(options, stream); } @@ -269,7 +269,7 @@ private Image DecodeImage(ISpecializedImageDecoder decoder, T opti { options.GeneralOptions.SetConfiguration(this.Configuration); - var testFile = TestFile.Create(this.FilePath); + TestFile testFile = TestFile.Create(this.FilePath); using Stream stream = new MemoryStream(testFile.Bytes); return decoder.Decode(options, stream); } @@ -277,7 +277,7 @@ private Image DecodeImage(ISpecializedImageDecoder decoder, T opti public static string GetFilePathOrNull(ITestImageProvider provider) { - var fileProvider = provider as FileProvider; + FileProvider fileProvider = provider as FileProvider; return fileProvider?.FilePath; } } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/MemberMethodProvider.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/MemberMethodProvider.cs index c0d34715..7bd3c918 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/MemberMethodProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/MemberMethodProvider.cs @@ -54,7 +54,7 @@ public override void Deserialize(IXunitSerializationInfo info) private Func> GetFactory() { - var declaringType = Type.GetType(this.declaringTypeName); + Type declaringType = Type.GetType(this.declaringTypeName); MethodInfo m = declaringType.GetMethod(this.methodName); Type pixelType = typeof(TPixel); Type imgType = typeof(Image<>).MakeGenericType(pixelType); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 9f6d1cf4..21bca03e 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -88,10 +88,10 @@ public static TestImageProvider Solid( public abstract Image GetImage(); public Image GetImage(IImageDecoder decoder) - => this.GetImage(decoder, new()); + => this.GetImage(decoder, new DecoderOptions()); public Task> GetImageAsync(IImageDecoder decoder) - => this.GetImageAsync(decoder, new()); + => this.GetImageAsync(decoder, new DecoderOptions()); public virtual Image GetImage(IImageDecoder decoder, DecoderOptions options) => throw new NotSupportedException($"Decoder specific GetImage() is not supported with {this.GetType().Name}!"); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 5ca033bf..44334853 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Numerics; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; using Xunit.Abstractions; @@ -18,16 +19,16 @@ private class TestPatternProvider : BlankProvider private static readonly Dictionary> TestImages = new(); private static readonly TPixel[] BlackWhitePixels = - { + [ Color.Black.ToPixel(), Color.White.ToPixel() - }; + ]; private static readonly TPixel[] PinkBluePixels = - { + [ Color.HotPink.ToPixel(), Color.Blue.ToPixel() - }; + ]; public TestPatternProvider(int width, int height) : base(width, height) @@ -49,7 +50,7 @@ public override Image GetImage() { if (!TestImages.ContainsKey(this.SourceFileOrDescription)) { - var image = new Image(this.Width, this.Height); + Image image = new(this.Width, this.Height); DrawTestPattern(image); TestImages.Add(this.SourceFileOrDescription, image); } @@ -153,9 +154,9 @@ private static void TransparentGradients(Buffer2D pixels) int bottom = pixels.Height; int height = (int)Math.Ceiling(pixels.Height / 6f); - var red = Color.Red.ToPixel().ToVector4(); // use real color so we can see how it translates in the test pattern - var green = Color.Green.ToPixel().ToVector4(); // use real color so we can see how it translates in the test pattern - var blue = Color.Blue.ToPixel().ToVector4(); // use real color so we can see how it translates in the test pattern + Vector4 red = Color.Red.ToPixel().ToVector4(); // use real color so we can see how it translates in the test pattern + Vector4 green = Color.Green.ToPixel().ToVector4(); // use real color so we can see how it translates in the test pattern + Vector4 blue = Color.Blue.ToPixel().ToVector4(); // use real color so we can see how it translates in the test pattern for (int x = left; x < right; x++) { @@ -197,14 +198,14 @@ private static void Rainbow(Buffer2D pixels) int pixelCount = left * top; uint stepsPerPixel = (uint)(uint.MaxValue / pixelCount); - var t = new Rgba32(0); + Rgba32 t = new(0); for (int x = left; x < right; x++) { for (int y = top; y < bottom; y++) { t.PackedValue += stepsPerPixel; - var v = t.ToVector4(); + Vector4 v = t.ToVector4(); // v.W = (x - left) / (float)left; pixels[x, y] = TPixel.FromVector4(v); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/MeasureFixture.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/MeasureFixture.cs index 8d53239d..ddf89cfc 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/MeasureFixture.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/MeasureFixture.cs @@ -30,7 +30,7 @@ public void Measure(int times, Action action, [CallerMemberName] string operatio this.Output?.WriteLine($"{operationName} X {times} ..."); } - var sw = Stopwatch.StartNew(); + Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { @@ -57,7 +57,7 @@ public class MeasureGuard : IDisposable { private readonly string operation; - private readonly Stopwatch stopwatch = new Stopwatch(); + private readonly Stopwatch stopwatch = new(); public MeasureGuard(ITestOutputHelper output, string operation) { diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/PolygonFactory.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/PolygonFactory.cs index 4d371b70..e0bdfa02 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/PolygonFactory.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/PolygonFactory.cs @@ -21,7 +21,7 @@ internal static class PolygonFactory // https://github.com/SixLabors/ImageSharp.Drawing/issues/15#issuecomment-521061283 public static IReadOnlyList GetGeoJsonPoints(Feature geometryOwner, Matrix3x2 transform) { - var result = new List(); + List result = []; IGeometryObject geometry = geometryOwner.Geometry; if (geometry is GeoJSON.Net.Geometry.Polygon p) { @@ -88,7 +88,7 @@ public static PointF[] CreatePointArray(params (float X, float Y)[] coords) => public static T[] CloneArray(this T[] points) { - var result = new T[points.Length]; + T[] result = new T[points.Length]; Array.Copy(points, result, points.Length); return result; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs index 7d3d926b..f1e9a7cb 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs @@ -32,15 +32,15 @@ public MagickReferenceDecoder(IImageFormat imageFormat, bool validate) this.validate = validate; } - public static MagickReferenceDecoder Png { get; } = new MagickReferenceDecoder(PngFormat.Instance); + public static MagickReferenceDecoder Png { get; } = new(PngFormat.Instance); - public static MagickReferenceDecoder Bmp { get; } = new MagickReferenceDecoder(BmpFormat.Instance); + public static MagickReferenceDecoder Bmp { get; } = new(BmpFormat.Instance); - public static MagickReferenceDecoder Jpeg { get; } = new MagickReferenceDecoder(JpegFormat.Instance); + public static MagickReferenceDecoder Jpeg { get; } = new(JpegFormat.Instance); - public static MagickReferenceDecoder Tiff { get; } = new MagickReferenceDecoder(TiffFormat.Instance); + public static MagickReferenceDecoder Tiff { get; } = new(TiffFormat.Instance); - public static MagickReferenceDecoder WebP { get; } = new MagickReferenceDecoder(WebpFormat.Instance); + public static MagickReferenceDecoder WebP { get; } = new(WebpFormat.Instance); protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { @@ -96,7 +96,7 @@ protected override Image Decode(DecoderOptions options, Stream s } } - return ReferenceCodecUtilities.EnsureDecodedMetadata(new(configuration, metadata, framesList), this.imageFormat); + return ReferenceCodecUtilities.EnsureDecodedMetadata(new Image(configuration, metadata, framesList), this.imageFormat); } protected override Image Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) @@ -106,7 +106,7 @@ protected override ImageInfo Identify(DecoderOptions options, Stream stream, Can { using Image image = this.Decode(options, stream, cancellationToken); ImageMetadata metadata = image.Metadata; - return new(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) + return new ImageInfo(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) { PixelType = metadata.GetDecodedPixelTypeInfo() }; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index 8e087f75..ab9b698f 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -27,7 +27,7 @@ internal static unsafe Image From32bppArgbSystemDrawingBitmap(Bi int w = bmp.Width; int h = bmp.Height; - var fullRect = new System.Drawing.Rectangle(0, 0, w, h); + System.Drawing.Rectangle fullRect = new(0, 0, w, h); if (bmp.PixelFormat != PixelFormat.Format32bppArgb) { @@ -37,7 +37,7 @@ internal static unsafe Image From32bppArgbSystemDrawingBitmap(Bi } BitmapData data = bmp.LockBits(fullRect, ImageLockMode.ReadWrite, bmp.PixelFormat); - var image = new Image(w, h); + Image image = new(w, h); try { byte* sourcePtrBase = (byte*)data.Scan0; @@ -86,7 +86,7 @@ internal static unsafe Image From24bppRgbSystemDrawingBitmap(Bit int w = bmp.Width; int h = bmp.Height; - var fullRect = new System.Drawing.Rectangle(0, 0, w, h); + System.Drawing.Rectangle fullRect = new(0, 0, w, h); if (bmp.PixelFormat != PixelFormat.Format24bppRgb) { @@ -96,7 +96,7 @@ internal static unsafe Image From24bppRgbSystemDrawingBitmap(Bit } BitmapData data = bmp.LockBits(fullRect, ImageLockMode.ReadWrite, bmp.PixelFormat); - var image = new Image(w, h); + Image image = new(w, h); try { byte* sourcePtrBase = (byte*)data.Scan0; @@ -136,8 +136,8 @@ internal static unsafe Bitmap To32bppArgbSystemDrawingBitmap(Image this.imageFormat = imageFormat; - public static SystemDrawingReferenceDecoder Png { get; } = new SystemDrawingReferenceDecoder(PngFormat.Instance); + public static SystemDrawingReferenceDecoder Png { get; } = new(PngFormat.Instance); - public static SystemDrawingReferenceDecoder Bmp { get; } = new SystemDrawingReferenceDecoder(BmpFormat.Instance); + public static SystemDrawingReferenceDecoder Bmp { get; } = new(BmpFormat.Instance); protected override ImageInfo Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) { using Image image = this.Decode(options, stream, cancellationToken); ImageMetadata metadata = image.Metadata; - return new(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) + return new ImageInfo(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) { PixelType = metadata.GetDecodedPixelTypeInfo() }; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs index f67c4630..b3cf88c9 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/ReferenceCodecs/SystemDrawingReferenceEncoder.cs @@ -15,9 +15,9 @@ public class SystemDrawingReferenceEncoder : IImageEncoder public SystemDrawingReferenceEncoder(ImageFormat imageFormat) => this.imageFormat = imageFormat; - public static SystemDrawingReferenceEncoder Png { get; } = new SystemDrawingReferenceEncoder(ImageFormat.Png); + public static SystemDrawingReferenceEncoder Png { get; } = new(ImageFormat.Png); - public static SystemDrawingReferenceEncoder Bmp { get; } = new SystemDrawingReferenceEncoder(ImageFormat.Bmp); + public static SystemDrawingReferenceEncoder Bmp { get; } = new(ImageFormat.Bmp); public bool SkipMetadata { get; init; } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.Formats.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.Formats.cs index 7651b544..01598903 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.Formats.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.Formats.cs @@ -53,7 +53,7 @@ private static void ConfigureCodecs( private static Configuration CreateDefaultConfiguration() { - var cfg = new Configuration( + Configuration cfg = new( new JpegConfigurationModule(), new GifConfigurationModule(), new TgaConfigurationModule()); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs index 91978246..d8a85db9 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestEnvironment.cs @@ -19,9 +19,9 @@ public static partial class TestEnvironment private const string ToolsDirectoryRelativePath = @"tests\Images\External\tools"; - private static readonly Lazy SolutionDirectoryFullPathLazy = new Lazy(GetSolutionDirectoryFullPathImpl); + private static readonly Lazy SolutionDirectoryFullPathLazy = new(GetSolutionDirectoryFullPathImpl); - private static readonly Lazy NetCoreVersionLazy = new Lazy(GetNetCoreVersion); + private static readonly Lazy NetCoreVersionLazy = new(GetNetCoreVersion); internal static bool IsFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"); @@ -54,7 +54,7 @@ private static string GetSolutionDirectoryFullPathImpl() { string assemblyLocation = typeof(TestEnvironment).GetTypeInfo().Assembly.Location; - var assemblyFile = new FileInfo(assemblyLocation); + FileInfo assemblyFile = new(assemblyLocation); DirectoryInfo directory = assemblyFile.Directory; @@ -144,7 +144,7 @@ internal static string CreateOutputDirectory(string path, params string[] pathPa private static string GetNetCoreVersion() { Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; - string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); + string[] assemblyPath = assembly.Location.Split(['/', '\\'], StringSplitOptions.RemoveEmptyEntries); int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) { diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestImageExtensions.cs index 16c03c23..34f35fc6 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestImageExtensions.cs @@ -341,7 +341,7 @@ public static Image GetReferenceOutputImageMultiFrame( appendPixelTypeToFileName, predicate); - List> temporaryFrameImages = new(); + List> temporaryFrameImages = []; IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(frameFiles[0]); @@ -691,7 +691,7 @@ internal static string VerifyEncoder( internal static Image ToGrayscaleImage(this Buffer2D buffer, float scale) { - var image = new Image(buffer.Width, buffer.Height); + Image image = new(buffer.Width, buffer.Height); Assert.True(image.Frames.RootFrame.DangerousTryGetSinglePixelMemory(out Memory pixelMem)); Span pixels = pixelMem.Span; @@ -700,7 +700,7 @@ internal static Image ToGrayscaleImage(this Buffer2D buffer, floa for (int i = 0; i < bufferSpan.Length; i++) { float value = bufferSpan[i] * scale; - var v = new Vector4(value, value, value, 1f); + Vector4 v = new(value, value, value, 1f); pixels[i] = Rgba32.FromVector4(v); } @@ -727,7 +727,7 @@ protected override void OnFrameApply(ImageFrame source) Rectangle sourceRectangle = this.SourceRectangle; Configuration configuration = this.Configuration; - var operation = new RowOperation(configuration, sourceRectangle, source.PixelBuffer); + RowOperation operation = new(configuration, sourceRectangle, source.PixelBuffer); ParallelRowIterator.IterateRowIntervals( configuration, diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryAllocator.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryAllocator.cs index 2625e465..997089dc 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryAllocator.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryAllocator.cs @@ -10,8 +10,8 @@ namespace SixLabors.ImageSharp.Drawing.Tests; internal class TestMemoryAllocator : MemoryAllocator { - private readonly List allocationLog = new(); - private readonly List returnLog = new(); + private readonly List allocationLog = []; + private readonly List returnLog = []; public TestMemoryAllocator(byte dirtyValue = 42) => this.DirtyValue = dirtyValue; @@ -37,7 +37,7 @@ public override IMemoryOwner Allocate(int length, AllocationOptions option private T[] AllocateArray(int length, AllocationOptions options) where T : struct { - var array = new T[length + 42]; + T[] array = new T[length + 42]; this.allocationLog.Add(AllocationRequest.Create(options, length, array)); if (options == AllocationOptions.None) diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryManager.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryManager.cs index c2c0f636..bdac42d7 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryManager.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestMemoryManager.cs @@ -23,7 +23,7 @@ public TestMemoryManager(T[] pixelArray) public static TestMemoryManager CreateAsCopyOf(Span copyThisBuffer) { - var pixelArray = new T[copyThisBuffer.Length]; + T[] pixelArray = new T[copyThisBuffer.Length]; copyThisBuffer.CopyTo(pixelArray); return new TestMemoryManager(pixelArray); } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestUtils.cs index 5d572874..b49b62bf 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestUtils.cs @@ -16,14 +16,14 @@ namespace SixLabors.ImageSharp.Drawing.Tests; /// public static class TestUtils { - private static readonly Dictionary ClrTypes2PixelTypes = new Dictionary(); + private static readonly Dictionary ClrTypes2PixelTypes = new(); private static readonly Assembly ImageSharpAssembly = typeof(Rgba32).GetTypeInfo().Assembly; - private static readonly Dictionary PixelTypes2ClrTypes = new Dictionary(); + private static readonly Dictionary PixelTypes2ClrTypes = new(); private static readonly PixelTypes[] AllConcretePixelTypes = GetAllPixelTypes() - .Except(new[] { PixelTypes.Undefined, PixelTypes.All }) + .Except([PixelTypes.Undefined, PixelTypes.All]) .ToArray(); static TestUtils() @@ -55,8 +55,8 @@ public static bool IsEquivalentTo(this Image a, Image b, return false; } - var rgb1 = default(Rgb24); - var rgb2 = default(Rgb24); + Rgb24 rgb1 = default(Rgb24); + Rgb24 rgb2 = default(Rgb24); Buffer2D pixA = a.GetRootFramePixelBuffer(); Buffer2D pixB = b.GetRootFramePixelBuffer(); @@ -102,7 +102,7 @@ public static IEnumerable> ExpandAllTypes(this Pi { if (pixelTypes == PixelTypes.Undefined) { - return Enumerable.Empty>(); + return []; } else if (pixelTypes == PixelTypes.All) { @@ -110,7 +110,7 @@ public static IEnumerable> ExpandAllTypes(this Pi return PixelTypes2ClrTypes; } - var result = new Dictionary(); + Dictionary result = new(); foreach (PixelTypes pt in AllConcretePixelTypes) { if (pixelTypes.HasAll(pt)) @@ -133,7 +133,7 @@ internal static bool HasAll(this PixelTypes pixelTypes, PixelTypes flagsToCheck) internal static Color GetColorByName(string colorName) { - var f = (FieldInfo)typeof(Color).GetMember(colorName)[0]; + FieldInfo f = (FieldInfo)typeof(Color).GetMember(colorName)[0]; return (Color)f.GetValue(null); } @@ -246,9 +246,9 @@ public static void RunValidatingProcessorTestOnWrappedMemoryImage( { Assert.True(image0.DangerousTryGetSinglePixelMemory(out Memory imageMem)); Span imageSpan = imageMem.Span; - var mmg = TestMemoryManager.CreateAsCopyOf(imageSpan); + TestMemoryManager mmg = TestMemoryManager.CreateAsCopyOf(imageSpan); - using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) + using (Image image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height)) { image1.Mutate(process); image1.DebugSave( @@ -297,7 +297,7 @@ internal static void RunRectangleConstrainedValidatingProcessorTest( using (Image image = provider.GetImage()) { - var bounds = new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2); + Rectangle bounds = new(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2); image.Mutate(x => process(x, bounds)); image.DebugSave(provider, testOutputDetails); image.CompareToReferenceOutput(comparer, provider, testOutputDetails); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestVector4.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestVector4.cs index 3a0e7574..cb5744cc 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/TestVector4.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/TestVector4.cs @@ -30,7 +30,7 @@ public TestVector4(float x, float y, float z, float w) public static implicit operator Vector4(TestVector4 d) => d?.AsVector() ?? default; - public Vector4 AsVector() => new Vector4(this.X, this.Y, this.Z, this.W); + public Vector4 AsVector() => new(this.X, this.Y, this.Z, this.W); public void Deserialize(IXunitSerializationInfo info) { diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/ImageComparerTests.cs index 99d29432..f8613024 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/ImageComparerTests.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -29,7 +29,7 @@ public void TolerantImageComparer_ApprovesPerfectSimilarity( { using (Image clone = image.Clone()) { - var comparer = ImageComparer.Tolerant(imageThreshold, pixelThreshold); + ImageComparer comparer = ImageComparer.Tolerant(imageThreshold, pixelThreshold); comparer.VerifySimilarity(image, clone); } } @@ -46,7 +46,7 @@ public void TolerantImageComparer_ApprovesSimilarityBelowTolerance(TestI { ImagingTestCaseUtility.ModifyPixel(clone, 0, 0, 1); - var comparer = ImageComparer.Tolerant(); + ImageComparer comparer = ImageComparer.Tolerant(); comparer.VerifySimilarity(image, clone); } } @@ -64,7 +64,7 @@ public void TolerantImageComparer_DoesNotApproveSimilarityAboveTolerance byte perChannelChange = 20; ImagingTestCaseUtility.ModifyPixel(clone, 3, 1, perChannelChange); - var comparer = ImageComparer.Tolerant(); + ImageComparer comparer = ImageComparer.Tolerant(); ImageDifferenceIsOverThresholdException ex = Assert.ThrowsAny( () => comparer.VerifySimilarity(image, clone)); @@ -88,7 +88,7 @@ public void TolerantImageComparer_TestPerPixelThreshold(TestImageProvide ImagingTestCaseUtility.ModifyPixel(clone, 1, 0, 1); ImagingTestCaseUtility.ModifyPixel(clone, 2, 0, 1); - var comparer = ImageComparer.Tolerant(perPixelManhattanThreshold: 257 * 3); + ImageComparer comparer = ImageComparer.Tolerant(perPixelManhattanThreshold: 257 * 3); comparer.VerifySimilarity(image, clone); } } diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs index ec000014..92a49c93 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestImageProviderTests.cs @@ -13,13 +13,13 @@ namespace SixLabors.ImageSharp.Drawing.Tests; public class TestImageProviderTests { - public static readonly TheoryData BasicData = new TheoryData + public static readonly TheoryData BasicData = new() { TestImageProvider.Blank(10, 20), TestImageProvider.Blank(10, 20), }; - public static readonly TheoryData FileData = new TheoryData + public static readonly TheoryData FileData = new() { TestImageProvider.File(TestImages.Bmp.Car), TestImageProvider.File(TestImages.Bmp.F) @@ -27,13 +27,11 @@ public class TestImageProviderTests public TestImageProviderTests(ITestOutputHelper output) => this.Output = output; - public static string[] AllBmpFiles { get; } = { TestImages.Bmp.F, TestImages.Bmp.Bit8 }; + public static string[] AllBmpFiles { get; } = [TestImages.Bmp.F, TestImages.Bmp.Bit8]; private ITestOutputHelper Output { get; } - public static Image CreateTestImage() - where TPixel : unmanaged, IPixel => - new Image(3, 3); + public static Image CreateTestImage() where TPixel : unmanaged, IPixel => new(3, 3); [Theory] [MemberData(nameof(BasicData))] @@ -77,7 +75,7 @@ public void GetImage_WithCustomParameterlessDecoder_ShouldUtilizeCache( { string testName = nameof(this.GetImage_WithCustomParameterlessDecoder_ShouldUtilizeCache); - var decoder = new TestDecoder(); + TestDecoder decoder = new(); decoder.InitCaller(testName); provider.GetImage(decoder); @@ -339,7 +337,7 @@ private static void EnsureCustomConfigurationIsApplied(TestImageProvider { using (provider.GetImage()) { - var customConfiguration = Configuration.CreateDefaultInstance(); + Configuration customConfiguration = Configuration.CreateDefaultInstance(); provider.Configuration = customConfiguration; using (Image image2 = provider.GetImage()) @@ -372,7 +370,7 @@ protected override ImageInfo Identify(DecoderOptions options, Stream stream, Can { using Image image = this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); ImageMetadata metadata = image.Metadata; - return new(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) + return new ImageInfo(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) { PixelType = metadata.GetDecodedPixelTypeInfo() }; @@ -419,7 +417,7 @@ protected override ImageInfo Identify(DecoderOptions options, Stream stream, Can { using Image image = this.Decode(this.CreateDefaultSpecializedOptions(options), stream, cancellationToken); ImageMetadata metadata = image.Metadata; - return new(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) + return new ImageInfo(image.Size, metadata, new List(image.Frames.Select(x => x.Metadata))) { PixelType = metadata.GetDecodedPixelTypeInfo() }; diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 41597be7..212cf6fe 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -19,7 +19,7 @@ public TestUtilityExtensionsTests(ITestOutputHelper output) public static Image CreateTestImage() where TPixel : unmanaged, IPixel { - var image = new Image(10, 10); + Image image = new(10, 10); Buffer2D pixels = image.GetRootFramePixelBuffer(); for (int i = 0; i < 10; i++) diff --git a/tests/ImageSharp.Drawing.Tests/Utilities/ThreadLocalBlenderBuffersTests.cs b/tests/ImageSharp.Drawing.Tests/Utilities/ThreadLocalBlenderBuffersTests.cs index 25d68925..42d7e598 100644 --- a/tests/ImageSharp.Drawing.Tests/Utilities/ThreadLocalBlenderBuffersTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Utilities/ThreadLocalBlenderBuffersTests.cs @@ -8,16 +8,16 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Drawing.Utils; public class ThreadLocalBlenderBuffersTests { - private readonly TestMemoryAllocator memoryAllocator = new TestMemoryAllocator(); + private readonly TestMemoryAllocator memoryAllocator = new(); [Fact] public void CreatesPerThreadUniqueInstances() { - using var buffers = new ThreadLocalBlenderBuffers(this.memoryAllocator, 100); + using ThreadLocalBlenderBuffers buffers = new(this.memoryAllocator, 100); - var allSetSemaphore = new SemaphoreSlim(2); + SemaphoreSlim allSetSemaphore = new(2); - var thread1 = new Thread(() => + Thread thread1 = new(() => { Span ams = buffers.AmountSpan; Span overlays = buffers.OverlaySpan; @@ -32,7 +32,7 @@ public void CreatesPerThreadUniqueInstances() Assert.Equal(10, buffers.OverlaySpan[0].R); }); - var thread2 = new Thread(() => + Thread thread2 = new(() => { Span ams = buffers.AmountSpan; Span overlays = buffers.OverlaySpan; @@ -60,7 +60,7 @@ public void CreatesPerThreadUniqueInstances() [InlineData(true, 3)] public void Dispose_ReturnsAllBuffers(bool amountBufferOnly, int threadCount) { - var buffers = new ThreadLocalBlenderBuffers(this.memoryAllocator, 100, amountBufferOnly); + ThreadLocalBlenderBuffers buffers = new(this.memoryAllocator, 100, amountBufferOnly); void RunThread() {