Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Mar 31, 2024
1 parent 0a1f862 commit 147dcf3
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string Stroke
}
}

public HashSet<Connector> RelatedConnectors { get; } = new();
public HashSet<Connector> RelatedConnectors { get; } = [];

public override void HandlePointerMove(PointerEventArgs eventArgs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void AddNew(SVGEditor SVG, Shape parent)
AnimateD animate = new(element, parent, SVG)
{
AttributeName = "d",
Values = new(),
Values = [],
Begin = 0,
Dur = 5,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void AddNew(SVGEditor SVG, Shape parent)
AnimateFill animate = new(element, parent, SVG)
{
AttributeName = "fill",
Values = new(),
Values = [],
Begin = 0,
Dur = 5,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void AddNew(SVGEditor SVG, Shape parent)
AnimateStroke animate = new(element, parent, SVG)
{
AttributeName = "stroke",
Values = new(),
Values = [],
Begin = 0,
Dur = 5,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void AddNew(SVGEditor SVG, Shape parent)
AnimateStrokeDashoffset animate = new(element, parent, SVG)
{
AttributeName = "stroke-dashoffset",
Values = new(),
Values = [],
Begin = 0,
Dur = 5,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void UpdateValues()

public static List<string> StringToValues(string attribute)
{
return attribute == null ? new List<string>() : attribute.Split(";").Select(e => e.Trim()).ToList();
return attribute == null ? [] : attribute.Split(";").Select(e => e.Trim()).ToList();
}

private static string ValuesToString(List<string> values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ internal static double ParseAsDouble(this string s)
try
{
return string.IsNullOrWhiteSpace(points)
? new()
? []
: points.Trim().Split(" ").Select(p => (x: p.Split(",")[0].ParseAsDouble(), y: p.Split(",")[1].ParseAsDouble())).ToList();
}
catch (Exception)
{
return new();
return [];
}
}
internal static string ToUrl(this string id)
Expand Down
2 changes: 1 addition & 1 deletion src/KristofferStrube.Blazor.SVGEditor/Gradients/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void UpdateInput(ISVGElement child)

public SVGEditor SVG { get; init; }

public List<ISVGElement> Children { get; init; } = new();
public List<ISVGElement> Children { get; init; } = [];

public Type Presenter => typeof(DefsPresenter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public BaseControlPointPathInstruction(bool Relative, IPathInstruction PreviousI
{
UpdateReflectedPreviousInstructionsLastControlPoint();
}
public List<(double x, double y)> ControlPoints { get; set; } = new();
public List<(double x, double y)> ControlPoints { get; set; } = [];
public override List<(double x, double y)> SelectionPoints => base.SelectionPoints.Concat(ControlPoints).ToList();

public (double x, double y) ReflectedPreviousInstructionsLastControlPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public BasePathInstruction(bool Relative, IPathInstruction? PreviousInstruction)
public bool ExplicitSymbol { get; set; } = true;
public (double x, double y) StartPosition => PreviousInstruction is not null ? PreviousInstruction.EndPosition : (0, 0);
public abstract (double x, double y) EndPosition { get; set; }
public virtual List<(double x, double y)> SelectionPoints => new() { StartPosition };
public virtual List<(double x, double y)> SelectionPoints => [StartPosition];
public abstract string AbsoluteInstruction { get; }
public abstract string RelativeInstruction { get; }
public abstract override string ToString();
Expand Down
22 changes: 11 additions & 11 deletions src/KristofferStrube.Blazor.SVGEditor/SVGEditor.razor.Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public partial class SVGEditor
public bool DisableScaleLabel { get; set; }

[Parameter]
public List<CompleteNewShapeMenuItem> CompleteNewShapeMenuItems { get; set; } = new() {
public List<CompleteNewShapeMenuItem> CompleteNewShapeMenuItems { get; set; } = [
new(typeof(CompleteWithoutCloseMenuItem), (svgEditor) => svgEditor.SelectedShapes[0] is Path),
new(typeof(RemoveLastInstruction), (svgEditor) => svgEditor.SelectedShapes[0] is Path),
};
];

[Parameter]
public List<SupportedAddNewSVGElementMenuItem> AddNewSVGElementMenuItems { get; set; } = new() {
public List<SupportedAddNewSVGElementMenuItem> AddNewSVGElementMenuItems { get; set; } = [
new(typeof(AddNewStopFromLinearGradientMenuItem), (svgEditor, data) => data is LinearGradient),
new(typeof(AddNewStopFromStopMenuItem), (svgEditor, data) => data is Stop),
new(typeof(AddNewPathMenuItem), (_, data) => data is not (LinearGradient or Stop)),
Expand All @@ -83,10 +83,10 @@ public partial class SVGEditor
new(typeof(AddNewTextMenuItem), (_, data) => data is not (LinearGradient or Stop)),
new(typeof(AddNewGradientMenuItem), (_, data) => data is not (LinearGradient or Stop)),
new(typeof(AddNewAnimationMenuItem), (_, data) => data is Shape shape && !shape.IsChildElement && !shape.AnimationElements.Any(a => a.AttributeName is "fill" or "stroke" or "d")),
};
];

[Parameter]
public List<ActionMenuItem> ActionMenuItems { get; set; } = new() {
public List<ActionMenuItem> ActionMenuItems { get; set; } = [
new(typeof(FillMenuItem), (_, data) => data is Shape shape && !shape.IsChildElement),
new(typeof(StrokeMenuItem), (_, data) => data is Shape shape && !shape.IsChildElement),
new(typeof(TextMenuItem), (_, data) => data is Text text && !text.IsChildElement),
Expand All @@ -99,10 +99,10 @@ public partial class SVGEditor
new(typeof(CopyMenuItem), (svgEditor, data) => data is Shape && !svgEditor.DisableCopyElement),
new(typeof(PasteMenuItem), (svgEditor, _) => !svgEditor.DisablePasteElement),
new(typeof(OptimizeMenuItem), (_, data) => data is Shape shape && !shape.IsChildElement),
};
];

[Parameter]
public List<SupportedElement> SupportedElements { get; set; } = new() {
public List<SupportedElement> SupportedElements { get; set; } = [
new(typeof(Rect), (IElement element) => element.TagName.ToUpper() == "RECT"),
new(typeof(Circle), (IElement element) => element.TagName.ToUpper() == "CIRCLE"),
new(typeof(Ellipse), (IElement element) => element.TagName.ToUpper() == "ELLIPSE"),
Expand All @@ -113,16 +113,16 @@ public partial class SVGEditor
new(typeof(Text), (IElement element) => element.TagName.ToUpper() == "TEXT"),
new(typeof(G), (IElement element) => element.TagName.ToUpper() == "G"),
new(typeof(Defs), (IElement element) => element.TagName.ToUpper() == "DEFS"),
};
];

[Parameter]
public List<SupportedAnimation> AnimationTypes { get; set; } = new()
{
public List<SupportedAnimation> AnimationTypes { get; set; } =
[
new(typeof(AnimateFill), "fill"),
new(typeof(AnimateStroke), "stroke"),
new(typeof(AnimateStrokeDashoffset), "stroke-dashoffset"),
new(typeof(AnimateD), "d"),
};
];

public void DisableAllInteractions()
{
Expand Down
6 changes: 3 additions & 3 deletions src/KristofferStrube.Blazor.SVGEditor/SVGEditor.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public bool ShouldShowContextMenu(object? data)

public List<ISVGElement> Elements { get; protected set; } = default!;

public List<Shape> SelectedShapes { get; set; } = new();
public List<Shape> SelectedShapes { get; set; } = [];

public Dictionary<string, ISVGElement> Definitions { get; set; } = new();
public Dictionary<string, ISVGElement> Definitions { get; set; } = [];

public ISVGElement? EditGradient { get; set; }

public Shape? FocusedShape { get; set; }

public List<Shape> MoveOverShapes { get; set; } = new();
public List<Shape> MoveOverShapes { get; set; } = [];

public (double x, double y) MovePanner { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/KristofferStrube.Blazor.SVGEditor/Shapes/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public double R
set { Element.SetAttribute("r", value.AsString()); Changed?.Invoke(this); }
}

public override List<(double x, double y)> SelectionPoints => new() { (Cx + R, Cy + R), (Cx + R, Cy - R), (Cx - R, Cy + R), (Cx - R, Cy - R) };
public override List<(double x, double y)> SelectionPoints => [(Cx + R, Cy + R), (Cx + R, Cy - R), (Cx - R, Cy + R), (Cx - R, Cy - R)];

public override void HandlePointerMove(PointerEventArgs eventArgs)
{
Expand Down
2 changes: 1 addition & 1 deletion src/KristofferStrube.Blazor.SVGEditor/Shapes/Ellipse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public double Ry
set { Element.SetAttribute("ry", value.AsString()); Changed?.Invoke(this); }
}

public override List<(double x, double y)> SelectionPoints => new() { (Cx + Rx, Cy + Ry), (Cx + Rx, Cy - Ry), (Cx - Rx, Cy + Ry), (Cx - Rx, Cy - Ry) };
public override List<(double x, double y)> SelectionPoints => [(Cx + Rx, Cy + Ry), (Cx + Rx, Cy - Ry), (Cx - Rx, Cy + Ry), (Cx - Rx, Cy - Ry)];

private double _r;

Expand Down
2 changes: 1 addition & 1 deletion src/KristofferStrube.Blazor.SVGEditor/Shapes/G.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void UpdateInput(ISVGElement child)

public override string StateRepresentation => string.Join("-", ChildShapes.Select(c => c.StateRepresentation)) + string.Join("-", Element.Attributes.Select(a => a.Value)) + Selected.ToString() + SVG.EditMode.ToString() + SVG.Scale + SVG.Translate.x + SVG.Translate.y + Serialize(BoundingBox);

public List<Shape> ChildShapes { get; set; } = new List<Shape>();
public List<Shape> ChildShapes { get; set; } = [];

public override IEnumerable<(double x, double y)> SelectionPoints => ChildShapes.SelectMany(child => child.SelectionPoints);

Expand Down
2 changes: 1 addition & 1 deletion src/KristofferStrube.Blazor.SVGEditor/Shapes/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public double Y2
set { Element.SetAttribute("y2", value.AsString()); Changed?.Invoke(this); }
}

public override List<(double x, double y)> SelectionPoints => new() { (X1, Y1), (X2, Y2) };
public override List<(double x, double y)> SelectionPoints => [(X1, Y1), (X2, Y2)];

public override void HandlePointerMove(PointerEventArgs eventArgs)
{
Expand Down
2 changes: 1 addition & 1 deletion src/KristofferStrube.Blazor.SVGEditor/Shapes/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public double Height

private (double x, double y)? AddPos { get; set; }

public override List<(double x, double y)> SelectionPoints => new() { (X, Y), (X + Width, Y), (X + Width, Y + Height), (X, Y + Height) };
public override List<(double x, double y)> SelectionPoints => [(X, Y), (X + Width, Y), (X + Width, Y + Height), (X, Y + Height)];

public override void HandlePointerMove(PointerEventArgs eventArgs)
{
Expand Down
4 changes: 2 additions & 2 deletions src/KristofferStrube.Blazor.SVGEditor/Shapes/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Text(IElement element, SVGEditor svg) : base(element, svg)
{
string? style = element.GetAttribute("style");
styleAttributes = style is null
? (Dictionary<string, string>)new()
? (Dictionary<string, string>)[]
: style
.Split(";")
.Select(style => style.Split(":"))
Expand Down Expand Up @@ -77,7 +77,7 @@ public void UpdateStyle()

public override Type Presenter => typeof(TextEditor);

public override List<(double x, double y)> SelectionPoints => new() { (BoundingBox.X, BoundingBox.Y), (BoundingBox.X + BoundingBox.Width, BoundingBox.Y), (BoundingBox.X + BoundingBox.Width, BoundingBox.Y + BoundingBox.Height), (BoundingBox.X, BoundingBox.Y + BoundingBox.Height) };
public override List<(double x, double y)> SelectionPoints => [(BoundingBox.X, BoundingBox.Y), (BoundingBox.X + BoundingBox.Width, BoundingBox.Y), (BoundingBox.X + BoundingBox.Width, BoundingBox.Y + BoundingBox.Height), (BoundingBox.X, BoundingBox.Y + BoundingBox.Height)];

public override void HandlePointerMove(PointerEventArgs eventArgs)
{
Expand Down

0 comments on commit 147dcf3

Please sign in to comment.