From 53a39ddb866abff6f39e95bd2753f7ed356ae2f1 Mon Sep 17 00:00:00 2001 From: Renan Alvarenga Date: Thu, 29 Feb 2024 10:49:27 +1100 Subject: [PATCH] Addressed new comments --- src/Blazor.Diagrams.Core/Models/PortModel.cs | 16 ++++---- .../Models/PortModelTest.cs | 37 +------------------ 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Models/PortModel.cs b/src/Blazor.Diagrams.Core/Models/PortModel.cs index 4513fe04..ef206856 100644 --- a/src/Blazor.Diagrams.Core/Models/PortModel.cs +++ b/src/Blazor.Diagrams.Core/Models/PortModel.cs @@ -68,33 +68,33 @@ public virtual bool CanAttachTo(ILinkable other) void ILinkable.RemoveLink(BaseLinkModel link) => _links.Remove(link); - public virtual void SetPortPositionOnNodeSizeChanged(double deltaX, double deltaY) + public virtual void SetPortPositionOnNodeSizeChanged(double deltaWidth, double deltaHeight) { switch (Alignment) { case PortAlignment.Top: - Position = new Point(Position.X + deltaX / 2, Position.Y); + Position = new Point(Position.X + deltaWidth / 2, Position.Y); break; case PortAlignment.TopRight: - Position = new Point(Position.X + deltaX, Position.Y); + Position = new Point(Position.X + deltaWidth, Position.Y); break; case PortAlignment.TopLeft: Position = new Point(Position.X, Position.Y); break; case PortAlignment.Right: - Position = new Point(Position.X + deltaX, Position.Y + deltaY / 2); + Position = new Point(Position.X + deltaWidth, Position.Y + deltaHeight / 2); break; case PortAlignment.Left: - Position = new Point(Position.X, Position.Y + deltaY / 2); + Position = new Point(Position.X, Position.Y + deltaHeight / 2); break; case PortAlignment.Bottom: - Position = new Point(Position.X + deltaX / 2, Position.Y + deltaY); + Position = new Point(Position.X + deltaWidth / 2, Position.Y + deltaHeight); break; case PortAlignment.BottomRight: - Position = new Point(Position.X + deltaX, Position.Y + deltaY); + Position = new Point(Position.X + deltaWidth, Position.Y + deltaHeight); break; case PortAlignment.BottomLeft: - Position = new Point(Position.X, Position.Y + deltaY); + Position = new Point(Position.X, Position.Y + deltaHeight); break; default: Position = new Point(Position.X, Position.Y); diff --git a/tests/Blazor.Diagrams.Core.Tests/Models/PortModelTest.cs b/tests/Blazor.Diagrams.Core.Tests/Models/PortModelTest.cs index abce812e..d4dc57bf 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Models/PortModelTest.cs +++ b/tests/Blazor.Diagrams.Core.Tests/Models/PortModelTest.cs @@ -26,41 +26,8 @@ public void SetPortPositionOnNodeSizeChangedCalculatesCorrectPosition(PortAlignm port.SetPortPositionOnNodeSizeChanged(100, 100); // Assert - switch (alignment) - { - case PortAlignment.Top: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.TopRight: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.TopLeft: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.Right: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.Left: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.Bottom: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.BottomRight: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - case PortAlignment.BottomLeft: - Assert.Equal(expectedXPosition, port.Position.X); - Assert.Equal(expectedYPosition, port.Position.Y); - break; - } + Assert.Equal(expectedXPosition, port.Position.X); + Assert.Equal(expectedYPosition, port.Position.Y); } } }