From 9ab90fd3627987915cf817648153cb2c7c13140f Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Fri, 2 Oct 2026 18:20:48 +0200 Subject: [PATCH 01/22] Radius-Fehlermeldungen vereinheitlicht MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In `Circle.vb` wurden die `ArgumentException`-Meldungen mehrerer `Shared`-Methoden sprachlich vereinheitlicht: „Radius darf nicht negativ sein.“ wurde zu „Der Radius darf nicht negativ sein.“ geändert. --- Geometry/TwoDimensional/Circle.vb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index f76f037..a393e0f 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -27,7 +27,7 @@ Namespace TwoDimensional ''' Fläche = π * r^2 Public Shared Function Area(r As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Return Math.PI * r * r End Function @@ -48,7 +48,7 @@ Namespace TwoDimensional ''' Umfang = 2 * π * r Public Shared Function Circumference(r As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Return 2.0 * Math.PI * r End Function @@ -69,7 +69,7 @@ Namespace TwoDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(r As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Return 2.0 * r End Function @@ -96,7 +96,7 @@ Namespace TwoDimensional ''' Bogenlänge = r * angle Public Shared Function ArcLength(r As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Return r * angleRadians End Function @@ -120,7 +120,7 @@ Namespace TwoDimensional ''' Sektorfläche = 0.5 * r^2 * angle Public Shared Function SectorArea(r As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Return 0.5 * r * r * angleRadians End Function @@ -144,7 +144,7 @@ Namespace TwoDimensional ''' Sehnenlänge = 2 * r * sin(angle/2) Public Shared Function ChordLength(r As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Return 2.0 * r * Math.Sin(angleRadians / 2.0) End Function @@ -156,7 +156,7 @@ Namespace TwoDimensional ''' Sehnenlänge Public Shared Function ChordLengthFromSagitta(r As Double, sagitta As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) If sagitta < 0 Or sagitta > r Then Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) ' Abstand vom Mittelpunkt zur Sehne (h) = r - sagitta @@ -206,7 +206,7 @@ Namespace TwoDimensional ''' PointF mit Koordinaten des Punktes Public Shared Function PointOnCircle(cx As Double, cy As Double, r As Double, angleRadians As Double) As PointF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Dim x As Single = CSng(cx + (r * Math.Cos(angleRadians))) Dim y As Single = CSng(cy + (r * Math.Sin(angleRadians))) Return New PointF(x, y) @@ -221,7 +221,7 @@ Namespace TwoDimensional ''' Achsenparalleles BoundingBox-Rechteck Public Shared Function BoundingBox(cx As Double, cy As Double, r As Double) As RectangleF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) Dim x As Single = CSng(cx - r) Dim y As Single = CSng(cy - r) Dim size As Single = CSng(2.0 * r) From 409a07d0e69b5f54b24e63f7b274cbb8951df6e6 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:27:21 +0200 Subject: [PATCH 02/22] Radius-Validierung zentralisiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue Ressource `RadiusIsNegative` und `Messages.vb` in `Geometry.vbproj` ergänzt; negative Radiusprüfungen in `Circle`, `Cone`, `Cylinder` und `Sphere` auf die zentrale lokalisierbare Fehlermeldung umgestellt; kleines Formatdetail in `Sphere` angepasst. --- Geometry/Geometry.vbproj | 1 + Geometry/Messages.vb | 8 ++++ Geometry/My Project/Resources.Designer.vb | 45 ++++++++++++++--------- Geometry/My Project/Resources.resx | 16 +++++--- Geometry/ThreeDimensional/Cone.vb | 12 +++--- Geometry/ThreeDimensional/Cylinder.vb | 14 +++---- Geometry/ThreeDimensional/Sphere.vb | 13 ++++--- Geometry/TwoDimensional/Circle.vb | 18 ++++----- 8 files changed, 76 insertions(+), 51 deletions(-) create mode 100644 Geometry/Messages.vb diff --git a/Geometry/Geometry.vbproj b/Geometry/Geometry.vbproj index 29a0973..1d80af6 100644 --- a/Geometry/Geometry.vbproj +++ b/Geometry/Geometry.vbproj @@ -75,6 +75,7 @@ + diff --git a/Geometry/Messages.vb b/Geometry/Messages.vb new file mode 100644 index 0000000..00b755c --- /dev/null +++ b/Geometry/Messages.vb @@ -0,0 +1,8 @@ +Friend Class Messages + + Public Shared Sub RadiusIsNegative(ParameterName As String) + Dim message As String = My.Resources.RadiusIsNegative + Throw New ArgumentException(message, ParameterName) + End Sub + +End Class diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 6fc80ea..26a6774 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -14,28 +14,28 @@ Option Explicit On Imports System Namespace My.Resources - + 'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert '-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. 'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen 'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - ''' + ''' ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - ''' - + ''' + _ Friend Module Resources - + Private resourceMan As Global.System.Resources.ResourceManager - + Private resourceCulture As Global.System.Globalization.CultureInfo - - ''' + + ''' ''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - ''' - + ''' + _ Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then @@ -45,19 +45,28 @@ Namespace My.Resources Return resourceMan End Get End Property - - ''' + + ''' ''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle ''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - ''' - + ''' + _ Friend Property Culture() As Global.System.Globalization.CultureInfo Get Return resourceCulture End Get Set - resourceCulture = Value + resourceCulture = value End Set End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property RadiusIsNegative() As String + Get + Return ResourceManager.GetString("RadiusIsNegative", resourceCulture) + End Get + End Property End Module End Namespace diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index af7dbeb..2a0fcd9 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,12 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Der Radius darf nicht negativ sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index d01d1f2..56d056a 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -26,7 +26,7 @@ Namespace ThreeDimensional ''' Volumen (PI * r^2 * h) / 3 Public Shared Function Volume(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * radius * radius * height) / 3.0 @@ -41,7 +41,7 @@ Namespace ThreeDimensional ''' Schräghöhe sqrt(r^2 + h^2) Public Shared Function SlantHeight(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) Return Math.Sqrt((radius * radius) + (height * height)) End Function @@ -54,7 +54,7 @@ Namespace ThreeDimensional ''' Mantelfläche PI * r * s Public Shared Function LateralArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) Return Math.PI * radius * SlantHeight(radius, height) End Function @@ -67,7 +67,7 @@ Namespace ThreeDimensional ''' Oberfläche PI * r * (r + s) Public Shared Function SurfaceArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) Dim s = SlantHeight(radius, height) Return Math.PI * radius * (radius + s) @@ -80,7 +80,7 @@ Namespace ThreeDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return 2.0 * radius End Function @@ -163,7 +163,7 @@ Namespace ThreeDimensional ''' 3D-Punkt als Tuple(X,Y,Z) Public Shared Function PointOnLateralSurface(centerX As Double, centerY As Double, baseZ As Double, radius As Double, height As Double, angleRadians As Double, t As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) If t < 0 OrElse t > 1 Then Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index cb4186c..5e35c76 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -26,7 +26,7 @@ Namespace ThreeDimensional ''' Volumen PI * r^2 * h Public Shared Function Volume(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) Return Math.PI * radius * radius * height End Function @@ -39,7 +39,7 @@ Namespace ThreeDimensional ''' Mantelfläche 2 * PI * r * h Public Shared Function LateralArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) Return 2.0 * Math.PI * radius * height End Function @@ -52,7 +52,7 @@ Namespace ThreeDimensional ''' Oberfläche 2*PI*r*(r+h) Public Shared Function SurfaceArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) Return 2.0 * Math.PI * radius * (radius + height) End Function @@ -64,7 +64,7 @@ Namespace ThreeDimensional ''' 2 * PI * r Public Shared Function BaseCircumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return 2.0 * Math.PI * radius End Function @@ -75,7 +75,7 @@ Namespace ThreeDimensional ''' PI * r^2 Public Shared Function BaseArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return Math.PI * radius * radius End Function @@ -86,7 +86,7 @@ Namespace ThreeDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return 2.0 * radius End Function @@ -154,7 +154,7 @@ Namespace ThreeDimensional ''' 3D-Koordinate als Tuple(X, Y, Z) Public Shared Function PointOnLateralSurface(centerX As Double, centerY As Double, baseZ As Double, radius As Double, height As Double, angleRadians As Double, heightOffset As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) If heightOffset < 0 OrElse heightOffset > height Then Throw New ArgumentException("Höhenoffset muss im Bereich 0 bis Höhe liegen.", NameOf(heightOffset)) diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 6cfe1bb..6bdf76c 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -25,7 +25,8 @@ Namespace ThreeDimensional ''' Volumen 4/3 * PI * r^3 Public Shared Function Volume(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3) #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -38,7 +39,7 @@ Namespace ThreeDimensional ''' Oberfläche 4 * PI * r^2 Public Shared Function SurfaceArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return 4.0 * Math.PI * radius * radius End Function @@ -49,7 +50,7 @@ Namespace ThreeDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return 2.0 * radius End Function @@ -71,7 +72,7 @@ Namespace ThreeDimensional ''' Umfang 2 * PI * r Public Shared Function GreatCircleCircumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return 2.0 * Math.PI * radius End Function @@ -82,7 +83,7 @@ Namespace ThreeDimensional ''' Fläche PI * r^2 Public Shared Function GreatCircleArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) Return Math.PI * radius * radius End Function @@ -130,7 +131,7 @@ Namespace ThreeDimensional ''' 3D-Koordinate als Tuple(X, Y, Z) Public Shared Function PointOnSphere(centerX As Double, centerY As Double, centerZ As Double, radius As Double, polarAngleRadians As Double, azimuthRadians As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(radius)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) If polarAngleRadians < 0 OrElse polarAngleRadians > Math.PI Then Throw New ArgumentException("Der Polarwinkel muss im Bereich 0 bis PI liegen.", NameOf(polarAngleRadians)) End If diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index a393e0f..feca991 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -27,7 +27,7 @@ Namespace TwoDimensional ''' Fläche = π * r^2 Public Shared Function Area(r As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Return Math.PI * r * r End Function @@ -48,7 +48,7 @@ Namespace TwoDimensional ''' Umfang = 2 * π * r Public Shared Function Circumference(r As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Return 2.0 * Math.PI * r End Function @@ -69,7 +69,7 @@ Namespace TwoDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(r As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Return 2.0 * r End Function @@ -96,7 +96,7 @@ Namespace TwoDimensional ''' Bogenlänge = r * angle Public Shared Function ArcLength(r As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Return r * angleRadians End Function @@ -120,7 +120,7 @@ Namespace TwoDimensional ''' Sektorfläche = 0.5 * r^2 * angle Public Shared Function SectorArea(r As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Return 0.5 * r * r * angleRadians End Function @@ -144,7 +144,7 @@ Namespace TwoDimensional ''' Sehnenlänge = 2 * r * sin(angle/2) Public Shared Function ChordLength(r As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Return 2.0 * r * Math.Sin(angleRadians / 2.0) End Function @@ -156,7 +156,7 @@ Namespace TwoDimensional ''' Sehnenlänge Public Shared Function ChordLengthFromSagitta(r As Double, sagitta As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) If sagitta < 0 Or sagitta > r Then Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) ' Abstand vom Mittelpunkt zur Sehne (h) = r - sagitta @@ -206,7 +206,7 @@ Namespace TwoDimensional ''' PointF mit Koordinaten des Punktes Public Shared Function PointOnCircle(cx As Double, cy As Double, r As Double, angleRadians As Double) As PointF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Dim x As Single = CSng(cx + (r * Math.Cos(angleRadians))) Dim y As Single = CSng(cy + (r * Math.Sin(angleRadians))) Return New PointF(x, y) @@ -221,7 +221,7 @@ Namespace TwoDimensional ''' Achsenparalleles BoundingBox-Rechteck Public Shared Function BoundingBox(cx As Double, cy As Double, r As Double) As RectangleF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Throw New ArgumentException("Der Radius darf nicht negativ sein.", NameOf(r)) + If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) Dim x As Single = CSng(cx - r) Dim y As Single = CSng(cy - r) Dim size As Single = CSng(2.0 * r) From 629d89b14016f76acd777f890d90df90b5b2a4c6 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:20:44 +0200 Subject: [PATCH 03/22] =?UTF-8?q?Circle-Parameter=20umbenannt,=20Version?= =?UTF-8?q?=20erh=C3=B6ht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AssemblyInfo.vb: System.Runtime.InteropServices importiert und AssemblyVersion/AssemblyFileVersion auf 1.2026.1002.1 erhöht. Circle.vb: Parameter r konsistent in radius umbenannt, XML-Kommentare und abhängige Hilfsmethoden angepasst; RadiusFromDiameter meldet nun präziser, dass der Durchmesser nicht negativ sein darf. --- Geometry/My Project/AssemblyInfo.vb | 4 +- Geometry/TwoDimensional/Circle.vb | 130 ++++++++++++++-------------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index f58d255..9a3e336 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index feca991..cc379a1 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -23,12 +23,12 @@ Namespace TwoDimensional ''' ''' Berechnet die Fläche eines Kreises aus dem Radius. ''' - ''' Radius (>= 0) - ''' Fläche = π * r^2 - Public Shared Function Area(r As Double) As Double + ''' Radius (>= 0) + ''' Fläche = π * radius^2 + Public Shared Function Area(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Return Math.PI * r * r + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Return Math.PI * radius * radius End Function ''' @@ -44,12 +44,12 @@ Namespace TwoDimensional ''' ''' Berechnet den Umfang (Kreisumfang) aus dem Radius. ''' - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Umfang = 2 * π * r - Public Shared Function Circumference(r As Double) As Double + Public Shared Function Circumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Return 2.0 * Math.PI * r + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Return 2.0 * Math.PI * radius End Function ''' @@ -65,12 +65,12 @@ Namespace TwoDimensional ''' ''' Konvertiert Radius in Durchmesser. ''' - ''' Radius (>= 0) - ''' Durchmesser 2 * r - Public Shared Function DiameterFromRadius(r As Double) As Double + ''' Radius (>= 0) + ''' Durchmesser 2 * radius + Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Return 2.0 * r + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Return 2.0 * radius End Function ''' @@ -80,7 +80,7 @@ Namespace TwoDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(d As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If d < 0 Then Throw New ArgumentException("Durchmesser darf nicht negativ sein.", NameOf(d)) + If d < 0 Then Throw New ArgumentException("Der Durchmesser darf nicht negativ sein.", NameOf(d)) Return d / 2.0 End Function @@ -91,105 +91,105 @@ Namespace TwoDimensional ''' ''' Berechnet die Bogenlänge für einen gegebenen Zentralwinkel (im Bogenmaß). ''' - ''' Radius + ''' Radius ''' Winkel in Bogenmaß - ''' Bogenlänge = r * angle - Public Shared Function ArcLength(r As Double, angleRadians As Double) As Double + ''' Bogenlänge = radius * angle + Public Shared Function ArcLength(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Return r * angleRadians + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Return radius * angleRadians End Function ''' ''' Berechnet die Bogenlänge für einen Winkel in Grad. ''' - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Winkel in Grad ''' Bogenlänge - Public Shared Function ArcLengthDegrees(r As Double, angleDegrees As Double) As Double + Public Shared Function ArcLengthDegrees(radius As Double, angleDegrees As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. Dim rad As Double = angleDegrees * Math.PI / 180.0 - Return ArcLength(r, rad) + Return ArcLength(radius, rad) End Function ''' ''' Berechnet die Fläche eines Kreissektors für einen gegebenen Zentralwinkel (Bogenmaß). ''' - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Winkel in Bogenmaß - ''' Sektorfläche = 0.5 * r^2 * angle - Public Shared Function SectorArea(r As Double, angleRadians As Double) As Double + ''' Sektorfläche = 0.5 * radius^2 * angle + Public Shared Function SectorArea(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Return 0.5 * r * r * angleRadians + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Return 0.5 * radius * radius * angleRadians End Function ''' ''' Sektorfläche für Winkel in Grad. ''' - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Winkel in Grad ''' Sektorfläche - Public Shared Function SectorAreaDegrees(r As Double, angleDegrees As Double) As Double + Public Shared Function SectorAreaDegrees(radius As Double, angleDegrees As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. Dim rad As Double = angleDegrees * Math.PI / 180.0 - Return SectorArea(r, rad) + Return SectorArea(radius, rad) End Function ''' ''' Berechnet die Länge einer Sehne für einen gegebenen Zentralwinkel (Bogenmaß). ''' - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Winkel in Bogenmaß - ''' Sehnenlänge = 2 * r * sin(angle/2) - Public Shared Function ChordLength(r As Double, angleRadians As Double) As Double + ''' Sehnenlänge = 2 * radius * sin(angle/2) + Public Shared Function ChordLength(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Return 2.0 * r * Math.Sin(angleRadians / 2.0) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Return 2.0 * radius * Math.Sin(angleRadians / 2.0) End Function ''' ''' Berechnet die Sehnenlänge aus der Sehnenhöhe (Sagitta). ''' - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Sehnenhöhe (Abstand von Kreisrand zur Sehnenmitte) ''' Sehnenlänge - Public Shared Function ChordLengthFromSagitta(r As Double, sagitta As Double) As Double + Public Shared Function ChordLengthFromSagitta(radius As Double, sagitta As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - If sagitta < 0 Or sagitta > r Then Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If sagitta < 0 Or sagitta > radius Then Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) - ' Abstand vom Mittelpunkt zur Sehne (h) = r - sagitta - Dim h As Double = r - sagitta - ' Halbe Sehnenlänge = sqrt(r^2 - h^2) - Dim half As Double = Math.Sqrt((r * r) - (h * h)) + ' Abstand vom Mittelpunkt zur Sehne (h) = radius - sagitta + Dim h As Double = radius - sagitta + ' Halbe Sehnenlänge = sqrt(radius^2 - h^2) + Dim half As Double = Math.Sqrt((radius * radius) - (h * h)) Return 2.0 * half End Function ''' ''' Berechnet den Zentralwinkel (Bogenmaß) aus Bogenlänge. ''' - ''' Radius (> 0) + ''' Radius (> 0) ''' Bogenlänge ''' Zentralwinkel im Bogenmaß - Public Shared Function AngleFromArcLength(r As Double, arcLength As Double) As Double + Public Shared Function AngleFromArcLength(radius As Double, arcLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r <= 0 Then Throw New ArgumentException("Radius muss > 0 sein.", NameOf(r)) - Return arcLength / r + If radius <= 0 Then Throw New ArgumentException("Radius muss > 0 sein.", NameOf(radius)) + Return arcLength / radius End Function ''' ''' Berechnet den Zentralwinkel (Bogenmaß) aus Sehnenlänge. ''' - ''' Radius (> 0) + ''' Radius (> 0) ''' Sehnenlänge ''' Zentralwinkel im Bogenmaß - Public Shared Function AngleFromChordLength(r As Double, chordLength As Double) As Double + Public Shared Function AngleFromChordLength(radius As Double, chordLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r <= 0 Then Throw New ArgumentException("Radius muss > 0 sein.", NameOf(r)) - If chordLength < 0 OrElse chordLength > 2.0 * r Then Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) - ' chord = 2 r sin(theta/2) => theta = 2 * asin(chord/(2r)) - Return 2.0 * Math.Asin(chordLength / (2.0 * r)) + If radius <= 0 Then Throw New ArgumentException("Radius muss > 0 sein.", NameOf(radius)) + If chordLength < 0 OrElse chordLength > 2.0 * radius Then Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) + ' chord = 2 radius sin(theta/2) => theta = 2 * asin(chord/(2*radius)) + Return 2.0 * Math.Asin(chordLength / (2.0 * radius)) End Function #End Region @@ -201,14 +201,14 @@ Namespace TwoDimensional ''' ''' Mittelpunkt X ''' Mittelpunkt Y - ''' Radius + ''' Radius ''' Winkel im Bogenmaß (0 = rechts) ''' PointF mit Koordinaten des Punktes - Public Shared Function PointOnCircle(cx As Double, cy As Double, r As Double, angleRadians As Double) As PointF + Public Shared Function PointOnCircle(cx As Double, cy As Double, radius As Double, angleRadians As Double) As PointF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Dim x As Single = CSng(cx + (r * Math.Cos(angleRadians))) - Dim y As Single = CSng(cy + (r * Math.Sin(angleRadians))) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Dim x As Single = CSng(cx + (radius * Math.Cos(angleRadians))) + Dim y As Single = CSng(cy + (radius * Math.Sin(angleRadians))) Return New PointF(x, y) End Function @@ -217,14 +217,14 @@ Namespace TwoDimensional ''' ''' Mittelpunkt X ''' Mittelpunkt Y - ''' Radius (>= 0) + ''' Radius (>= 0) ''' Achsenparalleles BoundingBox-Rechteck - Public Shared Function BoundingBox(cx As Double, cy As Double, r As Double) As RectangleF + Public Shared Function BoundingBox(cx As Double, cy As Double, radius As Double) As RectangleF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If r < 0 Then Messages.RadiusIsNegative(NameOf(r)) - Dim x As Single = CSng(cx - r) - Dim y As Single = CSng(cy - r) - Dim size As Single = CSng(2.0 * r) + If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + Dim x As Single = CSng(cx - radius) + Dim y As Single = CSng(cy - radius) + Dim size As Single = CSng(2.0 * radius) Return New RectangleF(x, y, size, size) End Function From fd218c5b8b91ed2cc5efe8338702616bd97451a7 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:48:18 +0200 Subject: [PATCH 04/22] Durchmesser-Checks und Ressourcen aktualisiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Messages.vb auf Module umgestellt und um DiameterIsNegative erweitert. Die Durchmesser-Prüfungen in Circle, Cone, Cylinder und Sphere werfen nun bei negativen Werten die zentrale Ressourcennachricht. In Circle wurden Parameter und XML-Dokumentation vereinheitlicht. Assembly- und File-Version auf 1.2026.1003.0 angehoben. --- Geometry/Messages.vb | 11 ++++++++--- Geometry/My Project/AssemblyInfo.vb | 4 ++-- Geometry/My Project/Resources.Designer.vb | 9 +++++++++ Geometry/My Project/Resources.resx | 3 +++ Geometry/ThreeDimensional/Cone.vb | 2 +- Geometry/ThreeDimensional/Cylinder.vb | 2 +- Geometry/ThreeDimensional/Sphere.vb | 2 +- Geometry/TwoDimensional/Circle.vb | 24 +++++++++++------------ 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Geometry/Messages.vb b/Geometry/Messages.vb index 00b755c..1a8de5b 100644 --- a/Geometry/Messages.vb +++ b/Geometry/Messages.vb @@ -1,8 +1,13 @@ -Friend Class Messages +Module Messages - Public Shared Sub RadiusIsNegative(ParameterName As String) + Public Sub RadiusIsNegative(ParameterName As String) Dim message As String = My.Resources.RadiusIsNegative Throw New ArgumentException(message, ParameterName) End Sub -End Class + Public Sub DiameterIsNegative(ParameterName As String) + Dim message As String = My.Resources.DiameterIsNegative + Throw New ArgumentException(message, ParameterName) + End Sub + +End Module diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index 9a3e336..9b8dfe9 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 26a6774..5efe138 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -60,6 +60,15 @@ Namespace My.Resources End Set End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Durchmesser darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property DiameterIsNegative() As String + Get + Return ResourceManager.GetString("DiameterIsNegative", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius darf nicht negativ sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 2a0fcd9..9010915 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Der Durchmesser darf nicht negativ sein. + Der Radius darf nicht negativ sein. diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index 56d056a..6c44223 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -91,7 +91,7 @@ Namespace ThreeDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Throw New ArgumentException("Der Durchmesser darf nicht negativ sein.", NameOf(diameter)) + If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) Return diameter / 2.0 End Function diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index 5e35c76..1df5d5b 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -97,7 +97,7 @@ Namespace ThreeDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Throw New ArgumentException("Der Durchmesser darf nicht negativ sein.", NameOf(diameter)) + If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) Return diameter / 2.0 End Function diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 6bdf76c..92b30f6 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -61,7 +61,7 @@ Namespace ThreeDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Throw New ArgumentException("Der Durchmesser darf nicht negativ sein.", NameOf(diameter)) + If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) Return diameter / 2.0 End Function diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index cc379a1..bf77ef4 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -34,18 +34,18 @@ Namespace TwoDimensional ''' ''' Berechnet die Fläche eines Kreises aus dem Durchmesser. ''' - ''' Durchmesser (>= 0) + ''' Durchmesser (>= 0) ''' Fläche - Public Shared Function AreaFromDiameter(d As Double) As Double + Public Shared Function AreaFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - Return Area(RadiusFromDiameter(d)) + Return Area(RadiusFromDiameter(diameter)) End Function ''' ''' Berechnet den Umfang (Kreisumfang) aus dem Radius. ''' ''' Radius (>= 0) - ''' Umfang = 2 * π * r + ''' Umfang = 2 * π * radius Public Shared Function Circumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) @@ -55,11 +55,11 @@ Namespace TwoDimensional ''' ''' Berechnet den Umfang aus dem Durchmesser. ''' - ''' Durchmesser (>= 0) + ''' Durchmesser (>= 0) ''' Umfang - Public Shared Function CircumferenceFromDiameter(d As Double) As Double + Public Shared Function CircumferenceFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - Return Circumference(RadiusFromDiameter(d)) + Return Circumference(RadiusFromDiameter(diameter)) End Function ''' @@ -76,12 +76,12 @@ Namespace TwoDimensional ''' ''' Konvertiert Durchmesser in Radius. ''' - ''' Durchmesser (>= 0) - ''' Radius d / 2 - Public Shared Function RadiusFromDiameter(d As Double) As Double + ''' Durchmesser (>= 0) + ''' Radius diameter / 2 + Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If d < 0 Then Throw New ArgumentException("Der Durchmesser darf nicht negativ sein.", NameOf(d)) - Return d / 2.0 + If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) + Return diameter / 2.0 End Function #End Region From 840aac8730b0799d9122e07eed98999219d2fcb4 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sat, 3 Oct 2026 16:28:39 +0200 Subject: [PATCH 05/22] =?UTF-8?q?Zentrale=20Radius-Fehlermeldung=20erg?= =?UTF-8?q?=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue Ressourcenmeldung `RadiusIfZeroOrLess` samt `Messages.RadiusIsZeroOrLess(...)` hinzugefügt und in `Circle.AngleFromArcLength` sowie `Circle.AngleFromChordLength` als gemeinsamer Guard für `radius <= 0` verwendet. --- Geometry/Messages.vb | 5 +++++ Geometry/My Project/Resources.Designer.vb | 9 +++++++++ Geometry/My Project/Resources.resx | 3 +++ Geometry/TwoDimensional/Circle.vb | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Geometry/Messages.vb b/Geometry/Messages.vb index 1a8de5b..3c9e5a2 100644 --- a/Geometry/Messages.vb +++ b/Geometry/Messages.vb @@ -10,4 +10,9 @@ Throw New ArgumentException(message, ParameterName) End Sub + Public Sub RadiusIsZeroOrLess(ParameterName As String) + Dim message As String = My.Resources.RadiusIfZeroOrLess + Throw New ArgumentException(message, ParameterName) + End Sub + End Module diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 5efe138..c6d6701 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -69,6 +69,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius muss grösser Null sein. ähnelt. + ''' + Friend ReadOnly Property RadiusIfZeroOrLess() As String + Get + Return ResourceManager.GetString("RadiusIfZeroOrLess", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius darf nicht negativ sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 9010915..bf889b8 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -120,6 +120,9 @@ Der Durchmesser darf nicht negativ sein. + + Der Radius muss grösser Null sein. + Der Radius darf nicht negativ sein. diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index bf77ef4..d18f629 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -174,7 +174,7 @@ Namespace TwoDimensional ''' Zentralwinkel im Bogenmaß Public Shared Function AngleFromArcLength(radius As Double, arcLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius <= 0 Then Throw New ArgumentException("Radius muss > 0 sein.", NameOf(radius)) + If radius <= 0 Then Messages.RadiusIsZeroOrLess(NameOf(radius)) Return arcLength / radius End Function @@ -186,7 +186,7 @@ Namespace TwoDimensional ''' Zentralwinkel im Bogenmaß Public Shared Function AngleFromChordLength(radius As Double, chordLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius <= 0 Then Throw New ArgumentException("Radius muss > 0 sein.", NameOf(radius)) + If radius <= 0 Then Messages.RadiusIsZeroOrLess(NameOf(radius)) If chordLength < 0 OrElse chordLength > 2.0 * radius Then Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) ' chord = 2 radius sin(theta/2) => theta = 2 * asin(chord/(2*radius)) Return 2.0 * Math.Asin(chordLength / (2.0 * radius)) From 4e6af2985384a79c22586ca4024fc828358aa560 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sat, 3 Oct 2026 17:44:08 +0200 Subject: [PATCH 06/22] Dreiecksfehler lokalisieren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue lokalisierte Fehlermeldung `InvalidTriangleSides` für `Triangle.vb` verwendet und Ressourcen sowie Assembly-Version auf `1.2026.1003.1` aktualisiert. --- Geometry/Messages.vb | 5 +++++ Geometry/My Project/AssemblyInfo.vb | 4 ++-- Geometry/My Project/Resources.Designer.vb | 9 +++++++++ Geometry/My Project/Resources.resx | 3 +++ Geometry/TwoDimensional/Triangle.vb | 5 ++--- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Geometry/Messages.vb b/Geometry/Messages.vb index 3c9e5a2..2abad9d 100644 --- a/Geometry/Messages.vb +++ b/Geometry/Messages.vb @@ -15,4 +15,9 @@ Throw New ArgumentException(message, ParameterName) End Sub + Public Sub InvalidTriangleSides() + Dim message As String = My.Resources.InvalidTriangleSides + Throw New ArgumentException(message) + End Sub + End Module diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index 9b8dfe9..be76e78 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index c6d6701..3ccd66b 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -69,6 +69,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten bilden kein gültiges Dreieck. ähnelt. + ''' + Friend ReadOnly Property InvalidTriangleSides() As String + Get + Return ResourceManager.GetString("InvalidTriangleSides", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius muss grösser Null sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index bf889b8..194c1cc 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -120,6 +120,9 @@ Der Durchmesser darf nicht negativ sein. + + Die angegebenen Seiten bilden kein gültiges Dreieck. + Der Radius muss grösser Null sein. diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index b106c76..e0c99f4 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -95,7 +95,7 @@ Namespace TwoDimensional Dim cosValue = ((adjacent1 * adjacent1) + (adjacent2 * adjacent2) - (opposite * opposite)) / denominator If cosValue < -1.0 OrElse cosValue > 1.0 Then - Throw New ArgumentException("Die angegebenen Seiten bilden kein gültiges Dreieck.") + Messages.InvalidTriangleSides() End If Return Math.Acos(cosValue) @@ -183,9 +183,8 @@ Namespace TwoDimensional If a <= 0 Then Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) If b <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) If c <= 0 Then Throw New ArgumentException("Seite c muss größer als 0 sein.", NameOf(c)) - If a + b <= c OrElse a + c <= b OrElse b + c <= a Then - Throw New ArgumentException("Die angegebenen Seiten bilden kein gültiges Dreieck.") + Messages.InvalidTriangleSides() End If End Sub From 81f8c1bb56fef0674df082c12580e85f941db0b0 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sat, 3 Oct 2026 21:06:10 +0200 Subject: [PATCH 07/22] =?UTF-8?q?Guard-Clauses=20vereinheitlichen,=20Versi?= =?UTF-8?q?on=20erh=C3=B6hen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Messages.vb entfernt; ArgumentException nutzt nun direkt My.Resources. Guard-Clauses für negative Radien, ungültige Durchmesser sowie Dreiecksseiten und Cosinuswerte vereinheitlicht. Assembly-Version auf 1.2026.1003.3 angehoben. --- Geometry/Geometry.vbproj | 1 - Geometry/Messages.vb | 23 ------------ Geometry/My Project/AssemblyInfo.vb | 4 +-- Geometry/ThreeDimensional/Cone.vb | 45 +++++++++++++++++------ Geometry/ThreeDimensional/Cylinder.vb | 52 ++++++++++++++++++++------- Geometry/ThreeDimensional/Sphere.vb | 28 +++++++++++---- Geometry/TwoDimensional/Circle.vb | 50 +++++++++++++++++++------- Geometry/TwoDimensional/Triangle.vb | 4 +-- 8 files changed, 136 insertions(+), 71 deletions(-) delete mode 100644 Geometry/Messages.vb diff --git a/Geometry/Geometry.vbproj b/Geometry/Geometry.vbproj index 1d80af6..29a0973 100644 --- a/Geometry/Geometry.vbproj +++ b/Geometry/Geometry.vbproj @@ -75,7 +75,6 @@ - diff --git a/Geometry/Messages.vb b/Geometry/Messages.vb deleted file mode 100644 index 2abad9d..0000000 --- a/Geometry/Messages.vb +++ /dev/null @@ -1,23 +0,0 @@ -Module Messages - - Public Sub RadiusIsNegative(ParameterName As String) - Dim message As String = My.Resources.RadiusIsNegative - Throw New ArgumentException(message, ParameterName) - End Sub - - Public Sub DiameterIsNegative(ParameterName As String) - Dim message As String = My.Resources.DiameterIsNegative - Throw New ArgumentException(message, ParameterName) - End Sub - - Public Sub RadiusIsZeroOrLess(ParameterName As String) - Dim message As String = My.Resources.RadiusIfZeroOrLess - Throw New ArgumentException(message, ParameterName) - End Sub - - Public Sub InvalidTriangleSides() - Dim message As String = My.Resources.InvalidTriangleSides - Throw New ArgumentException(message) - End Sub - -End Module diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index be76e78..fe433d9 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index 6c44223..463c374 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -26,8 +26,12 @@ Namespace ThreeDimensional ''' Volumen (PI * r^2 * h) / 3 Public Shared Function Volume(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * radius * radius * height) / 3.0 #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -41,8 +45,12 @@ Namespace ThreeDimensional ''' Schräghöhe sqrt(r^2 + h^2) Public Shared Function SlantHeight(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If Return Math.Sqrt((radius * radius) + (height * height)) End Function @@ -54,8 +62,12 @@ Namespace ThreeDimensional ''' Mantelfläche PI * r * s Public Shared Function LateralArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If Return Math.PI * radius * SlantHeight(radius, height) End Function @@ -67,8 +79,12 @@ Namespace ThreeDimensional ''' Oberfläche PI * r * (r + s) Public Shared Function SurfaceArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If Dim s = SlantHeight(radius, height) Return Math.PI * radius * (radius + s) End Function @@ -80,7 +96,9 @@ Namespace ThreeDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * radius End Function @@ -91,7 +109,9 @@ Namespace ThreeDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) + If diameter < 0 Then + Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + End If Return diameter / 2.0 End Function @@ -163,7 +183,10 @@ Namespace ThreeDimensional ''' 3D-Punkt als Tuple(X,Y,Z) Public Shared Function PointOnLateralSurface(centerX As Double, centerY As Double, baseZ As Double, radius As Double, height As Double, angleRadians As Double, t As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) If t < 0 OrElse t > 1 Then Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index 1df5d5b..3a72233 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -26,8 +26,12 @@ Namespace ThreeDimensional ''' Volumen PI * r^2 * h Public Shared Function Volume(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If Return Math.PI * radius * radius * height End Function @@ -39,8 +43,12 @@ Namespace ThreeDimensional ''' Mantelfläche 2 * PI * r * h Public Shared Function LateralArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If Return 2.0 * Math.PI * radius * height End Function @@ -52,8 +60,12 @@ Namespace ThreeDimensional ''' Oberfläche 2*PI*r*(r+h) Public Shared Function SurfaceArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If Return 2.0 * Math.PI * radius * (radius + height) End Function @@ -64,7 +76,9 @@ Namespace ThreeDimensional ''' 2 * PI * r Public Shared Function BaseCircumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * Math.PI * radius End Function @@ -75,7 +89,9 @@ Namespace ThreeDimensional ''' PI * r^2 Public Shared Function BaseArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return Math.PI * radius * radius End Function @@ -86,7 +102,9 @@ Namespace ThreeDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * radius End Function @@ -97,7 +115,9 @@ Namespace ThreeDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) + If diameter < 0 Then + Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + End If Return diameter / 2.0 End Function @@ -154,9 +174,15 @@ Namespace ThreeDimensional ''' 3D-Koordinate als Tuple(X, Y, Z) Public Shared Function PointOnLateralSurface(centerX As Double, centerY As Double, baseZ As Double, radius As Double, height As Double, angleRadians As Double, heightOffset As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) - If heightOffset < 0 OrElse heightOffset > height Then Throw New ArgumentException("Höhenoffset muss im Bereich 0 bis Höhe liegen.", NameOf(heightOffset)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + If height < 0 Then + Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + End If + If heightOffset < 0 OrElse heightOffset > height Then + Throw New ArgumentException("Höhenoffset muss im Bereich 0 bis Höhe liegen.", NameOf(heightOffset)) + End If Dim x = centerX + (radius * Math.Cos(angleRadians)) Dim y = centerY + (radius * Math.Sin(angleRadians)) diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 92b30f6..e55ef31 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -25,7 +25,9 @@ Namespace ThreeDimensional ''' Volumen 4/3 * PI * r^3 Public Shared Function Volume(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3) @@ -39,7 +41,9 @@ Namespace ThreeDimensional ''' Oberfläche 4 * PI * r^2 Public Shared Function SurfaceArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 4.0 * Math.PI * radius * radius End Function @@ -50,7 +54,9 @@ Namespace ThreeDimensional ''' Durchmesser 2 * r Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * radius End Function @@ -61,7 +67,9 @@ Namespace ThreeDimensional ''' Radius d / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) + If diameter < 0 Then + Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + End If Return diameter / 2.0 End Function @@ -72,7 +80,9 @@ Namespace ThreeDimensional ''' Umfang 2 * PI * r Public Shared Function GreatCircleCircumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * Math.PI * radius End Function @@ -83,7 +93,9 @@ Namespace ThreeDimensional ''' Fläche PI * r^2 Public Shared Function GreatCircleArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return Math.PI * radius * radius End Function @@ -131,7 +143,9 @@ Namespace ThreeDimensional ''' 3D-Koordinate als Tuple(X, Y, Z) Public Shared Function PointOnSphere(centerX As Double, centerY As Double, centerZ As Double, radius As Double, polarAngleRadians As Double, azimuthRadians As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If If polarAngleRadians < 0 OrElse polarAngleRadians > Math.PI Then Throw New ArgumentException("Der Polarwinkel muss im Bereich 0 bis PI liegen.", NameOf(polarAngleRadians)) End If diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index d18f629..74731b2 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -27,7 +27,10 @@ Namespace TwoDimensional ''' Fläche = π * radius^2 Public Shared Function Area(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + Return Math.PI * radius * radius End Function @@ -48,7 +51,9 @@ Namespace TwoDimensional ''' Umfang = 2 * π * radius Public Shared Function Circumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * Math.PI * radius End Function @@ -69,7 +74,9 @@ Namespace TwoDimensional ''' Durchmesser 2 * radius Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * radius End Function @@ -80,7 +87,9 @@ Namespace TwoDimensional ''' Radius diameter / 2 Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diameter < 0 Then Messages.DiameterIsNegative(NameOf(diameter)) + If diameter < 0 Then + Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + End If Return diameter / 2.0 End Function @@ -96,7 +105,9 @@ Namespace TwoDimensional ''' Bogenlänge = radius * angle Public Shared Function ArcLength(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return radius * angleRadians End Function @@ -120,7 +131,9 @@ Namespace TwoDimensional ''' Sektorfläche = 0.5 * radius^2 * angle Public Shared Function SectorArea(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 0.5 * radius * radius * angleRadians End Function @@ -144,7 +157,9 @@ Namespace TwoDimensional ''' Sehnenlänge = 2 * radius * sin(angle/2) Public Shared Function ChordLength(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Return 2.0 * radius * Math.Sin(angleRadians / 2.0) End Function @@ -156,7 +171,9 @@ Namespace TwoDimensional ''' Sehnenlänge Public Shared Function ChordLengthFromSagitta(radius As Double, sagitta As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If If sagitta < 0 Or sagitta > radius Then Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) ' Abstand vom Mittelpunkt zur Sehne (h) = radius - sagitta @@ -174,7 +191,9 @@ Namespace TwoDimensional ''' Zentralwinkel im Bogenmaß Public Shared Function AngleFromArcLength(radius As Double, arcLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius <= 0 Then Messages.RadiusIsZeroOrLess(NameOf(radius)) + If radius <= 0 Then + Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) + End If Return arcLength / radius End Function @@ -186,7 +205,9 @@ Namespace TwoDimensional ''' Zentralwinkel im Bogenmaß Public Shared Function AngleFromChordLength(radius As Double, chordLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius <= 0 Then Messages.RadiusIsZeroOrLess(NameOf(radius)) + If radius <= 0 Then + Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) + End If If chordLength < 0 OrElse chordLength > 2.0 * radius Then Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) ' chord = 2 radius sin(theta/2) => theta = 2 * asin(chord/(2*radius)) Return 2.0 * Math.Asin(chordLength / (2.0 * radius)) @@ -206,7 +227,10 @@ Namespace TwoDimensional ''' PointF mit Koordinaten des Punktes Public Shared Function PointOnCircle(cx As Double, cy As Double, radius As Double, angleRadians As Double) As PointF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If + Dim x As Single = CSng(cx + (radius * Math.Cos(angleRadians))) Dim y As Single = CSng(cy + (radius * Math.Sin(angleRadians))) Return New PointF(x, y) @@ -221,7 +245,9 @@ Namespace TwoDimensional ''' Achsenparalleles BoundingBox-Rechteck Public Shared Function BoundingBox(cx As Double, cy As Double, radius As Double) As RectangleF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius < 0 Then Messages.RadiusIsNegative(NameOf(radius)) + If radius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + End If Dim x As Single = CSng(cx - radius) Dim y As Single = CSng(cy - radius) Dim size As Single = CSng(2.0 * radius) diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index e0c99f4..8e60c2d 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -95,7 +95,7 @@ Namespace TwoDimensional Dim cosValue = ((adjacent1 * adjacent1) + (adjacent2 * adjacent2) - (opposite * opposite)) / denominator If cosValue < -1.0 OrElse cosValue > 1.0 Then - Messages.InvalidTriangleSides() + Throw New ArgumentException(My.Resources.InvalidTriangleSides) End If Return Math.Acos(cosValue) @@ -184,7 +184,7 @@ Namespace TwoDimensional If b <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) If c <= 0 Then Throw New ArgumentException("Seite c muss größer als 0 sein.", NameOf(c)) If a + b <= c OrElse a + c <= b OrElse b + c <= a Then - Messages.InvalidTriangleSides() + Throw New ArgumentException(My.Resources.InvalidTriangleSides) End If End Sub From b954d90ee07cdea843b16058de5aeac0acf36367 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sun, 4 Oct 2026 12:20:14 +0200 Subject: [PATCH 08/22] 3D-Validierung auf Ressourcen umgestellt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue lokalisierte Ressourcen für negative Höhe, Länge und Breite ergänzt und in Cone.vb sowie Cuboid.vb für die Validierung verwendet. Hardcodierte Fehlermeldungen wurden durch My.Resources.* ersetzt. --- Geometry/My Project/Resources.Designer.vb | 27 +++++++++++++++ Geometry/My Project/Resources.resx | 9 +++++ Geometry/ThreeDimensional/Cone.vb | 16 ++++----- Geometry/ThreeDimensional/Cuboid.vb | 42 +++++++++++------------ 4 files changed, 65 insertions(+), 29 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 3ccd66b..fe396ec 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -69,6 +69,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Höhe darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property HeightIsNegative() As String + Get + Return ResourceManager.GetString("HeightIsNegative", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten bilden kein gültiges Dreieck. ähnelt. ''' @@ -78,6 +87,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property LengthIsNegative() As String + Get + Return ResourceManager.GetString("LengthIsNegative", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius muss grösser Null sein. ähnelt. ''' @@ -95,5 +113,14 @@ Namespace My.Resources Return ResourceManager.GetString("RadiusIsNegative", resourceCulture) End Get End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite darf nicht negatv sein. ähnelt. + ''' + Friend ReadOnly Property WidthIsNegative() As String + Get + Return ResourceManager.GetString("WidthIsNegative", resourceCulture) + End Get + End Property End Module End Namespace diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 194c1cc..827fcc7 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -120,13 +120,22 @@ Der Durchmesser darf nicht negativ sein. + + Die Höhe darf nicht negativ sein. + Die angegebenen Seiten bilden kein gültiges Dreieck. + + Die Länge darf nicht negativ sein. + Der Radius muss grösser Null sein. Der Radius darf nicht negativ sein. + + Die Breite darf nicht negatv sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index 463c374..88dddad 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -30,7 +30,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * radius * radius * height) / 3.0 @@ -49,7 +49,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If Return Math.Sqrt((radius * radius) + (height * height)) End Function @@ -66,7 +66,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If Return Math.PI * radius * SlantHeight(radius, height) End Function @@ -83,7 +83,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If Dim s = SlantHeight(radius, height) Return Math.PI * radius * (radius + s) @@ -129,7 +129,7 @@ Namespace ThreeDimensional Public Shared Function FrustumVolume(radiusBottom As Double, radiusTop As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * height / 3.0) * ((radiusBottom * radiusBottom) + (radiusBottom * radiusTop) + (radiusTop * radiusTop)) #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -145,7 +145,7 @@ Namespace ThreeDimensional Public Shared Function FrustumLateralArea(radiusBottom As Double, radiusTop As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Dim s = Math.Sqrt(((radiusBottom - radiusTop) * (radiusBottom - radiusTop)) + (height * height)) Return Math.PI * (radiusBottom + radiusTop) * s End Function @@ -160,7 +160,7 @@ Namespace ThreeDimensional Public Shared Function FrustumSurfaceArea(radiusBottom As Double, radiusTop As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Dim lateral = FrustumLateralArea(radiusBottom, radiusTop, height) Dim bases = Math.PI * ((radiusBottom * radiusBottom) + (radiusTop * radiusTop)) Return lateral + bases @@ -187,7 +187,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) If t < 0 OrElse t > 1 Then Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) Dim currentRadius = radius * (1.0 - t) diff --git a/Geometry/ThreeDimensional/Cuboid.vb b/Geometry/ThreeDimensional/Cuboid.vb index 25be741..40b4f41 100644 --- a/Geometry/ThreeDimensional/Cuboid.vb +++ b/Geometry/ThreeDimensional/Cuboid.vb @@ -27,9 +27,9 @@ Namespace ThreeDimensional ''' Volumen length * width * height Public Shared Function Volume(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Return length * width * height End Function @@ -43,9 +43,9 @@ Namespace ThreeDimensional ''' Oberfläche 2 * (lw + lh + wh) Public Shared Function SurfaceArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Return 2.0 * ((length * width) + (length * height) + (width * height)) End Function @@ -59,9 +59,9 @@ Namespace ThreeDimensional ''' Raumdiagonale sqrt(l^2 + w^2 + h^2) Public Shared Function SpaceDiagonal(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Return Math.Sqrt((length * length) + (width * width) + (height * height)) End Function @@ -74,8 +74,8 @@ Namespace ThreeDimensional ''' Flächendiagonale sqrt(l^2 + w^2) Public Shared Function FaceDiagonalLengthWidth(length As Double, width As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) Return Math.Sqrt((length * length) + (width * width)) End Function @@ -87,8 +87,8 @@ Namespace ThreeDimensional ''' Flächendiagonale sqrt(l^2 + h^2) Public Shared Function FaceDiagonalLengthHeight(length As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Return Math.Sqrt((length * length) + (height * height)) End Function @@ -100,8 +100,8 @@ Namespace ThreeDimensional ''' Flächendiagonale sqrt(w^2 + h^2) Public Shared Function FaceDiagonalWidthHeight(width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Return Math.Sqrt((width * width) + (height * height)) End Function @@ -130,9 +130,9 @@ Namespace ThreeDimensional ''' True, wenn alle drei Kanten innerhalb der Toleranz gleich sind Public Shared Function IsCube(length As Double, width As Double, height As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) Return Math.Abs(length - width) <= tolerance AndAlso Math.Abs(length - height) <= tolerance @@ -169,9 +169,9 @@ Namespace ThreeDimensional ''' Array mit 8 Eckpunkten als Tuple(X,Y,Z) Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, length As Double, width As Double, height As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Länge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Breite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) Dim lx = length / 2.0 Dim wy = width / 2.0 From 534bea610219b1a34775c63dc3c27467b335014b Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sun, 4 Oct 2026 13:21:40 +0200 Subject: [PATCH 09/22] Guard-Clauses vereinheitlicht MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guard-Clauses in 2D-/3D-Geometrieklassen vereinheitlicht, Einzeiler meist auf blockierte If-Prüfungen umgestellt und negative Höhen auf My.Resources.HeightIsNegative umgestellt. --- Geometry/ThreeDimensional/Cylinder.vb | 16 +++-- Geometry/ThreeDimensional/Frustum.vb | 74 +++++++++++++++----- Geometry/ThreeDimensional/Prism.vb | 56 +++++++++++---- Geometry/ThreeDimensional/Pyramid.vb | 88 ++++++++++++++++++------ Geometry/ThreeDimensional/Sphere.vb | 12 +++- Geometry/TwoDimensional/Kite.vb | 36 +++++++--- Geometry/TwoDimensional/Parallelogram.vb | 24 +++++-- Geometry/TwoDimensional/Rectangle.vb | 20 ++++-- Geometry/TwoDimensional/Rhombus.vb | 20 ++++-- Geometry/TwoDimensional/Trapezoid.vb | 52 ++++++++++---- Geometry/TwoDimensional/Triangle.vb | 16 +++-- 11 files changed, 308 insertions(+), 106 deletions(-) diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index 3a72233..cb336bc 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -30,7 +30,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If Return Math.PI * radius * radius * height End Function @@ -47,7 +47,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If Return 2.0 * Math.PI * radius * height End Function @@ -64,7 +64,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If Return 2.0 * Math.PI * radius * (radius + height) End Function @@ -135,7 +135,9 @@ Namespace ThreeDimensional Public Shared Function HollowVolume(outerRadius As Double, innerRadius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateHollowRadii(outerRadius, innerRadius) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return Math.PI * ((outerRadius * outerRadius) - (innerRadius * innerRadius)) * height End Function @@ -149,7 +151,9 @@ Namespace ThreeDimensional Public Shared Function HollowSurfaceArea(outerRadius As Double, innerRadius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateHollowRadii(outerRadius, innerRadius) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim outerLateral = 2.0 * Math.PI * outerRadius * height Dim innerLateral = 2.0 * Math.PI * innerRadius * height @@ -178,7 +182,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If If heightOffset < 0 OrElse heightOffset > height Then Throw New ArgumentException("Höhenoffset muss im Bereich 0 bis Höhe liegen.", NameOf(heightOffset)) diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index 02bffdf..e3416a1 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -131,9 +131,15 @@ Namespace ThreeDimensional ''' Volumen ((bottomArea + topArea)/2) * height Public Shared Function PrismFrustumVolume(bottomArea As Double, topArea As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If bottomArea < 0 Then Throw New ArgumentException("Die untere Endfläche darf nicht negativ sein.", NameOf(bottomArea)) - If topArea < 0 Then Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If bottomArea < 0 Then + Throw New ArgumentException("Die untere Endfläche darf nicht negativ sein.", NameOf(bottomArea)) + End If + If topArea < 0 Then + Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return ((bottomArea + topArea) / 2.0) * height @@ -149,9 +155,15 @@ Namespace ThreeDimensional ''' Mantelfläche ((bottomPerimeter + topPerimeter)/2) * height Public Shared Function PrismFrustumLateralArea(bottomPerimeter As Double, topPerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If bottomPerimeter < 0 Then Throw New ArgumentException("Der untere Umfang darf nicht negativ sein.", NameOf(bottomPerimeter)) - If topPerimeter < 0 Then Throw New ArgumentException("Der obere Umfang darf nicht negativ sein.", NameOf(topPerimeter)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If bottomPerimeter < 0 Then + Throw New ArgumentException("Der untere Umfang darf nicht negativ sein.", NameOf(bottomPerimeter)) + End If + If topPerimeter < 0 Then + Throw New ArgumentException("Der obere Umfang darf nicht negativ sein.", NameOf(topPerimeter)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return ((bottomPerimeter + topPerimeter) / 2.0) * height @@ -169,11 +181,21 @@ Namespace ThreeDimensional ''' Oberfläche Endflächen + Mantelfläche Public Shared Function PrismFrustumSurfaceArea(bottomArea As Double, topArea As Double, bottomPerimeter As Double, topPerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If bottomArea < 0 Then Throw New ArgumentException("Die untere Endfläche darf nicht negativ sein.", NameOf(bottomArea)) - If topArea < 0 Then Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) - If bottomPerimeter < 0 Then Throw New ArgumentException("Der untere Umfang darf nicht negativ sein.", NameOf(bottomPerimeter)) - If topPerimeter < 0 Then Throw New ArgumentException("Der obere Umfang darf nicht negativ sein.", NameOf(topPerimeter)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If bottomArea < 0 Then + Throw New ArgumentException("Die untere Endfläche darf nicht negativ sein.", NameOf(bottomArea)) + End If + If topArea < 0 Then + Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) + End If + If bottomPerimeter < 0 Then + Throw New ArgumentException("Der untere Umfang darf nicht negativ sein.", NameOf(bottomPerimeter)) + End If + If topPerimeter < 0 Then + Throw New ArgumentException("Der obere Umfang darf nicht negativ sein.", NameOf(topPerimeter)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return bottomArea + topArea + PrismFrustumLateralArea(bottomPerimeter, topPerimeter, height) End Function @@ -187,18 +209,32 @@ Namespace ThreeDimensional If bottomRadius <= 0 Then Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(bottomRadius)) If topRadius < 0 Then Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(topRadius)) If topRadius >= bottomRadius Then Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(topRadius)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End Sub Private Shared Sub ValidatePyramidFrustumInputs(bottomLength As Double, bottomWidth As Double, topLength As Double, topWidth As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If bottomLength <= 0 Then Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) - If bottomWidth <= 0 Then Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) - If topLength < 0 Then Throw New ArgumentException("Die obere Grundlänge darf nicht negativ sein.", NameOf(topLength)) - If topWidth < 0 Then Throw New ArgumentException("Die obere Grundbreite darf nicht negativ sein.", NameOf(topWidth)) - If topLength >= bottomLength Then Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere sein.", NameOf(topLength)) - If topWidth >= bottomWidth Then Throw New ArgumentException("Die obere Grundbreite muss kleiner als die untere sein.", NameOf(topWidth)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If bottomLength <= 0 Then + Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) + End If + If bottomWidth <= 0 Then + Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) + End If + If topLength < 0 Then + Throw New ArgumentException("Die obere Grundlänge darf nicht negativ sein.", NameOf(topLength)) + End If + If topWidth < 0 Then + Throw New ArgumentException("Die obere Grundbreite darf nicht negativ sein.", NameOf(topWidth)) + End If + If topLength >= bottomLength Then + Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere sein.", NameOf(topLength)) + End If + If topWidth >= bottomWidth Then + Throw New ArgumentException("Die obere Grundbreite muss kleiner als die untere sein.", NameOf(topWidth)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If End Sub #End Region diff --git a/Geometry/ThreeDimensional/Prism.vb b/Geometry/ThreeDimensional/Prism.vb index 1168361..4f8beb7 100644 --- a/Geometry/ThreeDimensional/Prism.vb +++ b/Geometry/ThreeDimensional/Prism.vb @@ -26,8 +26,12 @@ Namespace ThreeDimensional ''' Volumen baseArea * height Public Shared Function Volume(baseArea As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseArea < 0 Then Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If baseArea < 0 Then + Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return baseArea * height End Function @@ -39,8 +43,12 @@ Namespace ThreeDimensional ''' Mantelfläche basePerimeter * height Public Shared Function LateralArea(basePerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If basePerimeter < 0 Then Throw New ArgumentException("Der Grundumfang darf nicht negativ sein.", NameOf(basePerimeter)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If basePerimeter < 0 Then + Throw New ArgumentException("Der Grundumfang darf nicht negativ sein.", NameOf(basePerimeter)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return basePerimeter * height End Function @@ -53,9 +61,15 @@ Namespace ThreeDimensional ''' Oberfläche 2 * baseArea + basePerimeter * height Public Shared Function SurfaceArea(baseArea As Double, basePerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseArea < 0 Then Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) - If basePerimeter < 0 Then Throw New ArgumentException("Der Grundumfang darf nicht negativ sein.", NameOf(basePerimeter)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If baseArea < 0 Then + Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) + End If + If basePerimeter < 0 Then + Throw New ArgumentException("Der Grundumfang darf nicht negativ sein.", NameOf(basePerimeter)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return (2.0 * baseArea) + LateralArea(basePerimeter, height) End Function @@ -88,7 +102,9 @@ Namespace ThreeDimensional ''' Volumen Dreiecksgrundfläche * height Public Shared Function TriangularPrismVolume(sideA As Double, sideB As Double, sideC As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return Volume(TriangularBaseArea(sideA, sideB, sideC), height) End Function @@ -102,7 +118,9 @@ Namespace ThreeDimensional ''' Oberfläche 2 * Dreiecksgrundfläche + (a+b+c) * height Public Shared Function TriangularPrismSurfaceArea(sideA As Double, sideB As Double, sideC As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim baseArea = TriangularBaseArea(sideA, sideB, sideC) Dim basePerimeter = sideA + sideB + sideC Return SurfaceArea(baseArea, basePerimeter, height) @@ -116,7 +134,9 @@ Namespace ThreeDimensional ''' Fläche n*s^2/(4*tan(PI/n)) Public Shared Function RegularPolygonBaseArea(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideLength < 0 Then Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(sideLength)) + If sideLength < 0 Then + Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(sideLength)) + End If ValidateSideCount(sideCount) If sideLength = 0 Then Return 0 @@ -134,7 +154,9 @@ Namespace ThreeDimensional ''' Volumen Grundfläche * Höhe Public Shared Function RegularPolygonPrismVolume(sideLength As Double, sideCount As Integer, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim baseArea = RegularPolygonBaseArea(sideLength, sideCount) Return Volume(baseArea, height) End Function @@ -148,7 +170,9 @@ Namespace ThreeDimensional ''' Oberfläche 2 * Grundfläche + Umfang * Höhe Public Shared Function RegularPolygonPrismSurfaceArea(sideLength As Double, sideCount As Integer, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim baseArea = RegularPolygonBaseArea(sideLength, sideCount) Dim basePerimeter = sideCount * sideLength Return SurfaceArea(baseArea, basePerimeter, height) @@ -160,8 +184,12 @@ Namespace ThreeDimensional Private Shared Sub ValidateTriangleSides(sideA As Double, sideB As Double, sideC As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideA <= 0 Then Throw New ArgumentException("Seite A muss größer als 0 sein.", NameOf(sideA)) - If sideB <= 0 Then Throw New ArgumentException("Seite B muss größer als 0 sein.", NameOf(sideB)) + If sideA <= 0 Then + Throw New ArgumentException("Seite A muss größer als 0 sein.", NameOf(sideA)) + End If + If sideB <= 0 Then + Throw New ArgumentException("Seite B muss größer als 0 sein.", NameOf(sideB)) + End If If sideC <= 0 Then Throw New ArgumentException("Seite C muss größer als 0 sein.", NameOf(sideC)) If sideA + sideB <= sideC OrElse sideA + sideC <= sideB OrElse sideB + sideC <= sideA Then diff --git a/Geometry/ThreeDimensional/Pyramid.vb b/Geometry/ThreeDimensional/Pyramid.vb index 997960e..d783bde 100644 --- a/Geometry/ThreeDimensional/Pyramid.vb +++ b/Geometry/ThreeDimensional/Pyramid.vb @@ -40,9 +40,15 @@ Namespace ThreeDimensional ''' Volumen (Grundfläche * Höhe) / 3 Public Shared Function Volume(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then + Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (BaseArea(length, width) * height) / 3.0 @@ -57,8 +63,12 @@ Namespace ThreeDimensional ''' Schräghöhe sqrt((width/2)^2 + h^2) Public Shared Function SlantHeightLengthFace(width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If width < 0 Then Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If width < 0 Then + Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim halfWidth = width / 2.0 Return Math.Sqrt((halfWidth * halfWidth) + (height * height)) @@ -72,8 +82,12 @@ Namespace ThreeDimensional ''' Schräghöhe sqrt((length/2)^2 + h^2) Public Shared Function SlantHeightWidthFace(length As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then + Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim halfLength = length / 2.0 Return Math.Sqrt((halfLength * halfLength) + (height * height)) @@ -88,9 +102,15 @@ Namespace ThreeDimensional ''' Mantelfläche aus 4 Dreiecksflächen Public Shared Function LateralArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then + Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim slantLen = SlantHeightLengthFace(width, height) Dim slantWid = SlantHeightWidthFace(length, height) @@ -106,9 +126,15 @@ Namespace ThreeDimensional ''' Gesamtoberfläche Grundfläche + Mantelfläche Public Shared Function SurfaceArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then + Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return BaseArea(length, width) + LateralArea(length, width, height) End Function @@ -204,9 +230,15 @@ Namespace ThreeDimensional ''' Array mit 5 Punkten: 4 Grundpunkte + Spitze Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, length As Double, width As Double, height As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If length < 0 Then + Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim halfLength = length / 2.0 Dim halfWidth = width / 2.0 @@ -228,12 +260,24 @@ Namespace ThreeDimensional Private Shared Sub ValidateFrustumInputs(bottomLength As Double, bottomWidth As Double, topLength As Double, topWidth As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomLength <= 0 Then Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) - If bottomWidth <= 0 Then Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) - If topLength < 0 Then Throw New ArgumentException("Die obere Grundlänge darf nicht negativ sein.", NameOf(topLength)) - If topWidth < 0 Then Throw New ArgumentException("Die obere Grundbreite darf nicht negativ sein.", NameOf(topWidth)) - If topLength >= bottomLength Then Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere Grundlänge sein.", NameOf(topLength)) - If topWidth >= bottomWidth Then Throw New ArgumentException("Die obere Grundbreite muss kleiner als die untere Grundbreite sein.", NameOf(topWidth)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If bottomWidth <= 0 Then + Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) + End If + If topLength < 0 Then + Throw New ArgumentException("Die obere Grundlänge darf nicht negativ sein.", NameOf(topLength)) + End If + If topWidth < 0 Then + Throw New ArgumentException("Die obere Grundbreite darf nicht negativ sein.", NameOf(topWidth)) + End If + If topLength >= bottomLength Then + Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere Grundlänge sein.", NameOf(topLength)) + End If + If topWidth >= bottomWidth Then + Throw New ArgumentException("Die obere Grundbreite muss kleiner als die untere Grundbreite sein.", NameOf(topWidth)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If End Sub #End Region diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index e55ef31..88f0999 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -164,9 +164,15 @@ Namespace ThreeDimensional Private Shared Sub ValidateCapInputs(radius As Double, capHeight As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radius <= 0 Then Throw New ArgumentException("Der Radius muss größer als 0 sein.", NameOf(radius)) - If capHeight < 0 Then Throw New ArgumentException("Die Kappenhöhe darf nicht negativ sein.", NameOf(capHeight)) - If capHeight > 2.0 * radius Then Throw New ArgumentException("Die Kappenhöhe darf maximal 2 * Radius sein.", NameOf(capHeight)) + If radius <= 0 Then + Throw New ArgumentException("Der Radius muss größer als 0 sein.", NameOf(radius)) + End If + If capHeight < 0 Then + Throw New ArgumentException("Die Kappenhöhe darf nicht negativ sein.", NameOf(capHeight)) + End If + If capHeight > 2.0 * radius Then + Throw New ArgumentException("Die Kappenhöhe darf maximal 2 * Radius sein.", NameOf(capHeight)) + End If End Sub #End Region diff --git a/Geometry/TwoDimensional/Kite.vb b/Geometry/TwoDimensional/Kite.vb index 27c7e2f..e227824 100644 --- a/Geometry/TwoDimensional/Kite.vb +++ b/Geometry/TwoDimensional/Kite.vb @@ -56,8 +56,12 @@ Namespace TwoDimensional ''' Fläche baseLength * height Public Shared Function AreaFromBaseHeight(baseLength As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseLength < 0 Then Throw New ArgumentException("Die Grundseite darf nicht negativ sein.", NameOf(baseLength)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If baseLength < 0 Then + Throw New ArgumentException("Die Grundseite darf nicht negativ sein.", NameOf(baseLength)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return baseLength * height End Function @@ -69,8 +73,12 @@ Namespace TwoDimensional ''' Höhe area / baseLength Public Shared Function HeightFromArea(area As Double, baseLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If area < 0 Then Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) - If baseLength <= 0 Then Throw New ArgumentException("Die Grundseite muss größer als 0 sein.", NameOf(baseLength)) + If area < 0 Then + Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) + End If + If baseLength <= 0 Then + Throw New ArgumentException("Die Grundseite muss größer als 0 sein.", NameOf(baseLength)) + End If Return area / baseLength End Function @@ -85,11 +93,21 @@ Namespace TwoDimensional ''' True, wenn |A-B| und |C-D| innerhalb der Toleranz sind Public Shared Function IsSymmetricBySides(sideA As Double, sideB As Double, sideC As Double, sideD As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideA < 0 Then Throw New ArgumentException("Seite A darf nicht negativ sein.", NameOf(sideA)) - If sideB < 0 Then Throw New ArgumentException("Seite B darf nicht negativ sein.", NameOf(sideB)) - If sideC < 0 Then Throw New ArgumentException("Seite C darf nicht negativ sein.", NameOf(sideC)) - If sideD < 0 Then Throw New ArgumentException("Seite D darf nicht negativ sein.", NameOf(sideD)) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If sideA < 0 Then + Throw New ArgumentException("Seite A darf nicht negativ sein.", NameOf(sideA)) + End If + If sideB < 0 Then + Throw New ArgumentException("Seite B darf nicht negativ sein.", NameOf(sideB)) + End If + If sideC < 0 Then + Throw New ArgumentException("Seite C darf nicht negativ sein.", NameOf(sideC)) + End If + If sideD < 0 Then + Throw New ArgumentException("Seite D darf nicht negativ sein.", NameOf(sideD)) + End If + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim firstPair = Math.Abs(sideA - sideB) <= tolerance AndAlso Math.Abs(sideC - sideD) <= tolerance Dim secondPair = Math.Abs(sideB - sideC) <= tolerance AndAlso Math.Abs(sideD - sideA) <= tolerance diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index a2a7ffa..16605fb 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -28,8 +28,12 @@ Namespace TwoDimensional ''' Fläche b * h Public Shared Function Area(b As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If b < 0 Then Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) - If h < 0 Then Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + If b < 0 Then + Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) + End If + If h < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) + End If Return b * h End Function @@ -42,8 +46,12 @@ Namespace TwoDimensional ''' Umfang 2 * (a + b) Public Shared Function Perimeter(a As Double, b As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If a < 0 Then Throw New ArgumentException("Seite a darf nicht negativ sein.", NameOf(a)) - If b < 0 Then Throw New ArgumentException("Seite b darf nicht negativ sein.", NameOf(b)) + If a < 0 Then + Throw New ArgumentException("Seite a darf nicht negativ sein.", NameOf(a)) + End If + If b < 0 Then + Throw New ArgumentException("Seite b darf nicht negativ sein.", NameOf(b)) + End If Return 2.0 * (a + b) End Function @@ -56,8 +64,12 @@ Namespace TwoDimensional ''' Höhe area / b Public Shared Function HeightFromArea(area As Double, b As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If area < 0 Then Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) - If b <= 0 Then Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) + If area < 0 Then + Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) + End If + If b <= 0 Then + Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) + End If Return area / b End Function diff --git a/Geometry/TwoDimensional/Rectangle.vb b/Geometry/TwoDimensional/Rectangle.vb index 5d28d77..cf8b64b 100644 --- a/Geometry/TwoDimensional/Rectangle.vb +++ b/Geometry/TwoDimensional/Rectangle.vb @@ -28,8 +28,12 @@ Namespace TwoDimensional ''' Fläche (w * h) Public Shared Function Area(w As Double, h As Double) As Double ' Guard-Clauses: negative Werte sind nicht erlaubt - If w < 0 Then Throw New ArgumentException("Breite darf nicht negativ sein.", NameOf(w)) - If h < 0 Then Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + If w < 0 Then + Throw New ArgumentException("Breite darf nicht negativ sein.", NameOf(w)) + End If + If h < 0 Then + Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + End If Return w * h End Function @@ -41,8 +45,12 @@ Namespace TwoDimensional ''' Umfang (2 * (w + h)) Public Shared Function Perimeter(w As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If w < 0 Then Throw New ArgumentException("Breite darf nicht negativ sein.", NameOf(w)) - If h < 0 Then Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + If w < 0 Then + Throw New ArgumentException("Breite darf nicht negativ sein.", NameOf(w)) + End If + If h < 0 Then + Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + End If Return 2.0 * (w + h) End Function @@ -66,7 +74,9 @@ Namespace TwoDimensional ''' Wenn h = 0 Public Shared Function AspectRatio(w As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If h = 0 Then Throw New ArgumentException("Höhe darf nicht 0 sein.", NameOf(h)) + If h = 0 Then + Throw New ArgumentException("Höhe darf nicht 0 sein.", NameOf(h)) + End If Return w / h End Function diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index 73c7e9a..c23ea67 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -28,8 +28,12 @@ Namespace TwoDimensional ''' Fläche baseLength * height Public Shared Function AreaFromBaseHeight(baseLength As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseLength < 0 Then Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(baseLength)) - If height < 0 Then Throw New ArgumentException("Die Höhe darf nicht negativ sein.", NameOf(height)) + If baseLength < 0 Then + Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(baseLength)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return baseLength * height End Function @@ -41,8 +45,12 @@ Namespace TwoDimensional ''' Fläche (d1 * d2) / 2 Public Shared Function AreaFromDiagonals(diagonal1 As Double, diagonal2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diagonal1 < 0 Then Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) - If diagonal2 < 0 Then Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + If diagonal1 < 0 Then + Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) + End If + If diagonal2 < 0 Then + Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (diagonal1 * diagonal2) / 2.0 #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -55,7 +63,9 @@ Namespace TwoDimensional ''' Umfang 4 * side Public Shared Function Perimeter(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(side)) + End If Return 4.0 * side End Function diff --git a/Geometry/TwoDimensional/Trapezoid.vb b/Geometry/TwoDimensional/Trapezoid.vb index 059cb10..0754eb8 100644 --- a/Geometry/TwoDimensional/Trapezoid.vb +++ b/Geometry/TwoDimensional/Trapezoid.vb @@ -29,9 +29,15 @@ Namespace TwoDimensional ''' Fläche ((a + c) / 2) * h Public Shared Function Area(baseA As Double, baseB As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseA < 0 Then Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) - If baseB < 0 Then Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) - If height < 0 Then Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(height)) + If baseA < 0 Then + Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + End If + If baseB < 0 Then + Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return ((baseA + baseB) / 2.0) * height @@ -48,10 +54,18 @@ Namespace TwoDimensional ''' Umfang a + b + c + d Public Shared Function Perimeter(baseA As Double, legB As Double, baseC As Double, legD As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseA <= 0 Then Throw New ArgumentException("Grundseite a muss größer als 0 sein.", NameOf(baseA)) - If legB <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(legB)) - If baseC <= 0 Then Throw New ArgumentException("Grundseite c muss größer als 0 sein.", NameOf(baseC)) - If legD <= 0 Then Throw New ArgumentException("Seite d muss größer als 0 sein.", NameOf(legD)) + If baseA <= 0 Then + Throw New ArgumentException("Grundseite a muss größer als 0 sein.", NameOf(baseA)) + End If + If legB <= 0 Then + Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(legB)) + End If + If baseC <= 0 Then + Throw New ArgumentException("Grundseite c muss größer als 0 sein.", NameOf(baseC)) + End If + If legD <= 0 Then + Throw New ArgumentException("Seite d muss größer als 0 sein.", NameOf(legD)) + End If Return baseA + legB + baseC + legD End Function @@ -100,9 +114,15 @@ Namespace TwoDimensional ''' Schenkellänge Public Shared Function LegLengthIsosceles(baseA As Double, baseB As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseA < 0 Then Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) - If baseB < 0 Then Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) - If height < 0 Then Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(height)) + If baseA < 0 Then + Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + End If + If baseB < 0 Then + Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim halfDiff = Math.Abs(baseA - baseB) / 2.0 Return Math.Sqrt((halfDiff * halfDiff) + (height * height)) @@ -117,9 +137,15 @@ Namespace TwoDimensional ''' True, wenn |b-d| innerhalb der Toleranz liegt Public Shared Function IsIsosceles(legB As Double, legD As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If legB <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(legB)) - If legD <= 0 Then Throw New ArgumentException("Seite d muss größer als 0 sein.", NameOf(legD)) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If legB <= 0 Then + Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(legB)) + End If + If legD <= 0 Then + Throw New ArgumentException("Seite d muss größer als 0 sein.", NameOf(legD)) + End If + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Return Math.Abs(legB - legD) <= tolerance End Function diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index 8e60c2d..efeb502 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -28,8 +28,12 @@ Namespace TwoDimensional ''' Fläche b * h / 2 Public Shared Function Area(b As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If b < 0 Then Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) - If h < 0 Then Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + If b < 0 Then + Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) + End If + If h < 0 Then + Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (b * h) / 2.0 @@ -57,8 +61,12 @@ Namespace TwoDimensional ''' Höhe 2 * area / b Public Shared Function HeightFromArea(area As Double, b As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If area < 0 Then Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) - If b <= 0 Then Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) + If area < 0 Then + Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) + End If + If b <= 0 Then + Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (2.0 * area) / b From d3194bce071c7fe7c28e7cd3c9d6cdf4f4974a9c Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:51:55 +0200 Subject: [PATCH 10/22] Guard-Clauses vereinheitlicht MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guard-Clauses in mehreren 2D- und 3D-Geometrieklassen auf konsistente Mehrzeilen-If-Then-End If-Blöcke umgestellt und harte Textmeldungen durch My.Resources-Meldungen ersetzt. --- Geometry/ThreeDimensional/Cone.vb | 32 +++++-- Geometry/ThreeDimensional/Cube.vb | 32 +++++-- Geometry/ThreeDimensional/Cuboid.vb | 100 ++++++++++++++++------ Geometry/ThreeDimensional/Cylinder.vb | 12 ++- Geometry/ThreeDimensional/Frustum.vb | 20 +++-- Geometry/ThreeDimensional/Prism.vb | 10 ++- Geometry/ThreeDimensional/Pyramid.vb | 36 ++++---- Geometry/ThreeDimensional/Sphere.vb | 2 +- Geometry/TwoDimensional/Circle.vb | 8 +- Geometry/TwoDimensional/Kite.vb | 36 ++++++-- Geometry/TwoDimensional/Parallelogram.vb | 72 ++++++++++++---- Geometry/TwoDimensional/Polygon.vb | 16 +++- Geometry/TwoDimensional/Rectangle.vb | 20 +++-- Geometry/TwoDimensional/RegularPolygon.vb | 36 ++++++-- Geometry/TwoDimensional/Rhombus.vb | 40 ++++++--- Geometry/TwoDimensional/Square.vb | 40 ++++++--- Geometry/TwoDimensional/Trapezoid.vb | 48 ++++++++--- Geometry/TwoDimensional/Triangle.vb | 26 ++++-- 18 files changed, 428 insertions(+), 158 deletions(-) diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index 88dddad..45f253c 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -129,7 +129,9 @@ Namespace ThreeDimensional Public Shared Function FrustumVolume(radiusBottom As Double, radiusTop As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * height / 3.0) * ((radiusBottom * radiusBottom) + (radiusBottom * radiusTop) + (radiusTop * radiusTop)) #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -145,7 +147,9 @@ Namespace ThreeDimensional Public Shared Function FrustumLateralArea(radiusBottom As Double, radiusTop As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim s = Math.Sqrt(((radiusBottom - radiusTop) * (radiusBottom - radiusTop)) + (height * height)) Return Math.PI * (radiusBottom + radiusTop) * s End Function @@ -160,7 +164,9 @@ Namespace ThreeDimensional Public Shared Function FrustumSurfaceArea(radiusBottom As Double, radiusTop As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim lateral = FrustumLateralArea(radiusBottom, radiusTop, height) Dim bases = Math.PI * ((radiusBottom * radiusBottom) + (radiusTop * radiusTop)) Return lateral + bases @@ -187,8 +193,12 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) - If t < 0 OrElse t > 1 Then Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If + If t < 0 OrElse t > 1 Then + Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) + End If Dim currentRadius = radius * (1.0 - t) Dim x = centerX + (currentRadius * Math.Cos(angleRadians)) @@ -203,9 +213,15 @@ Namespace ThreeDimensional Private Shared Sub ValidateFrustumRadii(radiusBottom As Double, radiusTop As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radiusBottom <= 0 Then Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(radiusBottom)) - If radiusTop < 0 Then Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(radiusTop)) - If radiusTop >= radiusBottom Then Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(radiusTop)) + If radiusBottom <= 0 Then + Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(radiusBottom)) + End If + If radiusTop < 0 Then + Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(radiusTop)) + End If + If radiusTop >= radiusBottom Then + Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(radiusTop)) + End If End Sub #End Region diff --git a/Geometry/ThreeDimensional/Cube.vb b/Geometry/ThreeDimensional/Cube.vb index 935b465..e06a1bd 100644 --- a/Geometry/ThreeDimensional/Cube.vb +++ b/Geometry/ThreeDimensional/Cube.vb @@ -25,7 +25,9 @@ Namespace ThreeDimensional ''' Volumen side^3 Public Shared Function Volume(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Die Kantenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side * side * side End Function @@ -36,7 +38,9 @@ Namespace ThreeDimensional ''' Oberfläche 6 * side^2 Public Shared Function SurfaceArea(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Die Kantenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return 6.0 * side * side End Function @@ -47,7 +51,9 @@ Namespace ThreeDimensional ''' Raumdiagonale side * sqrt(3) Public Shared Function SpaceDiagonal(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Die Kantenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side * Math.Sqrt(3.0) End Function @@ -58,7 +64,9 @@ Namespace ThreeDimensional ''' Flächendiagonale side * sqrt(2) Public Shared Function FaceDiagonal(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Die Kantenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side * Math.Sqrt(2.0) End Function @@ -69,7 +77,9 @@ Namespace ThreeDimensional ''' Kantenlänge cubic-root(volume) Public Shared Function SideFromVolume(volume As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If volume < 0 Then Throw New ArgumentException("Das Volumen darf nicht negativ sein.", NameOf(volume)) + If volume < 0 Then + Throw New ArgumentException("Das Volumen darf nicht negativ sein.", NameOf(volume)) + End If Return Math.Pow(volume, 1.0 / 3.0) End Function @@ -80,7 +90,9 @@ Namespace ThreeDimensional ''' Kantenlänge sqrt(surfaceArea / 6) Public Shared Function SideFromSurfaceArea(surfaceArea As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If surfaceArea < 0 Then Throw New ArgumentException("Die Oberfläche darf nicht negativ sein.", NameOf(surfaceArea)) + If surfaceArea < 0 Then + Throw New ArgumentException("Die Oberfläche darf nicht negativ sein.", NameOf(surfaceArea)) + End If Return Math.Sqrt(surfaceArea / 6.0) End Function @@ -91,7 +103,9 @@ Namespace ThreeDimensional ''' Kantenlänge spaceDiagonal / sqrt(3) Public Shared Function SideFromSpaceDiagonal(spaceDiagonal As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If spaceDiagonal < 0 Then Throw New ArgumentException("Die Raumdiagonale darf nicht negativ sein.", NameOf(spaceDiagonal)) + If spaceDiagonal < 0 Then + Throw New ArgumentException("Die Raumdiagonale darf nicht negativ sein.", NameOf(spaceDiagonal)) + End If Return spaceDiagonal / Math.Sqrt(3.0) End Function @@ -124,7 +138,9 @@ Namespace ThreeDimensional ''' Array mit 8 Eckpunkten als Tuple(X,Y,Z) Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, side As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Die Kantenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Dim h = side / 2.0 Return New Tuple(Of Double, Double, Double)() { diff --git a/Geometry/ThreeDimensional/Cuboid.vb b/Geometry/ThreeDimensional/Cuboid.vb index 40b4f41..47dcd72 100644 --- a/Geometry/ThreeDimensional/Cuboid.vb +++ b/Geometry/ThreeDimensional/Cuboid.vb @@ -27,9 +27,15 @@ Namespace ThreeDimensional ''' Volumen length * width * height Public Shared Function Volume(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return length * width * height End Function @@ -43,9 +49,15 @@ Namespace ThreeDimensional ''' Oberfläche 2 * (lw + lh + wh) Public Shared Function SurfaceArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return 2.0 * ((length * width) + (length * height) + (width * height)) End Function @@ -59,9 +71,15 @@ Namespace ThreeDimensional ''' Raumdiagonale sqrt(l^2 + w^2 + h^2) Public Shared Function SpaceDiagonal(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return Math.Sqrt((length * length) + (width * width) + (height * height)) End Function @@ -74,8 +92,12 @@ Namespace ThreeDimensional ''' Flächendiagonale sqrt(l^2 + w^2) Public Shared Function FaceDiagonalLengthWidth(length As Double, width As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If Return Math.Sqrt((length * length) + (width * width)) End Function @@ -87,8 +109,12 @@ Namespace ThreeDimensional ''' Flächendiagonale sqrt(l^2 + h^2) Public Shared Function FaceDiagonalLengthHeight(length As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return Math.Sqrt((length * length) + (height * height)) End Function @@ -100,8 +126,12 @@ Namespace ThreeDimensional ''' Flächendiagonale sqrt(w^2 + h^2) Public Shared Function FaceDiagonalWidthHeight(width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Return Math.Sqrt((width * width) + (height * height)) End Function @@ -114,9 +144,15 @@ Namespace ThreeDimensional ''' Fehlende Kante volume / (edge1 * edge2) Public Shared Function EdgeFromVolume(volume As Double, edge1 As Double, edge2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If volume < 0 Then Throw New ArgumentException("Das Volumen darf nicht negativ sein.", NameOf(volume)) - If edge1 <= 0 Then Throw New ArgumentException("Kante 1 muss größer als 0 sein.", NameOf(edge1)) - If edge2 <= 0 Then Throw New ArgumentException("Kante 2 muss größer als 0 sein.", NameOf(edge2)) + If volume < 0 Then + Throw New ArgumentException("Das Volumen darf nicht negativ sein.", NameOf(volume)) + End If + If edge1 <= 0 Then + Throw New ArgumentException("Kante 1 muss größer als 0 sein.", NameOf(edge1)) + End If + If edge2 <= 0 Then + Throw New ArgumentException("Kante 2 muss größer als 0 sein.", NameOf(edge2)) + End If Return volume / (edge1 * edge2) End Function @@ -130,10 +166,18 @@ Namespace ThreeDimensional ''' True, wenn alle drei Kanten innerhalb der Toleranz gleich sind Public Shared Function IsCube(length As Double, width As Double, height As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Return Math.Abs(length - width) <= tolerance AndAlso Math.Abs(length - height) <= tolerance End Function @@ -169,9 +213,15 @@ Namespace ThreeDimensional ''' Array mit 8 Eckpunkten als Tuple(X,Y,Z) Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, length As Double, width As Double, height As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) - If width < 0 Then Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If Dim lx = length / 2.0 Dim wy = width / 2.0 diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index cb336bc..d5bb815 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -201,9 +201,15 @@ Namespace ThreeDimensional Private Shared Sub ValidateHollowRadii(outerRadius As Double, innerRadius As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If outerRadius <= 0 Then Throw New ArgumentException("Der Außenradius muss größer als 0 sein.", NameOf(outerRadius)) - If innerRadius < 0 Then Throw New ArgumentException("Der Innenradius darf nicht negativ sein.", NameOf(innerRadius)) - If innerRadius >= outerRadius Then Throw New ArgumentException("Der Innenradius muss kleiner als der Außenradius sein.", NameOf(innerRadius)) + If outerRadius <= 0 Then + Throw New ArgumentException("Der Außenradius muss größer als 0 sein.", NameOf(outerRadius)) + End If + If innerRadius < 0 Then + Throw New ArgumentException("Der Innenradius darf nicht negativ sein.", NameOf(innerRadius)) + End If + If innerRadius >= outerRadius Then + Throw New ArgumentException("Der Innenradius muss kleiner als der Außenradius sein.", NameOf(innerRadius)) + End If End Sub #End Region diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index e3416a1..a563c9f 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -206,10 +206,18 @@ Namespace ThreeDimensional Private Shared Sub ValidateConeFrustumInputs(bottomRadius As Double, topRadius As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If bottomRadius <= 0 Then Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(bottomRadius)) - If topRadius < 0 Then Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(topRadius)) - If topRadius >= bottomRadius Then Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(topRadius)) - If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + If bottomRadius <= 0 Then + Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(bottomRadius)) + End If + If topRadius < 0 Then + Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(topRadius)) + End If + If topRadius >= bottomRadius Then + Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(topRadius)) + End If + If height < 0 Then + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + End If End Sub Private Shared Sub ValidatePyramidFrustumInputs(bottomLength As Double, bottomWidth As Double, topLength As Double, topWidth As Double, height As Double) @@ -221,10 +229,10 @@ Namespace ThreeDimensional Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) End If If topLength < 0 Then - Throw New ArgumentException("Die obere Grundlänge darf nicht negativ sein.", NameOf(topLength)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(topLength)) End If If topWidth < 0 Then - Throw New ArgumentException("Die obere Grundbreite darf nicht negativ sein.", NameOf(topWidth)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(topWidth)) End If If topLength >= bottomLength Then Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere sein.", NameOf(topLength)) diff --git a/Geometry/ThreeDimensional/Prism.vb b/Geometry/ThreeDimensional/Prism.vb index 4f8beb7..6e41e99 100644 --- a/Geometry/ThreeDimensional/Prism.vb +++ b/Geometry/ThreeDimensional/Prism.vb @@ -135,7 +135,7 @@ Namespace ThreeDimensional Public Shared Function RegularPolygonBaseArea(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideLength < 0 Then - Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(sideLength)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) End If ValidateSideCount(sideCount) @@ -190,7 +190,9 @@ Namespace ThreeDimensional If sideB <= 0 Then Throw New ArgumentException("Seite B muss größer als 0 sein.", NameOf(sideB)) End If - If sideC <= 0 Then Throw New ArgumentException("Seite C muss größer als 0 sein.", NameOf(sideC)) + If sideC <= 0 Then + Throw New ArgumentException("Seite C muss größer als 0 sein.", NameOf(sideC)) + End If If sideA + sideB <= sideC OrElse sideA + sideC <= sideB OrElse sideB + sideC <= sideA Then Throw New ArgumentException("Die Seiten erfüllen die Dreiecksungleichung nicht.", NameOf(sideC)) @@ -199,7 +201,9 @@ Namespace ThreeDimensional Private Shared Sub ValidateSideCount(sideCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideCount < 3 Then Throw New ArgumentException("Die Seitenanzahl muss größer oder gleich 3 sein.", NameOf(sideCount)) + If sideCount < 3 Then + Throw New ArgumentException("Die Seitenanzahl muss größer oder gleich 3 sein.", NameOf(sideCount)) + End If End Sub #End Region diff --git a/Geometry/ThreeDimensional/Pyramid.vb b/Geometry/ThreeDimensional/Pyramid.vb index d783bde..bbee22c 100644 --- a/Geometry/ThreeDimensional/Pyramid.vb +++ b/Geometry/ThreeDimensional/Pyramid.vb @@ -26,8 +26,12 @@ Namespace ThreeDimensional ''' Grundfläche length * width Public Shared Function BaseArea(length As Double, width As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If length < 0 Then Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) - If width < 0 Then Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + If length < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + End If + If width < 0 Then + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + End If Return length * width End Function @@ -41,10 +45,10 @@ Namespace ThreeDimensional Public Shared Function Volume(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -64,7 +68,7 @@ Namespace ThreeDimensional Public Shared Function SlantHeightLengthFace(width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If width < 0 Then - Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -83,7 +87,7 @@ Namespace ThreeDimensional Public Shared Function SlantHeightWidthFace(length As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -103,10 +107,10 @@ Namespace ThreeDimensional Public Shared Function LateralArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -127,10 +131,10 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -231,10 +235,10 @@ Namespace ThreeDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, length As Double, width As Double, height As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException("Die Grundlänge darf nicht negativ sein.", NameOf(length)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException("Die Grundbreite darf nicht negativ sein.", NameOf(width)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -259,15 +263,17 @@ Namespace ThreeDimensional Private Shared Sub ValidateFrustumInputs(bottomLength As Double, bottomWidth As Double, topLength As Double, topWidth As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If bottomLength <= 0 Then Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) + If bottomLength <= 0 Then + Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) + End If If bottomWidth <= 0 Then Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) End If If topLength < 0 Then - Throw New ArgumentException("Die obere Grundlänge darf nicht negativ sein.", NameOf(topLength)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(topLength)) End If If topWidth < 0 Then - Throw New ArgumentException("Die obere Grundbreite darf nicht negativ sein.", NameOf(topWidth)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(topWidth)) End If If topLength >= bottomLength Then Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere Grundlänge sein.", NameOf(topLength)) diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 88f0999..06c59fd 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -168,7 +168,7 @@ Namespace ThreeDimensional Throw New ArgumentException("Der Radius muss größer als 0 sein.", NameOf(radius)) End If If capHeight < 0 Then - Throw New ArgumentException("Die Kappenhöhe darf nicht negativ sein.", NameOf(capHeight)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(capHeight)) End If If capHeight > 2.0 * radius Then Throw New ArgumentException("Die Kappenhöhe darf maximal 2 * Radius sein.", NameOf(capHeight)) diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index 74731b2..e34c8c3 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -174,7 +174,9 @@ Namespace TwoDimensional If radius < 0 Then Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If - If sagitta < 0 Or sagitta > radius Then Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) + If sagitta < 0 Or sagitta > radius Then + Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) + End If ' Abstand vom Mittelpunkt zur Sehne (h) = radius - sagitta Dim h As Double = radius - sagitta @@ -208,7 +210,9 @@ Namespace TwoDimensional If radius <= 0 Then Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) End If - If chordLength < 0 OrElse chordLength > 2.0 * radius Then Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) + If chordLength < 0 OrElse chordLength > 2.0 * radius Then + Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) + End If ' chord = 2 radius sin(theta/2) => theta = 2 * asin(chord/(2*radius)) Return 2.0 * Math.Asin(chordLength / (2.0 * radius)) End Function diff --git a/Geometry/TwoDimensional/Kite.vb b/Geometry/TwoDimensional/Kite.vb index e227824..fa083ef 100644 --- a/Geometry/TwoDimensional/Kite.vb +++ b/Geometry/TwoDimensional/Kite.vb @@ -28,8 +28,12 @@ Namespace TwoDimensional ''' Fläche (d1 * d2) / 2 Public Shared Function AreaFromDiagonals(diagonal1 As Double, diagonal2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diagonal1 < 0 Then Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) - If diagonal2 < 0 Then Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + If diagonal1 < 0 Then + Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) + End If + If diagonal2 < 0 Then + Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (diagonal1 * diagonal2) / 2.0 #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -43,8 +47,12 @@ Namespace TwoDimensional ''' Umfang 2 * (sideA + sideB) Public Shared Function Perimeter(sideA As Double, sideB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideA < 0 Then Throw New ArgumentException("Seitenlänge A darf nicht negativ sein.", NameOf(sideA)) - If sideB < 0 Then Throw New ArgumentException("Seitenlänge B darf nicht negativ sein.", NameOf(sideB)) + If sideA < 0 Then + Throw New ArgumentException("Seitenlänge A darf nicht negativ sein.", NameOf(sideA)) + End If + If sideB < 0 Then + Throw New ArgumentException("Seitenlänge B darf nicht negativ sein.", NameOf(sideB)) + End If Return 2.0 * (sideA + sideB) End Function @@ -129,8 +137,12 @@ Namespace TwoDimensional ''' Array mit 4 Eckpunkten in umlaufender Reihenfolge Public Shared Function VerticesFromCenter(cx As Double, cy As Double, diagonal1 As Double, diagonal2 As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diagonal1 < 0 Then Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) - If diagonal2 < 0 Then Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + If diagonal1 < 0 Then + Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) + End If + If diagonal2 < 0 Then + Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + End If Dim halfD1 = diagonal1 / 2.0 Dim halfD2 = diagonal2 / 2.0 @@ -196,7 +208,9 @@ Namespace TwoDimensional Public Shared Function IsKiteFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim l0 = Distance(vertices(0), vertices(1)) Dim l1 = Distance(vertices(1), vertices(2)) @@ -214,8 +228,12 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length <> 4 Then Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length <> 4 Then + Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + End If End Sub Private Shared Function Distance(p1 As PointF, p2 As PointF) As Double diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index 16605fb..b1cb964 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -86,9 +86,15 @@ Namespace TwoDimensional ''' Fehlende Seitenlänge Public Shared Function SideFromPerimeter(perimeter As Double, knownSide As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If perimeter < 0 Then Throw New ArgumentException("Umfang darf nicht negativ sein.", NameOf(perimeter)) - If knownSide < 0 Then Throw New ArgumentException("Bekannte Seite darf nicht negativ sein.", NameOf(knownSide)) - If perimeter <= 2.0 * knownSide Then Throw New ArgumentException("Umfang ist für die angegebene Seite zu klein.", NameOf(perimeter)) + If perimeter < 0 Then + Throw New ArgumentException("Umfang darf nicht negativ sein.", NameOf(perimeter)) + End If + If knownSide < 0 Then + Throw New ArgumentException("Bekannte Seite darf nicht negativ sein.", NameOf(knownSide)) + End If + If perimeter <= 2.0 * knownSide Then + Throw New ArgumentException("Umfang ist für die angegebene Seite zu klein.", NameOf(perimeter)) + End If Return (perimeter / 2.0) - knownSide End Function @@ -102,8 +108,12 @@ Namespace TwoDimensional ''' Array mit zwei Diagonalen: [|u+v|, |u-v|] Public Shared Function DiagonalBySidesAndAngle(a As Double, b As Double, includedAngleRadians As Double) As Double() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If a <= 0 Then Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) - If b <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + If a <= 0 Then + Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + End If + If b <= 0 Then + Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + End If If includedAngleRadians <= 0 OrElse includedAngleRadians >= Math.PI Then Throw New ArgumentException("Der eingeschlossene Winkel muss zwischen 0 und PI liegen.", NameOf(includedAngleRadians)) End If @@ -125,10 +135,18 @@ Namespace TwoDimensional ''' Innenwinkel im Bogenmaß Public Shared Function InteriorAngleFromSidesAndDiagonals(a As Double, b As Double, d1 As Double, d2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If a <= 0 Then Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) - If b <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) - If d1 <= 0 Then Throw New ArgumentException("Diagonale d1 muss größer als 0 sein.", NameOf(d1)) - If d2 <= 0 Then Throw New ArgumentException("Diagonale d2 muss größer als 0 sein.", NameOf(d2)) + If a <= 0 Then + Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + End If + If b <= 0 Then + Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + End If + If d1 <= 0 Then + Throw New ArgumentException("Diagonale d1 muss größer als 0 sein.", NameOf(d1)) + End If + If d2 <= 0 Then + Throw New ArgumentException("Diagonale d2 muss größer als 0 sein.", NameOf(d2)) + End If Dim denominator = 4.0 * a * b Dim cosValue = ((d1 * d1) - (d2 * d2)) / denominator @@ -169,8 +187,12 @@ Namespace TwoDimensional ''' Array mit 4 Eckpunkten in umlaufender Reihenfolge Public Shared Function VerticesFromCenter(cx As Double, cy As Double, a As Double, b As Double, includedAngleRadians As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If a <= 0 Then Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) - If b <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + If a <= 0 Then + Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + End If + If b <= 0 Then + Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + End If If includedAngleRadians <= 0 OrElse includedAngleRadians >= Math.PI Then Throw New ArgumentException("Der eingeschlossene Winkel muss zwischen 0 und PI liegen.", NameOf(includedAngleRadians)) End If @@ -199,8 +221,12 @@ Namespace TwoDimensional ''' Polygonfläche Public Shared Function AreaFromVertices(vertices As PointF()) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length < 3 Then Throw New ArgumentException("Es müssen mindestens 3 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length < 3 Then + Throw New ArgumentException("Es müssen mindestens 3 Eckpunkte angegeben werden.", NameOf(vertices)) + End If Dim sum As Double = 0.0 For i = 0 To vertices.Length - 1 @@ -218,8 +244,12 @@ Namespace TwoDimensional ''' Umfang als Summe der Kantenlängen Public Shared Function PerimeterFromVertices(vertices As PointF()) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length < 2 Then Throw New ArgumentException("Es müssen mindestens 2 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length < 2 Then + Throw New ArgumentException("Es müssen mindestens 2 Eckpunkte angegeben werden.", NameOf(vertices)) + End If Dim perimeter As Double = 0.0 For i = 0 To vertices.Length - 1 @@ -240,9 +270,15 @@ Namespace TwoDimensional ''' True, wenn die Diagonalen denselben Mittelpunkt besitzen Public Shared Function IsParallelogramFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length <> 4 Then Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length <> 4 Then + Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + End If + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim midpointDiagonal1 = Center(vertices(0).X, vertices(0).Y, vertices(2).X, vertices(2).Y) Dim midpointDiagonal2 = Center(vertices(1).X, vertices(1).Y, vertices(3).X, vertices(3).Y) diff --git a/Geometry/TwoDimensional/Polygon.vb b/Geometry/TwoDimensional/Polygon.vb index b571c4b..c5aeb41 100644 --- a/Geometry/TwoDimensional/Polygon.vb +++ b/Geometry/TwoDimensional/Polygon.vb @@ -65,7 +65,9 @@ Namespace TwoDimensional Public Shared Function IsConvex(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices, 3) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim hasPositive As Boolean = False Dim hasNegative As Boolean = False @@ -96,7 +98,9 @@ Namespace TwoDimensional Public Shared Function IsRegular(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices, 3) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If If Not IsConvex(vertices, tolerance) Then Return False Dim firstSide = Distance(vertices(0), vertices(1)) @@ -221,8 +225,12 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF(), minCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length < minCount Then Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length < minCount Then + Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte angegeben werden.", NameOf(vertices)) + End If End Sub Private Shared Function CrossZ(p0 As PointF, p1 As PointF, p2 As PointF) As Double diff --git a/Geometry/TwoDimensional/Rectangle.vb b/Geometry/TwoDimensional/Rectangle.vb index cf8b64b..822b67b 100644 --- a/Geometry/TwoDimensional/Rectangle.vb +++ b/Geometry/TwoDimensional/Rectangle.vb @@ -29,10 +29,10 @@ Namespace TwoDimensional Public Shared Function Area(w As Double, h As Double) As Double ' Guard-Clauses: negative Werte sind nicht erlaubt If w < 0 Then - Throw New ArgumentException("Breite darf nicht negativ sein.", NameOf(w)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(w)) End If If h < 0 Then - Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) End If Return w * h End Function @@ -46,10 +46,10 @@ Namespace TwoDimensional Public Shared Function Perimeter(w As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If w < 0 Then - Throw New ArgumentException("Breite darf nicht negativ sein.", NameOf(w)) + Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(w)) End If If h < 0 Then - Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) End If Return 2.0 * (w + h) End Function @@ -255,7 +255,9 @@ Namespace TwoDimensional ''' Public Shared Function AreaSquare(s As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If s < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(s)) + If s < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(s)) + End If Return s * s End Function @@ -264,7 +266,9 @@ Namespace TwoDimensional ''' Public Shared Function PerimeterSquare(s As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If s < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(s)) + If s < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(s)) + End If Return 4.0 * s End Function @@ -281,7 +285,9 @@ Namespace TwoDimensional ''' Public Shared Function FromDiagonalToSide(d As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If d < 0 Then Throw New ArgumentException("Diagonale darf nicht negativ sein.", NameOf(d)) + If d < 0 Then + Throw New ArgumentException("Diagonale darf nicht negativ sein.", NameOf(d)) + End If Return d / Math.Sqrt(2.0) End Function diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index 7d1be71..9d708e0 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -28,7 +28,9 @@ Namespace TwoDimensional ''' Umfang sideCount * sideLength Public Shared Function Perimeter(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideLength < 0 Then Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(sideLength)) + If sideLength < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + End If ValidateSideCount(sideCount) Return sideCount * sideLength End Function @@ -67,7 +69,9 @@ Namespace TwoDimensional ''' Apothem sideLength / (2*tan(PI/n)) Public Shared Function Apothem(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideLength < 0 Then Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(sideLength)) + If sideLength < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + End If ValidateSideCount(sideCount) If sideLength = 0 Then Return 0 @@ -82,7 +86,9 @@ Namespace TwoDimensional ''' Umkreisradius sideLength / (2*sin(PI/n)) Public Shared Function Circumradius(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideLength < 0 Then Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(sideLength)) + If sideLength < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + End If ValidateSideCount(sideCount) If sideLength = 0 Then Return 0 @@ -110,7 +116,9 @@ Namespace TwoDimensional ''' Seitenlänge perimeter / sideCount Public Shared Function SideLengthFromPerimeter(perimeter As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If perimeter < 0 Then Throw New ArgumentException("Der Umfang darf nicht negativ sein.", NameOf(perimeter)) + If perimeter < 0 Then + Throw New ArgumentException("Der Umfang darf nicht negativ sein.", NameOf(perimeter)) + End If ValidateSideCount(sideCount) Return perimeter / sideCount End Function @@ -131,7 +139,9 @@ Namespace TwoDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, sideCount As Integer, circumradius As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateSideCount(sideCount) - If circumradius < 0 Then Throw New ArgumentException("Der Umkreisradius darf nicht negativ sein.", NameOf(circumradius)) + If circumradius < 0 Then + Throw New ArgumentException("Der Umkreisradius darf nicht negativ sein.", NameOf(circumradius)) + End If Dim result(sideCount - 1) As PointF #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -193,7 +203,9 @@ Namespace TwoDimensional Public Shared Function IsRegularFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices, 3) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If If AreaFromVertices(vertices) <= tolerance Then Return False @@ -222,13 +234,19 @@ Namespace TwoDimensional Private Shared Sub ValidateSideCount(sideCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If sideCount < 3 Then Throw New ArgumentException("Die Seitenanzahl muss größer oder gleich 3 sein.", NameOf(sideCount)) + If sideCount < 3 Then + Throw New ArgumentException("Die Seitenanzahl muss größer oder gleich 3 sein.", NameOf(sideCount)) + End If End Sub Private Shared Sub ValidateVertices(vertices As PointF(), minCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length < minCount Then Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte vorhanden sein.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length < minCount Then + Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte vorhanden sein.", NameOf(vertices)) + End If End Sub Private Shared Function AverageCenter(vertices As PointF()) As PointF diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index c23ea67..77e45da 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -29,7 +29,7 @@ Namespace TwoDimensional Public Shared Function AreaFromBaseHeight(baseLength As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseLength < 0 Then - Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(baseLength)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(baseLength)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -64,7 +64,7 @@ Namespace TwoDimensional Public Shared Function Perimeter(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException("Die Seitenlänge darf nicht negativ sein.", NameOf(side)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) End If Return 4.0 * side End Function @@ -77,8 +77,12 @@ Namespace TwoDimensional ''' Höhe area / side Public Shared Function HeightFromArea(area As Double, side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If area < 0 Then Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) - If side <= 0 Then Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + If area < 0 Then + Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) + End If + If side <= 0 Then + Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + End If Return area / side End Function @@ -90,7 +94,9 @@ Namespace TwoDimensional ''' Array [d1, d2] Public Shared Function DiagonalFromSideAndAngle(side As Double, interiorAngleRadians As Double) As Double() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side <= 0 Then Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + If side <= 0 Then + Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + End If If interiorAngleRadians <= 0 OrElse interiorAngleRadians >= Math.PI Then Throw New ArgumentException("Der Innenwinkel muss zwischen 0 und PI liegen.", NameOf(interiorAngleRadians)) End If @@ -109,8 +115,12 @@ Namespace TwoDimensional ''' Inkreisradius 2 * area / perimeter Public Shared Function InradiusFromAreaPerimeter(area As Double, perimeter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If area < 0 Then Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) - If perimeter <= 0 Then Throw New ArgumentException("Der Umfang muss größer als 0 sein.", NameOf(perimeter)) + If area < 0 Then + Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) + End If + If perimeter <= 0 Then + Throw New ArgumentException("Der Umfang muss größer als 0 sein.", NameOf(perimeter)) + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (2.0 * area) / perimeter #Enable Warning IDE0047 ' Unnötige Klammern entfernen @@ -131,7 +141,9 @@ Namespace TwoDimensional ''' Array mit 4 Eckpunkten in umlaufender Reihenfolge Public Shared Function VerticesFromCenter(cx As Double, cy As Double, side As Double, interiorAngleRadians As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side <= 0 Then Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + If side <= 0 Then + Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + End If If interiorAngleRadians <= 0 OrElse interiorAngleRadians >= Math.PI Then Throw New ArgumentException("Der Innenwinkel muss zwischen 0 und PI liegen.", NameOf(interiorAngleRadians)) End If @@ -193,7 +205,9 @@ Namespace TwoDimensional Public Shared Function IsRhombusFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim lengths(3) As Double For i = 0 To 3 @@ -215,8 +229,12 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length <> 4 Then Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length <> 4 Then + Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + End If End Sub Private Shared Function Distance(p1 As PointF, p2 As PointF) As Double diff --git a/Geometry/TwoDimensional/Square.vb b/Geometry/TwoDimensional/Square.vb index c1692b5..3c4e90b 100644 --- a/Geometry/TwoDimensional/Square.vb +++ b/Geometry/TwoDimensional/Square.vb @@ -27,7 +27,9 @@ Namespace TwoDimensional ''' Fläche side * side Public Shared Function Area(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side * side End Function @@ -38,7 +40,9 @@ Namespace TwoDimensional ''' Umfang 4 * side Public Shared Function Perimeter(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return 4.0 * side End Function @@ -49,7 +53,9 @@ Namespace TwoDimensional ''' Diagonale side * sqrt(2) Public Shared Function Diagonal(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side * Math.Sqrt(2.0) End Function @@ -60,7 +66,9 @@ Namespace TwoDimensional ''' Seitenlänge diagonal / sqrt(2) Public Shared Function SideFromDiagonal(diagonal As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If diagonal < 0 Then Throw New ArgumentException("Diagonale darf nicht negativ sein.", NameOf(diagonal)) + If diagonal < 0 Then + Throw New ArgumentException("Diagonale darf nicht negativ sein.", NameOf(diagonal)) + End If Return diagonal / Math.Sqrt(2.0) End Function @@ -71,7 +79,9 @@ Namespace TwoDimensional ''' Inkreisradius side / 2 Public Shared Function Inradius(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side / 2.0 End Function @@ -82,7 +92,9 @@ Namespace TwoDimensional ''' Umkreisradius side / sqrt(2) Public Shared Function Circumradius(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Return side / Math.Sqrt(2.0) End Function @@ -100,7 +112,9 @@ Namespace TwoDimensional ''' Array mit 4 Eckpunkten im Uhrzeigersinn Public Shared Function VerticesFromCenter(cx As Double, cy As Double, side As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If side < 0 Then Throw New ArgumentException("Seitenlänge darf nicht negativ sein.", NameOf(side)) + If side < 0 Then + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + End If Dim halfSide = side / 2.0 Dim local As PointF() = { @@ -168,7 +182,9 @@ Namespace TwoDimensional Public Shared Function IsSquareFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim lengths(3) As Double For i = 0 To 3 @@ -205,8 +221,12 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length <> 4 Then Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length <> 4 Then + Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + End If End Sub Private Shared Function Distance(p1 As PointF, p2 As PointF) As Double diff --git a/Geometry/TwoDimensional/Trapezoid.vb b/Geometry/TwoDimensional/Trapezoid.vb index 0754eb8..31b3c1f 100644 --- a/Geometry/TwoDimensional/Trapezoid.vb +++ b/Geometry/TwoDimensional/Trapezoid.vb @@ -78,8 +78,12 @@ Namespace TwoDimensional ''' Mittellinie (a + c) / 2 Public Shared Function Midline(baseA As Double, baseB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseA < 0 Then Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) - If baseB < 0 Then Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + If baseA < 0 Then + Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + End If + If baseB < 0 Then + Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + End If Return (baseA + baseB) / 2.0 End Function @@ -93,12 +97,20 @@ Namespace TwoDimensional ''' Höhe Public Shared Function HeightFromArea(area As Double, baseA As Double, baseB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If area < 0 Then Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) - If baseA < 0 Then Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) - If baseB < 0 Then Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + If area < 0 Then + Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) + End If + If baseA < 0 Then + Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + End If + If baseB < 0 Then + Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + End If Dim denominator = baseA + baseB - If denominator <= 0 Then Throw New ArgumentException("Die Summe der Grundseiten muss größer als 0 sein.") + If denominator <= 0 Then + Throw New ArgumentException("Die Summe der Grundseiten muss größer als 0 sein.") + End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (2.0 * area) / denominator @@ -166,9 +178,15 @@ Namespace TwoDimensional ''' Array mit 4 Eckpunkten im Uhrzeigersinn Public Shared Function VerticesFromCenter(cx As Double, cy As Double, baseA As Double, baseB As Double, height As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If baseA <= 0 Then Throw New ArgumentException("Grundseite a muss größer als 0 sein.", NameOf(baseA)) - If baseB <= 0 Then Throw New ArgumentException("Grundseite c muss größer als 0 sein.", NameOf(baseB)) - If height <= 0 Then Throw New ArgumentException("Höhe muss größer als 0 sein.", NameOf(height)) + If baseA <= 0 Then + Throw New ArgumentException("Grundseite a muss größer als 0 sein.", NameOf(baseA)) + End If + If baseB <= 0 Then + Throw New ArgumentException("Grundseite c muss größer als 0 sein.", NameOf(baseB)) + End If + If height <= 0 Then + Throw New ArgumentException("Höhe muss größer als 0 sein.", NameOf(height)) + End If Dim halfA = baseA / 2.0 Dim halfB = baseB / 2.0 @@ -239,7 +257,9 @@ Namespace TwoDimensional Public Shared Function IsTrapezoidFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If Dim ab = New PointF(vertices(1).X - vertices(0).X, vertices(1).Y - vertices(0).Y) Dim bc = New PointF(vertices(2).X - vertices(1).X, vertices(2).Y - vertices(1).Y) @@ -258,8 +278,12 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length <> 4 Then Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length <> 4 Then + Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + End If End Sub Private Shared Function Distance(p1 As PointF, p2 As PointF) As Double diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index efeb502..f52fdd1 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -32,7 +32,7 @@ Namespace TwoDimensional Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) End If If h < 0 Then - Throw New ArgumentException("Höhe darf nicht negativ sein.", NameOf(h)) + Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -176,7 +176,9 @@ Namespace TwoDimensional ''' True, wenn die Fläche größer als die Toleranz ist Public Shared Function IsValidTriangleFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + If tolerance <= 0 Then + Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + End If ValidateVertices(vertices) Return AreaFromVertices(vertices) > tolerance @@ -188,9 +190,15 @@ Namespace TwoDimensional Private Shared Sub ValidateSides(a As Double, b As Double, c As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If a <= 0 Then Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) - If b <= 0 Then Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) - If c <= 0 Then Throw New ArgumentException("Seite c muss größer als 0 sein.", NameOf(c)) + If a <= 0 Then + Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + End If + If b <= 0 Then + Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + End If + If c <= 0 Then + Throw New ArgumentException("Seite c muss größer als 0 sein.", NameOf(c)) + End If If a + b <= c OrElse a + c <= b OrElse b + c <= a Then Throw New ArgumentException(My.Resources.InvalidTriangleSides) End If @@ -198,8 +206,12 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If vertices Is Nothing Then Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) - If vertices.Length <> 3 Then Throw New ArgumentException("Es müssen genau 3 Eckpunkte angegeben werden.", NameOf(vertices)) + If vertices Is Nothing Then + Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + End If + If vertices.Length <> 3 Then + Throw New ArgumentException("Es müssen genau 3 Eckpunkte angegeben werden.", NameOf(vertices)) + End If End Sub Private Shared Function Distance(p1 As PointF, p2 As PointF) As Double From accd904ff0464d677c52d7670d0f31ce082cc5ac Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sun, 4 Oct 2026 19:18:54 +0200 Subject: [PATCH 11/22] Lokalisierte Validierungen bereinigt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ressourcenmeldungen ergänzt, Geometrie-Validierungen auf My.Resources umgestellt, XML-Doku in Cone vereinheitlicht und Projektdatei inkl. Assembly-Version auf 1.2026.1004.1 aktualisiert. --- Geometry/Geometry.vbproj | 2 +- Geometry/My Project/AssemblyInfo.vb | 4 +- Geometry/My Project/Resources.Designer.vb | 45 +++++++++++++++++++++++ Geometry/My Project/Resources.resx | 15 ++++++++ Geometry/ThreeDimensional/Cone.vb | 20 +++++----- Geometry/ThreeDimensional/Cylinder.vb | 4 +- Geometry/ThreeDimensional/Frustum.vb | 10 ++--- Geometry/ThreeDimensional/Pyramid.vb | 8 ++-- Geometry/ThreeDimensional/Sphere.vb | 2 +- Geometry/TwoDimensional/RegularPolygon.vb | 2 +- Geometry/TwoDimensional/Rhombus.vb | 6 +-- 11 files changed, 89 insertions(+), 29 deletions(-) diff --git a/Geometry/Geometry.vbproj b/Geometry/Geometry.vbproj index 29a0973..4862eca 100644 --- a/Geometry/Geometry.vbproj +++ b/Geometry/Geometry.vbproj @@ -114,9 +114,9 @@ VbMyResourcesResXFileCodeGenerator - Resources.Designer.vb My.Resources Designer + Resources.Designer.vb diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index fe433d9..4658d20 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index fe396ec..2e4b944 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -60,6 +60,24 @@ Namespace My.Resources End Set End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge muss grösser als Null sein. ähnelt. + ''' + Friend ReadOnly Property CheckPositiveLength() As String + Get + Return ResourceManager.GetString("CheckPositiveLength", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite muss grösser als Null sein. ähnelt. + ''' + Friend ReadOnly Property CheckPositiveWidth() As String + Get + Return ResourceManager.GetString("CheckPositiveWidth", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Durchmesser darf nicht negativ sein. ähnelt. ''' @@ -114,6 +132,33 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Länge muss kleiner als die untere Länge sein. ähnelt. + ''' + Friend ReadOnly Property VerifyTopLengthLessThanBottom() As String + Get + Return ResourceManager.GetString("String1", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Breite muss kleiner als die untere Breite sein. ähnelt. + ''' + Friend ReadOnly Property VerifyTopWidthLessThanBottom() As String + Get + Return ResourceManager.GetString("String2", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der obere Radius muss kleiner als der untere Radius sein. ähnelt. + ''' + Friend ReadOnly Property VerifyTopRadiusLessThanBottom() As String + Get + Return ResourceManager.GetString("VerifyTopLessThanBottom", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite darf nicht negatv sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 827fcc7..7a1d5a6 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Die Länge muss grösser als Null sein. + + + Die Breite muss grösser als Null sein. + Der Durchmesser darf nicht negativ sein. @@ -135,6 +141,15 @@ Der Radius darf nicht negativ sein. + + Die obere Länge muss kleiner als die untere Länge sein. + + + Die obere Breite muss kleiner als die untere Breite sein. + + + Der obere Radius muss kleiner als der untere Radius sein. + Die Breite darf nicht negatv sein. diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index 45f253c..c0dd91c 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -123,7 +123,7 @@ Namespace ThreeDimensional ''' Berechnet das Volumen eines Kegelstumpfs. ''' ''' Unterer Radius (> 0) - ''' Oberer Radius (>= 0 und < radiusBottom) + ''' Oberer Radius (>= 0 und < bottomRadius) ''' Höhe (>= 0) ''' Volumen (PI * h / 3) * (R^2 + Rr + r^2) Public Shared Function FrustumVolume(radiusBottom As Double, radiusTop As Double, height As Double) As Double @@ -141,7 +141,7 @@ Namespace ThreeDimensional ''' Berechnet die Mantelfläche eines Kegelstumpfs. ''' ''' Unterer Radius (> 0) - ''' Oberer Radius (>= 0 und < radiusBottom) + ''' Oberer Radius (>= 0 und < bottomRadius) ''' Höhe (>= 0) ''' Mantelfläche PI * (R + r) * s Public Shared Function FrustumLateralArea(radiusBottom As Double, radiusTop As Double, height As Double) As Double @@ -158,7 +158,7 @@ Namespace ThreeDimensional ''' Berechnet die Gesamtoberfläche eines Kegelstumpfs. ''' ''' Unterer Radius (> 0) - ''' Oberer Radius (>= 0 und < radiusBottom) + ''' Oberer Radius (>= 0 und < bottomRadius) ''' Höhe (>= 0) ''' Gesamtoberfläche (Mantel + beide Grundflächen) Public Shared Function FrustumSurfaceArea(radiusBottom As Double, radiusTop As Double, height As Double) As Double @@ -211,16 +211,16 @@ Namespace ThreeDimensional #Region "Validierung und interne Hilfsmethoden" - Private Shared Sub ValidateFrustumRadii(radiusBottom As Double, radiusTop As Double) + Private Shared Sub ValidateFrustumRadii(bottomRadius As Double, topRadius As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. - If radiusBottom <= 0 Then - Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(radiusBottom)) + If bottomRadius <= 0 Then + Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(bottomRadius)) End If - If radiusTop < 0 Then - Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(radiusTop)) + If topRadius < 0 Then + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(topRadius)) End If - If radiusTop >= radiusBottom Then - Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(radiusTop)) + If topRadius >= bottomRadius Then + Throw New ArgumentException(My.Resources.VerifyTopRadiusLessThanBottom, NameOf(topRadius)) End If End Sub diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index d5bb815..4c5f856 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -202,10 +202,10 @@ Namespace ThreeDimensional Private Shared Sub ValidateHollowRadii(outerRadius As Double, innerRadius As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If outerRadius <= 0 Then - Throw New ArgumentException("Der Außenradius muss größer als 0 sein.", NameOf(outerRadius)) + Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(outerRadius)) End If If innerRadius < 0 Then - Throw New ArgumentException("Der Innenradius darf nicht negativ sein.", NameOf(innerRadius)) + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(innerRadius)) End If If innerRadius >= outerRadius Then Throw New ArgumentException("Der Innenradius muss kleiner als der Außenradius sein.", NameOf(innerRadius)) diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index a563c9f..96f0e0d 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -207,13 +207,13 @@ Namespace ThreeDimensional Private Shared Sub ValidateConeFrustumInputs(bottomRadius As Double, topRadius As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomRadius <= 0 Then - Throw New ArgumentException("Der untere Radius muss größer als 0 sein.", NameOf(bottomRadius)) + Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(bottomRadius)) End If If topRadius < 0 Then - Throw New ArgumentException("Der obere Radius darf nicht negativ sein.", NameOf(topRadius)) + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(topRadius)) End If If topRadius >= bottomRadius Then - Throw New ArgumentException("Der obere Radius muss kleiner als der untere Radius sein.", NameOf(topRadius)) + Throw New ArgumentException(My.Resources.VerifyTopRadiusLessThanBottom, NameOf(topRadius)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -223,10 +223,10 @@ Namespace ThreeDimensional Private Shared Sub ValidatePyramidFrustumInputs(bottomLength As Double, bottomWidth As Double, topLength As Double, topWidth As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomLength <= 0 Then - Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) + Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(bottomLength)) End If If bottomWidth <= 0 Then - Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) + Throw New ArgumentException(My.Resources.CheckPositiveWidth, NameOf(bottomWidth)) End If If topLength < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(topLength)) diff --git a/Geometry/ThreeDimensional/Pyramid.vb b/Geometry/ThreeDimensional/Pyramid.vb index bbee22c..bedf334 100644 --- a/Geometry/ThreeDimensional/Pyramid.vb +++ b/Geometry/ThreeDimensional/Pyramid.vb @@ -264,10 +264,10 @@ Namespace ThreeDimensional Private Shared Sub ValidateFrustumInputs(bottomLength As Double, bottomWidth As Double, topLength As Double, topWidth As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomLength <= 0 Then - Throw New ArgumentException("Die untere Grundlänge muss größer als 0 sein.", NameOf(bottomLength)) + Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(bottomLength)) End If If bottomWidth <= 0 Then - Throw New ArgumentException("Die untere Grundbreite muss größer als 0 sein.", NameOf(bottomWidth)) + Throw New ArgumentException(My.Resources.CheckPositiveWidth, NameOf(bottomWidth)) End If If topLength < 0 Then Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(topLength)) @@ -276,10 +276,10 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(topWidth)) End If If topLength >= bottomLength Then - Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere Grundlänge sein.", NameOf(topLength)) + Throw New ArgumentException(My.Resources.VerifyTopLengthLessThanBottom, NameOf(topLength)) End If If topWidth >= bottomWidth Then - Throw New ArgumentException("Die obere Grundbreite muss kleiner als die untere Grundbreite sein.", NameOf(topWidth)) + Throw New ArgumentException(My.Resources.VerifyTopWidthLessThanBottom, NameOf(topWidth)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 06c59fd..07fe59c 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -165,7 +165,7 @@ Namespace ThreeDimensional Private Shared Sub ValidateCapInputs(radius As Double, capHeight As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius <= 0 Then - Throw New ArgumentException("Der Radius muss größer als 0 sein.", NameOf(radius)) + Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) End If If capHeight < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(capHeight)) diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index 9d708e0..ba6ad89 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -140,7 +140,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateSideCount(sideCount) If circumradius < 0 Then - Throw New ArgumentException("Der Umkreisradius darf nicht negativ sein.", NameOf(circumradius)) + Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(circumradius)) End If Dim result(sideCount - 1) As PointF diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index 77e45da..01801da 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -81,7 +81,7 @@ Namespace TwoDimensional Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) End If If side <= 0 Then - Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(side)) End If Return area / side End Function @@ -95,7 +95,7 @@ Namespace TwoDimensional Public Shared Function DiagonalFromSideAndAngle(side As Double, interiorAngleRadians As Double) As Double() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side <= 0 Then - Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(side)) End If If interiorAngleRadians <= 0 OrElse interiorAngleRadians >= Math.PI Then Throw New ArgumentException("Der Innenwinkel muss zwischen 0 und PI liegen.", NameOf(interiorAngleRadians)) @@ -142,7 +142,7 @@ Namespace TwoDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, side As Double, interiorAngleRadians As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side <= 0 Then - Throw New ArgumentException("Die Seitenlänge muss größer als 0 sein.", NameOf(side)) + Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(side)) End If If interiorAngleRadians <= 0 OrElse interiorAngleRadians >= Math.PI Then Throw New ArgumentException("Der Innenwinkel muss zwischen 0 und PI liegen.", NameOf(interiorAngleRadians)) From 294d404b2cec724f477975aa5abc27dad382fe1e Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sun, 4 Oct 2026 19:41:51 +0200 Subject: [PATCH 12/22] Validierungsmeldungen lokalisieren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ressourcen ergänzt, fehlerhafte Resource-Properties bereinigt, Exception-Texte in Circle, Ellipse, Kite und Rhombus auf konsistente Ressourcenstrings umgestellt und Assembly-Version auf 1.2026.1004.2 angehoben. --- Geometry/My Project/AssemblyInfo.vb | 4 +- Geometry/My Project/Resources.Designer.vb | 50 +++++++++++++++++++---- Geometry/My Project/Resources.resx | 12 ++++++ Geometry/TwoDimensional/Circle.vb | 4 +- Geometry/TwoDimensional/Ellipse.vb | 2 +- Geometry/TwoDimensional/Kite.vb | 22 +++++----- Geometry/TwoDimensional/Rhombus.vb | 4 +- 7 files changed, 73 insertions(+), 25 deletions(-) diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index 4658d20..4376ee5 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 2e4b944..9ef9f0d 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -60,6 +60,24 @@ Namespace My.Resources End Set End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Diagonale darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeDiagonal() As String + Get + Return ResourceManager.GetString("CheckNonNegativeDiagonal", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Halbachsen müssen größer als 0 sein (a>0, b>0). ähnelt. + ''' + Friend ReadOnly Property CheckPositiveAxes() As String + Get + Return ResourceManager.GetString("CheckPositiveAxes", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge muss grösser als Null sein. ähnelt. ''' @@ -78,6 +96,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenlänge ist ungültig. ähnelt. + ''' + Friend ReadOnly Property ChordLengthInvalid() As String + Get + Return ResourceManager.GetString("ChordLengthInvalid", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Durchmesser darf nicht negativ sein. ähnelt. ''' @@ -133,20 +160,20 @@ Namespace My.Resources End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Länge muss kleiner als die untere Länge sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenhöhe ist ungültig. ähnelt. ''' - Friend ReadOnly Property VerifyTopLengthLessThanBottom() As String + Friend ReadOnly Property SagittaHeightInvalid() As String Get - Return ResourceManager.GetString("String1", resourceCulture) + Return ResourceManager.GetString("SagittaHeightInvalid", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Breite muss kleiner als die untere Breite sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Länge muss kleiner als die untere Länge sein. ähnelt. ''' - Friend ReadOnly Property VerifyTopWidthLessThanBottom() As String + Friend ReadOnly Property VerifyTopLengthLessThanBottom() As String Get - Return ResourceManager.GetString("String2", resourceCulture) + Return ResourceManager.GetString("VerifyTopLengthLessThanBottom", resourceCulture) End Get End Property @@ -155,7 +182,16 @@ Namespace My.Resources ''' Friend ReadOnly Property VerifyTopRadiusLessThanBottom() As String Get - Return ResourceManager.GetString("VerifyTopLessThanBottom", resourceCulture) + Return ResourceManager.GetString("VerifyTopRadiusLessThanBottom", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Breite muss kleiner als die untere Breite sein. ähnelt. + ''' + Friend ReadOnly Property VerifyTopWidthLessThanBottom() As String + Get + Return ResourceManager.GetString("VerifyTopWidthLessThanBottom", resourceCulture) End Get End Property diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 7a1d5a6..10ae927 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -153,4 +153,16 @@ Die Breite darf nicht negatv sein. + + Die Sehnenhöhe ist ungültig. + + + Die Sehnenlänge ist ungültig. + + + Die Halbachsen müssen größer als 0 sein (a>0, b>0). + + + Die Diagonale darf nicht negativ sein. + \ No newline at end of file diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index e34c8c3..854e8c3 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -175,7 +175,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If sagitta < 0 Or sagitta > radius Then - Throw New ArgumentException("Sehnenhöhe ungültig.", NameOf(sagitta)) + Throw New ArgumentException(My.Resources.SagittaHeightInvalid, NameOf(sagitta)) End If ' Abstand vom Mittelpunkt zur Sehne (h) = radius - sagitta @@ -211,7 +211,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) End If If chordLength < 0 OrElse chordLength > 2.0 * radius Then - Throw New ArgumentException("Sehnenlänge ungültig.", NameOf(chordLength)) + Throw New ArgumentException(My.Resources.ChordLengthInvalid, NameOf(chordLength)) End If ' chord = 2 radius sin(theta/2) => theta = 2 * asin(chord/(2*radius)) Return 2.0 * Math.Asin(chordLength / (2.0 * radius)) diff --git a/Geometry/TwoDimensional/Ellipse.vb b/Geometry/TwoDimensional/Ellipse.vb index f0af1ab..17bc285 100644 --- a/Geometry/TwoDimensional/Ellipse.vb +++ b/Geometry/TwoDimensional/Ellipse.vb @@ -338,7 +338,7 @@ Namespace TwoDimensional Private Shared Sub ValidateAxes(a As Double, b As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If a <= 0 OrElse b <= 0 Then - Throw New ArgumentException("Die Halbachsen müssen größer als 0 sein (a>0, b>0).") + Throw New ArgumentException(My.Resources.CheckPositiveAxes) End If End Sub diff --git a/Geometry/TwoDimensional/Kite.vb b/Geometry/TwoDimensional/Kite.vb index fa083ef..852e1d9 100644 --- a/Geometry/TwoDimensional/Kite.vb +++ b/Geometry/TwoDimensional/Kite.vb @@ -29,10 +29,10 @@ Namespace TwoDimensional Public Shared Function AreaFromDiagonals(diagonal1 As Double, diagonal2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diagonal1 < 0 Then - Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal1)) End If If diagonal2 < 0 Then - Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal2)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (diagonal1 * diagonal2) / 2.0 @@ -48,10 +48,10 @@ Namespace TwoDimensional Public Shared Function Perimeter(sideA As Double, sideB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideA < 0 Then - Throw New ArgumentException("Seitenlänge A darf nicht negativ sein.", NameOf(sideA)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideA)) End If If sideB < 0 Then - Throw New ArgumentException("Seitenlänge B darf nicht negativ sein.", NameOf(sideB)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideB)) End If Return 2.0 * (sideA + sideB) End Function @@ -65,7 +65,7 @@ Namespace TwoDimensional Public Shared Function AreaFromBaseHeight(baseLength As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseLength < 0 Then - Throw New ArgumentException("Die Grundseite darf nicht negativ sein.", NameOf(baseLength)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(baseLength)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -102,16 +102,16 @@ Namespace TwoDimensional Public Shared Function IsSymmetricBySides(sideA As Double, sideB As Double, sideC As Double, sideD As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideA < 0 Then - Throw New ArgumentException("Seite A darf nicht negativ sein.", NameOf(sideA)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideA)) End If If sideB < 0 Then - Throw New ArgumentException("Seite B darf nicht negativ sein.", NameOf(sideB)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideB)) End If If sideC < 0 Then - Throw New ArgumentException("Seite C darf nicht negativ sein.", NameOf(sideC)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideC)) End If If sideD < 0 Then - Throw New ArgumentException("Seite D darf nicht negativ sein.", NameOf(sideD)) + Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideD)) End If If tolerance <= 0 Then Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) @@ -138,10 +138,10 @@ Namespace TwoDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, diagonal1 As Double, diagonal2 As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diagonal1 < 0 Then - Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal1)) End If If diagonal2 < 0 Then - Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal2)) End If Dim halfD1 = diagonal1 / 2.0 diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index 01801da..55108b4 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -46,10 +46,10 @@ Namespace TwoDimensional Public Shared Function AreaFromDiagonals(diagonal1 As Double, diagonal2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diagonal1 < 0 Then - Throw New ArgumentException("Diagonale 1 darf nicht negativ sein.", NameOf(diagonal1)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal1)) End If If diagonal2 < 0 Then - Throw New ArgumentException("Diagonale 2 darf nicht negativ sein.", NameOf(diagonal2)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal2)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (diagonal1 * diagonal2) / 2.0 From a6f31354286959c174e0b306c9c91cae6b5b5479 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Sun, 4 Oct 2026 19:59:25 +0200 Subject: [PATCH 13/22] Sphere-Validierung auf Ressourcen umgestellt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue lokalisierte Ressourcen für IsPolarAngleInBounds und CheckCapHeightLimit ergänzt und die hart codierten Fehlermeldungen in Sphere.vb durch My.Resources-Texte ersetzt. --- Geometry/My Project/Resources.Designer.vb | 18 ++++++++++++++++++ Geometry/My Project/Resources.resx | 6 ++++++ Geometry/ThreeDimensional/Sphere.vb | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 9ef9f0d..4f839cd 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -60,6 +60,15 @@ Namespace My.Resources End Set End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Kappenhöhe darf maximal 2 * Radius sein. ähnelt. + ''' + Friend ReadOnly Property CheckCapHeightLimit() As String + Get + Return ResourceManager.GetString("CheckCapHeightLimit", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Diagonale darf nicht negativ sein. ähnelt. ''' @@ -132,6 +141,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Polarwinkel muss im Bereich von Null bis PI liegen. ähnelt. + ''' + Friend ReadOnly Property IsPolarAngleInBounds() As String + Get + Return ResourceManager.GetString("IsPolarAngleInBounds", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge darf nicht negativ sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 10ae927..4156b09 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -165,4 +165,10 @@ Die Diagonale darf nicht negativ sein. + + Der Polarwinkel muss im Bereich von Null bis PI liegen. + + + Die Kappenhöhe darf maximal 2 * Radius sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 07fe59c..4d70084 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -147,7 +147,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) End If If polarAngleRadians < 0 OrElse polarAngleRadians > Math.PI Then - Throw New ArgumentException("Der Polarwinkel muss im Bereich 0 bis PI liegen.", NameOf(polarAngleRadians)) + Throw New ArgumentException(My.Resources.IsPolarAngleInBounds, NameOf(polarAngleRadians)) End If Dim sinTheta = Math.Sin(polarAngleRadians) @@ -171,7 +171,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(capHeight)) End If If capHeight > 2.0 * radius Then - Throw New ArgumentException("Die Kappenhöhe darf maximal 2 * Radius sein.", NameOf(capHeight)) + Throw New ArgumentException(My.Resources.CheckCapHeightLimit, NameOf(capHeight)) End If End Sub From f0c1888018315c3b6e46803614bd754d2929fc41 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Mon, 5 Oct 2026 19:15:44 +0200 Subject: [PATCH 14/22] Validierungstexte in Ressourcen ausgelagert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Cylinder.vb` verwendet nun `My.Resources` für die Texte zu `innerRadius >= outerRadius` und `heightOffset`; die neuen lokalisierbaren Zeichenfolgen wurden in `Resources.resx` und `Resources.Designer.vb` ergänzt. Zusätzlich wurde die Zeilenaufteilung bei der Koordinatenberechnung bereinigt. --- Geometry/My Project/Resources.Designer.vb | 18 ++++++++++++++++++ Geometry/My Project/Resources.resx | 6 ++++++ Geometry/ThreeDimensional/Cylinder.vb | 7 +++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 4f839cd..4e84788 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -186,6 +186,24 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Innenradius muss kleiner als der Außenradius sein. ähnelt. + ''' + Friend ReadOnly Property VerifyInnerLessThanOuter() As String + Get + Return ResourceManager.GetString("VerifyInnerLessThanOuter", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Höhenoffset muss im Bereich 0 bis Höhe liegen. ähnelt. + ''' + Friend ReadOnly Property VerifyOffsetWithinHeight() As String + Get + Return ResourceManager.GetString("VerifyOffsetWithinHeight", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Länge muss kleiner als die untere Länge sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 4156b09..f71b6f4 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -171,4 +171,10 @@ Die Kappenhöhe darf maximal 2 * Radius sein. + + Der Innenradius muss kleiner als der Außenradius sein. + + + Höhenoffset muss im Bereich 0 bis Höhe liegen. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index 4c5f856..87b3a2a 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -185,12 +185,11 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) End If If heightOffset < 0 OrElse heightOffset > height Then - Throw New ArgumentException("Höhenoffset muss im Bereich 0 bis Höhe liegen.", NameOf(heightOffset)) + Throw New ArgumentException(My.Resources.VerifyOffsetWithinHeight, NameOf(heightOffset)) End If Dim x = centerX + (radius * Math.Cos(angleRadians)) - Dim y = centerY + (radius * Math.Sin(angleRadians)) - Dim z = baseZ + heightOffset + Dim y = centerY + (radius * Math.Sin(angleRadians)) Dim z = baseZ + heightOffset Return Tuple.Create(x, y, z) End Function @@ -208,7 +207,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(innerRadius)) End If If innerRadius >= outerRadius Then - Throw New ArgumentException("Der Innenradius muss kleiner als der Außenradius sein.", NameOf(innerRadius)) + Throw New ArgumentException(My.Resources.VerifyInnerLessThanOuter, NameOf(innerRadius)) End If End Sub From 2d11c8f4e7a46ea5aceefbe4ddd0b33ff5385cd2 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Mon, 5 Oct 2026 19:25:57 +0200 Subject: [PATCH 15/22] Ressourcenfehlertexte zentralisiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue Ressourcenschlüssel für Umfangs- und Seitenprüfungen ergänzt und Validierungen in Frustum, Prism, Parallelogram und RegularPolygon auf zentralisierte Ressourcentexte umgestellt. --- Geometry/My Project/Resources.Designer.vb | 18 ++++++++++++++++++ Geometry/My Project/Resources.resx | 6 ++++++ Geometry/ThreeDimensional/Frustum.vb | 8 ++++---- Geometry/ThreeDimensional/Prism.vb | 10 +++++----- Geometry/TwoDimensional/Parallelogram.vb | 2 +- Geometry/TwoDimensional/RegularPolygon.vb | 2 +- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 4e84788..da95f88 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -69,6 +69,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Umfang darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeCircumference() As String + Get + Return ResourceManager.GetString("CheckNonNegativeCircumference", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Diagonale darf nicht negativ sein. ähnelt. ''' @@ -96,6 +105,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Seite muss größer als Null sein. ähnelt. + ''' + Friend ReadOnly Property CheckPositiveSide() As String + Get + Return ResourceManager.GetString("CheckPositiveSide", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite muss grösser als Null sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index f71b6f4..c39ca3c 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -177,4 +177,10 @@ Höhenoffset muss im Bereich 0 bis Höhe liegen. + + Die Seite muss größer als Null sein. + + + Der Umfang darf nicht negativ sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index 96f0e0d..9db2653 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -156,10 +156,10 @@ Namespace ThreeDimensional Public Shared Function PrismFrustumLateralArea(bottomPerimeter As Double, topPerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomPerimeter < 0 Then - Throw New ArgumentException("Der untere Umfang darf nicht negativ sein.", NameOf(bottomPerimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(bottomPerimeter)) End If If topPerimeter < 0 Then - Throw New ArgumentException("Der obere Umfang darf nicht negativ sein.", NameOf(topPerimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(topPerimeter)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -188,10 +188,10 @@ Namespace ThreeDimensional Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) End If If bottomPerimeter < 0 Then - Throw New ArgumentException("Der untere Umfang darf nicht negativ sein.", NameOf(bottomPerimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(bottomPerimeter)) End If If topPerimeter < 0 Then - Throw New ArgumentException("Der obere Umfang darf nicht negativ sein.", NameOf(topPerimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(topPerimeter)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) diff --git a/Geometry/ThreeDimensional/Prism.vb b/Geometry/ThreeDimensional/Prism.vb index 6e41e99..ad720d0 100644 --- a/Geometry/ThreeDimensional/Prism.vb +++ b/Geometry/ThreeDimensional/Prism.vb @@ -44,7 +44,7 @@ Namespace ThreeDimensional Public Shared Function LateralArea(basePerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If basePerimeter < 0 Then - Throw New ArgumentException("Der Grundumfang darf nicht negativ sein.", NameOf(basePerimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(basePerimeter)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -65,7 +65,7 @@ Namespace ThreeDimensional Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) End If If basePerimeter < 0 Then - Throw New ArgumentException("Der Grundumfang darf nicht negativ sein.", NameOf(basePerimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(basePerimeter)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -185,13 +185,13 @@ Namespace ThreeDimensional Private Shared Sub ValidateTriangleSides(sideA As Double, sideB As Double, sideC As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideA <= 0 Then - Throw New ArgumentException("Seite A muss größer als 0 sein.", NameOf(sideA)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(sideA)) End If If sideB <= 0 Then - Throw New ArgumentException("Seite B muss größer als 0 sein.", NameOf(sideB)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(sideB)) End If If sideC <= 0 Then - Throw New ArgumentException("Seite C muss größer als 0 sein.", NameOf(sideC)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(sideC)) End If If sideA + sideB <= sideC OrElse sideA + sideC <= sideB OrElse sideB + sideC <= sideA Then diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index b1cb964..97c46f7 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -87,7 +87,7 @@ Namespace TwoDimensional Public Shared Function SideFromPerimeter(perimeter As Double, knownSide As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If perimeter < 0 Then - Throw New ArgumentException("Umfang darf nicht negativ sein.", NameOf(perimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(perimeter)) End If If knownSide < 0 Then Throw New ArgumentException("Bekannte Seite darf nicht negativ sein.", NameOf(knownSide)) diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index ba6ad89..291d4d1 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -117,7 +117,7 @@ Namespace TwoDimensional Public Shared Function SideLengthFromPerimeter(perimeter As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If perimeter < 0 Then - Throw New ArgumentException("Der Umfang darf nicht negativ sein.", NameOf(perimeter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(perimeter)) End If ValidateSideCount(sideCount) Return perimeter / sideCount From dbe31f73b408ee2d3ea0b4de7a2617273efe6c7d Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Mon, 5 Oct 2026 19:35:43 +0200 Subject: [PATCH 16/22] =?UTF-8?q?Fl=C3=A4chenfehler=20zentral=20lokalisier?= =?UTF-8?q?en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue Ressource `CheckNonNegativeArea` ergänzt und die bisherigen Inline-Fehlermeldungen für negative Flächenwerte in den Geometrieklassen vereinheitlicht. Exceptions werden jetzt konsistent über `My.Resources.CheckNonNegativeArea` behandelt. --- Geometry/My Project/Resources.Designer.vb | 9 +++++++++ Geometry/My Project/Resources.resx | 3 +++ Geometry/ThreeDimensional/Cube.vb | 2 +- Geometry/ThreeDimensional/Frustum.vb | 8 ++++---- Geometry/ThreeDimensional/Prism.vb | 4 ++-- Geometry/TwoDimensional/Kite.vb | 2 +- Geometry/TwoDimensional/Parallelogram.vb | 2 +- Geometry/TwoDimensional/Rhombus.vb | 4 ++-- Geometry/TwoDimensional/Trapezoid.vb | 2 +- Geometry/TwoDimensional/Triangle.vb | 2 +- 10 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index da95f88..1d643ea 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -69,6 +69,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Fläche darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeArea() As String + Get + Return ResourceManager.GetString("CheckNonNegativeArea", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Umfang darf nicht negativ sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index c39ca3c..6031943 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -183,4 +183,7 @@ Der Umfang darf nicht negativ sein. + + Die Fläche darf nicht negativ sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cube.vb b/Geometry/ThreeDimensional/Cube.vb index e06a1bd..e810e3e 100644 --- a/Geometry/ThreeDimensional/Cube.vb +++ b/Geometry/ThreeDimensional/Cube.vb @@ -91,7 +91,7 @@ Namespace ThreeDimensional Public Shared Function SideFromSurfaceArea(surfaceArea As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If surfaceArea < 0 Then - Throw New ArgumentException("Die Oberfläche darf nicht negativ sein.", NameOf(surfaceArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(surfaceArea)) End If Return Math.Sqrt(surfaceArea / 6.0) End Function diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index 9db2653..5003646 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -132,10 +132,10 @@ Namespace ThreeDimensional Public Shared Function PrismFrustumVolume(bottomArea As Double, topArea As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomArea < 0 Then - Throw New ArgumentException("Die untere Endfläche darf nicht negativ sein.", NameOf(bottomArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(bottomArea)) End If If topArea < 0 Then - Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(topArea)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -182,10 +182,10 @@ Namespace ThreeDimensional Public Shared Function PrismFrustumSurfaceArea(bottomArea As Double, topArea As Double, bottomPerimeter As Double, topPerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomArea < 0 Then - Throw New ArgumentException("Die untere Endfläche darf nicht negativ sein.", NameOf(bottomArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(bottomArea)) End If If topArea < 0 Then - Throw New ArgumentException("Die obere Endfläche darf nicht negativ sein.", NameOf(topArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(topArea)) End If If bottomPerimeter < 0 Then Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(bottomPerimeter)) diff --git a/Geometry/ThreeDimensional/Prism.vb b/Geometry/ThreeDimensional/Prism.vb index ad720d0..752f28b 100644 --- a/Geometry/ThreeDimensional/Prism.vb +++ b/Geometry/ThreeDimensional/Prism.vb @@ -27,7 +27,7 @@ Namespace ThreeDimensional Public Shared Function Volume(baseArea As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseArea < 0 Then - Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(baseArea)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) @@ -62,7 +62,7 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(baseArea As Double, basePerimeter As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseArea < 0 Then - Throw New ArgumentException("Die Grundfläche darf nicht negativ sein.", NameOf(baseArea)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(baseArea)) End If If basePerimeter < 0 Then Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(basePerimeter)) diff --git a/Geometry/TwoDimensional/Kite.vb b/Geometry/TwoDimensional/Kite.vb index 852e1d9..c925a64 100644 --- a/Geometry/TwoDimensional/Kite.vb +++ b/Geometry/TwoDimensional/Kite.vb @@ -82,7 +82,7 @@ Namespace TwoDimensional Public Shared Function HeightFromArea(area As Double, baseLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If area < 0 Then - Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If baseLength <= 0 Then Throw New ArgumentException("Die Grundseite muss größer als 0 sein.", NameOf(baseLength)) diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index 97c46f7..a41f8f2 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -65,7 +65,7 @@ Namespace TwoDimensional Public Shared Function HeightFromArea(area As Double, b As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If area < 0 Then - Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If b <= 0 Then Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index 55108b4..894ecf9 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -78,7 +78,7 @@ Namespace TwoDimensional Public Shared Function HeightFromArea(area As Double, side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If area < 0 Then - Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If side <= 0 Then Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(side)) @@ -116,7 +116,7 @@ Namespace TwoDimensional Public Shared Function InradiusFromAreaPerimeter(area As Double, perimeter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If area < 0 Then - Throw New ArgumentException("Die Fläche darf nicht negativ sein.", NameOf(area)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If perimeter <= 0 Then Throw New ArgumentException("Der Umfang muss größer als 0 sein.", NameOf(perimeter)) diff --git a/Geometry/TwoDimensional/Trapezoid.vb b/Geometry/TwoDimensional/Trapezoid.vb index 31b3c1f..38ce40c 100644 --- a/Geometry/TwoDimensional/Trapezoid.vb +++ b/Geometry/TwoDimensional/Trapezoid.vb @@ -98,7 +98,7 @@ Namespace TwoDimensional Public Shared Function HeightFromArea(area As Double, baseA As Double, baseB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If area < 0 Then - Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If baseA < 0 Then Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index f52fdd1..c1914a6 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -62,7 +62,7 @@ Namespace TwoDimensional Public Shared Function HeightFromArea(area As Double, b As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If area < 0 Then - Throw New ArgumentException("Fläche darf nicht negativ sein.", NameOf(area)) + Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If b <= 0 Then Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) From 276a86e9f80a503debcb06a12eca8d5b9cb04a67 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Tue, 6 Oct 2026 19:50:21 +0200 Subject: [PATCH 17/22] Ressourcen und Versionen aktualisiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lokalisierte Ressourcen ergänzt, harte Fehlermeldungen in Cube, Cuboid, Frustum, Prism und RegularPolygon auf Ressourcen umgestellt, Koordinatenberechnung in Cylinder leicht refaktoriert und Assembly-/Dateiversion auf 1.2026.1006.0 angehoben. --- Geometry/My Project/AssemblyInfo.vb | 4 +- Geometry/My Project/Resources.Designer.vb | 54 +++++++++++++++++++++++ Geometry/My Project/Resources.resx | 18 ++++++++ Geometry/ThreeDimensional/Cube.vb | 2 +- Geometry/ThreeDimensional/Cuboid.vb | 6 +-- Geometry/ThreeDimensional/Cylinder.vb | 3 +- Geometry/ThreeDimensional/Frustum.vb | 4 +- Geometry/ThreeDimensional/Prism.vb | 4 +- Geometry/TwoDimensional/RegularPolygon.vb | 2 +- 9 files changed, 85 insertions(+), 12 deletions(-) diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index 4376ee5..22edb48 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 1d643ea..bdd4b34 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -96,6 +96,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Das Volumen darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeVolume() As String + Get + Return ResourceManager.GetString("CheckNonNegativeVolume", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Halbachsen müssen größer als 0 sein (a>0, b>0). ähnelt. ''' @@ -105,6 +114,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Kante muss grösser als Null sein. ähnelt. + ''' + Friend ReadOnly Property CheckPositiveEdge() As String + Get + Return ResourceManager.GetString("CheckPositiveEdge", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge muss grösser als Null sein. ähnelt. ''' @@ -204,6 +222,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Seitenanzahl muss größer oder gleich 3 sein. ähnelt. + ''' + Friend ReadOnly Property RequireAtLeastThreeSides() As String + Get + Return ResourceManager.GetString("RequireAtLeastThreeSides", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenhöhe ist ungültig. ähnelt. ''' @@ -213,6 +240,33 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Seiten erfüllen die Dreiecksungleichung nicht. ähnelt. + ''' + Friend ReadOnly Property String1() As String + Get + Return ResourceManager.GetString("String1", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Grundlänge muss kleiner als die untere sein. ähnelt. + ''' + Friend ReadOnly Property String2() As String + Get + Return ResourceManager.GetString("String2", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Grundbreite muss kleiner als die untere sein. ähnelt. + ''' + Friend ReadOnly Property String3() As String + Get + Return ResourceManager.GetString("String3", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Innenradius muss kleiner als der Außenradius sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 6031943..0500f7a 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -186,4 +186,22 @@ Die Fläche darf nicht negativ sein. + + Die Seiten erfüllen die Dreiecksungleichung nicht. + + + Die Seitenanzahl muss größer oder gleich 3 sein. + + + Die obere Grundlänge muss kleiner als die untere sein. + + + Die obere Grundbreite muss kleiner als die untere sein. + + + Das Volumen darf nicht negativ sein. + + + Die Kante muss grösser als Null sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cube.vb b/Geometry/ThreeDimensional/Cube.vb index e810e3e..10fe53f 100644 --- a/Geometry/ThreeDimensional/Cube.vb +++ b/Geometry/ThreeDimensional/Cube.vb @@ -78,7 +78,7 @@ Namespace ThreeDimensional Public Shared Function SideFromVolume(volume As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If volume < 0 Then - Throw New ArgumentException("Das Volumen darf nicht negativ sein.", NameOf(volume)) + Throw New ArgumentException(My.Resources.CheckNonNegativeVolume, NameOf(volume)) End If Return Math.Pow(volume, 1.0 / 3.0) End Function diff --git a/Geometry/ThreeDimensional/Cuboid.vb b/Geometry/ThreeDimensional/Cuboid.vb index 47dcd72..3e79e71 100644 --- a/Geometry/ThreeDimensional/Cuboid.vb +++ b/Geometry/ThreeDimensional/Cuboid.vb @@ -145,13 +145,13 @@ Namespace ThreeDimensional Public Shared Function EdgeFromVolume(volume As Double, edge1 As Double, edge2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If volume < 0 Then - Throw New ArgumentException("Das Volumen darf nicht negativ sein.", NameOf(volume)) + Throw New ArgumentException(My.Resources.CheckNonNegativeVolume, NameOf(volume)) End If If edge1 <= 0 Then - Throw New ArgumentException("Kante 1 muss größer als 0 sein.", NameOf(edge1)) + Throw New ArgumentException(My.Resources.CheckPositiveEdge, NameOf(edge1)) End If If edge2 <= 0 Then - Throw New ArgumentException("Kante 2 muss größer als 0 sein.", NameOf(edge2)) + Throw New ArgumentException(My.Resources.CheckPositiveEdge, NameOf(edge2)) End If Return volume / (edge1 * edge2) End Function diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index 87b3a2a..636f979 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -189,7 +189,8 @@ Namespace ThreeDimensional End If Dim x = centerX + (radius * Math.Cos(angleRadians)) - Dim y = centerY + (radius * Math.Sin(angleRadians)) Dim z = baseZ + heightOffset + Dim y = centerY + (radius * Math.Sin(angleRadians)) + Dim z = baseZ + heightOffset Return Tuple.Create(x, y, z) End Function diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index 5003646..23982be 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -235,10 +235,10 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(topWidth)) End If If topLength >= bottomLength Then - Throw New ArgumentException("Die obere Grundlänge muss kleiner als die untere sein.", NameOf(topLength)) + Throw New ArgumentException(My.Resources.String2, NameOf(topLength)) End If If topWidth >= bottomWidth Then - Throw New ArgumentException("Die obere Grundbreite muss kleiner als die untere sein.", NameOf(topWidth)) + Throw New ArgumentException(My.Resources.String3, NameOf(topWidth)) End If If height < 0 Then Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) diff --git a/Geometry/ThreeDimensional/Prism.vb b/Geometry/ThreeDimensional/Prism.vb index 752f28b..5976571 100644 --- a/Geometry/ThreeDimensional/Prism.vb +++ b/Geometry/ThreeDimensional/Prism.vb @@ -195,14 +195,14 @@ Namespace ThreeDimensional End If If sideA + sideB <= sideC OrElse sideA + sideC <= sideB OrElse sideB + sideC <= sideA Then - Throw New ArgumentException("Die Seiten erfüllen die Dreiecksungleichung nicht.", NameOf(sideC)) + Throw New ArgumentException(My.Resources.String1, NameOf(sideC)) End If End Sub Private Shared Sub ValidateSideCount(sideCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideCount < 3 Then - Throw New ArgumentException("Die Seitenanzahl muss größer oder gleich 3 sein.", NameOf(sideCount)) + Throw New ArgumentException(My.Resources.RequireAtLeastThreeSides, NameOf(sideCount)) End If End Sub diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index 291d4d1..a199382 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -235,7 +235,7 @@ Namespace TwoDimensional Private Shared Sub ValidateSideCount(sideCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideCount < 3 Then - Throw New ArgumentException("Die Seitenanzahl muss größer oder gleich 3 sein.", NameOf(sideCount)) + Throw New ArgumentException(My.Resources.RequireAtLeastThreeSides, NameOf(sideCount)) End If End Sub From 2addaa3bab13b82cd19e5499f43909d7e98a765e Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Wed, 7 Oct 2026 18:53:01 +0200 Subject: [PATCH 18/22] =?UTF-8?q?Neue=20semantische=20Resource-Keys=20f?= =?UTF-8?q?=C3=BCr=20Pr=C3=BCfungen=20auf=20gr=C3=B6sser=20Null=20und=20gr?= =?UTF-8?q?=C3=B6sser=20gleich=20Null=20eingef=C3=BChrt,=20bestehende=20Ar?= =?UTF-8?q?gumentException-Meldungen=20in=202D-/3D-Klassen=20darauf=20umge?= =?UTF-8?q?stellt=20und=20Ressourcentexte=20sprachlich=20sowie=20fachlich?= =?UTF-8?q?=20pr=C3=A4zisiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Geometry/My Project/Resources.Designer.vb | 128 ++++++++++++++-------- Geometry/My Project/Resources.resx | 30 +++-- Geometry/ThreeDimensional/Cone.vb | 34 +++--- Geometry/ThreeDimensional/Cube.vb | 10 +- Geometry/ThreeDimensional/Cuboid.vb | 44 ++++---- Geometry/ThreeDimensional/Cylinder.vb | 32 +++--- Geometry/ThreeDimensional/Frustum.vb | 18 +-- Geometry/ThreeDimensional/Prism.vb | 16 +-- Geometry/ThreeDimensional/Pyramid.vb | 42 +++---- Geometry/ThreeDimensional/Sphere.vb | 18 +-- Geometry/TwoDimensional/Circle.vb | 24 ++-- Geometry/TwoDimensional/Kite.vb | 22 ++-- Geometry/TwoDimensional/Parallelogram.vb | 22 ++-- Geometry/TwoDimensional/Polygon.vb | 4 +- Geometry/TwoDimensional/Rectangle.vb | 12 +- Geometry/TwoDimensional/RegularPolygon.vb | 10 +- Geometry/TwoDimensional/Rhombus.vb | 10 +- Geometry/TwoDimensional/Square.vb | 14 +-- Geometry/TwoDimensional/Trapezoid.vb | 26 ++--- Geometry/TwoDimensional/Triangle.vb | 12 +- 20 files changed, 288 insertions(+), 240 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index bdd4b34..4a5f97a 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -96,6 +96,42 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Durchmesser darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeDiameter() As String + Get + Return ResourceManager.GetString("CheckNonNegativeDiameter", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Höhe darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeHeight() As String + Get + Return ResourceManager.GetString("CheckNonNegativeHeight", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeLength() As String + Get + Return ResourceManager.GetString("CheckNonNegativeLength", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeRadius() As String + Get + Return ResourceManager.GetString("CheckNonNegativeRadius", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Das Volumen darf nicht negativ sein. ähnelt. ''' @@ -106,7 +142,16 @@ Namespace My.Resources End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Halbachsen müssen größer als 0 sein (a>0, b>0). ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeWidth() As String + Get + Return ResourceManager.GetString("CheckNonNegativeWidth", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Halbachsen müssen größer als Null sein (a>0, b>0). ähnelt. ''' Friend ReadOnly Property CheckPositiveAxes() As String Get @@ -115,110 +160,110 @@ Namespace My.Resources End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Kante muss grösser als Null sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Der Umfang muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property CheckPositiveEdge() As String + Friend ReadOnly Property CheckPositiveCircumference() As String Get - Return ResourceManager.GetString("CheckPositiveEdge", resourceCulture) + Return ResourceManager.GetString("CheckPositiveCircumference", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge muss grösser als Null sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Diagonale muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property CheckPositiveLength() As String + Friend ReadOnly Property CheckPositiveDiagonal() As String Get - Return ResourceManager.GetString("CheckPositiveLength", resourceCulture) + Return ResourceManager.GetString("CheckPositiveDiagonal", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Seite muss größer als Null sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Kante muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property CheckPositiveSide() As String + Friend ReadOnly Property CheckPositiveEdge() As String Get - Return ResourceManager.GetString("CheckPositiveSide", resourceCulture) + Return ResourceManager.GetString("CheckPositiveEdge", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite muss grösser als Null sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die höhe muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property CheckPositiveWidth() As String + Friend ReadOnly Property CheckPositiveHeight() As String Get - Return ResourceManager.GetString("CheckPositiveWidth", resourceCulture) + Return ResourceManager.GetString("CheckPositiveHeight", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenlänge ist ungültig. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property ChordLengthInvalid() As String + Friend ReadOnly Property CheckPositiveLength() As String Get - Return ResourceManager.GetString("ChordLengthInvalid", resourceCulture) + Return ResourceManager.GetString("CheckPositiveLength", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Der Durchmesser darf nicht negativ sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property DiameterIsNegative() As String + Friend ReadOnly Property CheckPositiveRadius() As String Get - Return ResourceManager.GetString("DiameterIsNegative", resourceCulture) + Return ResourceManager.GetString("CheckPositiveRadius", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Höhe darf nicht negativ sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Seite muss größer als Null sein. ähnelt. ''' - Friend ReadOnly Property HeightIsNegative() As String + Friend ReadOnly Property CheckPositiveSide() As String Get - Return ResourceManager.GetString("HeightIsNegative", resourceCulture) + Return ResourceManager.GetString("CheckPositiveSide", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten bilden kein gültiges Dreieck. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Toleranz muss größer als Null sein. ähnelt. ''' - Friend ReadOnly Property InvalidTriangleSides() As String + Friend ReadOnly Property CheckPositiveTolerance() As String Get - Return ResourceManager.GetString("InvalidTriangleSides", resourceCulture) + Return ResourceManager.GetString("CheckPositiveTolerance", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Der Polarwinkel muss im Bereich von Null bis PI liegen. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite muss grösser als Null sein. ähnelt. ''' - Friend ReadOnly Property IsPolarAngleInBounds() As String + Friend ReadOnly Property CheckPositiveWidth() As String Get - Return ResourceManager.GetString("IsPolarAngleInBounds", resourceCulture) + Return ResourceManager.GetString("CheckPositiveWidth", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Länge darf nicht negativ sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenlänge ist ungültig. ähnelt. ''' - Friend ReadOnly Property LengthIsNegative() As String + Friend ReadOnly Property ChordLengthInvalid() As String Get - Return ResourceManager.GetString("LengthIsNegative", resourceCulture) + Return ResourceManager.GetString("ChordLengthInvalid", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius muss grösser Null sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten bilden kein gültiges Dreieck. ähnelt. ''' - Friend ReadOnly Property RadiusIfZeroOrLess() As String + Friend ReadOnly Property InvalidTriangleSides() As String Get - Return ResourceManager.GetString("RadiusIfZeroOrLess", resourceCulture) + Return ResourceManager.GetString("InvalidTriangleSides", resourceCulture) End Get End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Der Radius darf nicht negativ sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Der Polarwinkel muss im Bereich von Null bis PI liegen. ähnelt. ''' - Friend ReadOnly Property RadiusIsNegative() As String + Friend ReadOnly Property IsPolarAngleInBounds() As String Get - Return ResourceManager.GetString("RadiusIsNegative", resourceCulture) + Return ResourceManager.GetString("IsPolarAngleInBounds", resourceCulture) End Get End Property @@ -311,14 +356,5 @@ Namespace My.Resources Return ResourceManager.GetString("VerifyTopWidthLessThanBottom", resourceCulture) End Get End Property - - ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die Breite darf nicht negatv sein. ähnelt. - ''' - Friend ReadOnly Property WidthIsNegative() As String - Get - Return ResourceManager.GetString("WidthIsNegative", resourceCulture) - End Get - End Property End Module End Namespace diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index 0500f7a..e6d1651 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -123,22 +123,22 @@ Die Breite muss grösser als Null sein. - + Der Durchmesser darf nicht negativ sein. - + Die Höhe darf nicht negativ sein. Die angegebenen Seiten bilden kein gültiges Dreieck. - + Die Länge darf nicht negativ sein. - - Der Radius muss grösser Null sein. + + Der Radius muss grösser als Null sein. - + Der Radius darf nicht negativ sein. @@ -150,8 +150,8 @@ Der obere Radius muss kleiner als der untere Radius sein. - - Die Breite darf nicht negatv sein. + + Die Breite darf nicht negativ sein. Die Sehnenhöhe ist ungültig. @@ -160,7 +160,7 @@ Die Sehnenlänge ist ungültig. - Die Halbachsen müssen größer als 0 sein (a>0, b>0). + Die Halbachsen müssen größer als Null sein (a>0, b>0). Die Diagonale darf nicht negativ sein. @@ -204,4 +204,16 @@ Die Kante muss grösser als Null sein. + + Die Toleranz muss größer als Null sein. + + + Der Umfang muss grösser als Null sein. + + + Die höhe muss grösser als Null sein. + + + Die Diagonale muss grösser als Null sein. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index c0dd91c..21079f3 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -27,10 +27,10 @@ Namespace ThreeDimensional Public Shared Function Volume(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * radius * radius * height) / 3.0 @@ -46,10 +46,10 @@ Namespace ThreeDimensional Public Shared Function SlantHeight(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.Sqrt((radius * radius) + (height * height)) End Function @@ -63,10 +63,10 @@ Namespace ThreeDimensional Public Shared Function LateralArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.PI * radius * SlantHeight(radius, height) End Function @@ -80,10 +80,10 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim s = SlantHeight(radius, height) Return Math.PI * radius * (radius + s) @@ -97,7 +97,7 @@ Namespace ThreeDimensional Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * radius End Function @@ -110,7 +110,7 @@ Namespace ThreeDimensional Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diameter < 0 Then - Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiameter, NameOf(diameter)) End If Return diameter / 2.0 End Function @@ -130,7 +130,7 @@ Namespace ThreeDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (Math.PI * height / 3.0) * ((radiusBottom * radiusBottom) + (radiusBottom * radiusTop) + (radiusTop * radiusTop)) @@ -148,7 +148,7 @@ Namespace ThreeDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim s = Math.Sqrt(((radiusBottom - radiusTop) * (radiusBottom - radiusTop)) + (height * height)) Return Math.PI * (radiusBottom + radiusTop) * s @@ -165,7 +165,7 @@ Namespace ThreeDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateFrustumRadii(radiusBottom, radiusTop) If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim lateral = FrustumLateralArea(radiusBottom, radiusTop, height) Dim bases = Math.PI * ((radiusBottom * radiusBottom) + (radiusTop * radiusTop)) @@ -190,11 +190,11 @@ Namespace ThreeDimensional Public Shared Function PointOnLateralSurface(centerX As Double, centerY As Double, baseZ As Double, radius As Double, height As Double, angleRadians As Double, t As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If If t < 0 OrElse t > 1 Then Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) @@ -214,10 +214,10 @@ Namespace ThreeDimensional Private Shared Sub ValidateFrustumRadii(bottomRadius As Double, topRadius As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomRadius <= 0 Then - Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(bottomRadius)) + Throw New ArgumentException(My.Resources.CheckPositiveRadius, NameOf(bottomRadius)) End If If topRadius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(topRadius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(topRadius)) End If If topRadius >= bottomRadius Then Throw New ArgumentException(My.Resources.VerifyTopRadiusLessThanBottom, NameOf(topRadius)) diff --git a/Geometry/ThreeDimensional/Cube.vb b/Geometry/ThreeDimensional/Cube.vb index 10fe53f..7d7cd73 100644 --- a/Geometry/ThreeDimensional/Cube.vb +++ b/Geometry/ThreeDimensional/Cube.vb @@ -26,7 +26,7 @@ Namespace ThreeDimensional Public Shared Function Volume(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side * side * side End Function @@ -39,7 +39,7 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return 6.0 * side * side End Function @@ -52,7 +52,7 @@ Namespace ThreeDimensional Public Shared Function SpaceDiagonal(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side * Math.Sqrt(3.0) End Function @@ -65,7 +65,7 @@ Namespace ThreeDimensional Public Shared Function FaceDiagonal(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side * Math.Sqrt(2.0) End Function @@ -139,7 +139,7 @@ Namespace ThreeDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, side As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Dim h = side / 2.0 diff --git a/Geometry/ThreeDimensional/Cuboid.vb b/Geometry/ThreeDimensional/Cuboid.vb index 3e79e71..6f87baf 100644 --- a/Geometry/ThreeDimensional/Cuboid.vb +++ b/Geometry/ThreeDimensional/Cuboid.vb @@ -28,13 +28,13 @@ Namespace ThreeDimensional Public Shared Function Volume(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return length * width * height @@ -50,13 +50,13 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return 2.0 * ((length * width) + (length * height) + (width * height)) @@ -72,13 +72,13 @@ Namespace ThreeDimensional Public Shared Function SpaceDiagonal(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.Sqrt((length * length) + (width * width) + (height * height)) @@ -93,10 +93,10 @@ Namespace ThreeDimensional Public Shared Function FaceDiagonalLengthWidth(length As Double, width As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If Return Math.Sqrt((length * length) + (width * width)) End Function @@ -110,10 +110,10 @@ Namespace ThreeDimensional Public Shared Function FaceDiagonalLengthHeight(length As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.Sqrt((length * length) + (height * height)) End Function @@ -127,10 +127,10 @@ Namespace ThreeDimensional Public Shared Function FaceDiagonalWidthHeight(width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.Sqrt((width * width) + (height * height)) End Function @@ -167,16 +167,16 @@ Namespace ThreeDimensional Public Shared Function IsCube(length As Double, width As Double, height As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Return Math.Abs(length - width) <= tolerance AndAlso Math.Abs(length - height) <= tolerance @@ -214,13 +214,13 @@ Namespace ThreeDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, length As Double, width As Double, height As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim lx = length / 2.0 diff --git a/Geometry/ThreeDimensional/Cylinder.vb b/Geometry/ThreeDimensional/Cylinder.vb index 636f979..4758656 100644 --- a/Geometry/ThreeDimensional/Cylinder.vb +++ b/Geometry/ThreeDimensional/Cylinder.vb @@ -27,10 +27,10 @@ Namespace ThreeDimensional Public Shared Function Volume(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.PI * radius * radius * height End Function @@ -44,10 +44,10 @@ Namespace ThreeDimensional Public Shared Function LateralArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return 2.0 * Math.PI * radius * height End Function @@ -61,10 +61,10 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(radius As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return 2.0 * Math.PI * radius * (radius + height) End Function @@ -77,7 +77,7 @@ Namespace ThreeDimensional Public Shared Function BaseCircumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * Math.PI * radius End Function @@ -90,7 +90,7 @@ Namespace ThreeDimensional Public Shared Function BaseArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return Math.PI * radius * radius End Function @@ -103,7 +103,7 @@ Namespace ThreeDimensional Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * radius End Function @@ -116,7 +116,7 @@ Namespace ThreeDimensional Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diameter < 0 Then - Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiameter, NameOf(diameter)) End If Return diameter / 2.0 End Function @@ -136,7 +136,7 @@ Namespace ThreeDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateHollowRadii(outerRadius, innerRadius) If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Math.PI * ((outerRadius * outerRadius) - (innerRadius * innerRadius)) * height End Function @@ -152,7 +152,7 @@ Namespace ThreeDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateHollowRadii(outerRadius, innerRadius) If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim outerLateral = 2.0 * Math.PI * outerRadius * height @@ -179,10 +179,10 @@ Namespace ThreeDimensional Public Shared Function PointOnLateralSurface(centerX As Double, centerY As Double, baseZ As Double, radius As Double, height As Double, angleRadians As Double, heightOffset As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If If heightOffset < 0 OrElse heightOffset > height Then Throw New ArgumentException(My.Resources.VerifyOffsetWithinHeight, NameOf(heightOffset)) @@ -202,10 +202,10 @@ Namespace ThreeDimensional Private Shared Sub ValidateHollowRadii(outerRadius As Double, innerRadius As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If outerRadius <= 0 Then - Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(outerRadius)) + Throw New ArgumentException(My.Resources.CheckPositiveRadius, NameOf(outerRadius)) End If If innerRadius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(innerRadius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(innerRadius)) End If If innerRadius >= outerRadius Then Throw New ArgumentException(My.Resources.VerifyInnerLessThanOuter, NameOf(innerRadius)) diff --git a/Geometry/ThreeDimensional/Frustum.vb b/Geometry/ThreeDimensional/Frustum.vb index 23982be..668707a 100644 --- a/Geometry/ThreeDimensional/Frustum.vb +++ b/Geometry/ThreeDimensional/Frustum.vb @@ -138,7 +138,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(topArea)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -162,7 +162,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(topPerimeter)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -194,7 +194,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(topPerimeter)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return bottomArea + topArea + PrismFrustumLateralArea(bottomPerimeter, topPerimeter, height) @@ -207,16 +207,16 @@ Namespace ThreeDimensional Private Shared Sub ValidateConeFrustumInputs(bottomRadius As Double, topRadius As Double, height As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If bottomRadius <= 0 Then - Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(bottomRadius)) + Throw New ArgumentException(My.Resources.CheckPositiveRadius, NameOf(bottomRadius)) End If If topRadius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(topRadius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(topRadius)) End If If topRadius >= bottomRadius Then Throw New ArgumentException(My.Resources.VerifyTopRadiusLessThanBottom, NameOf(topRadius)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If End Sub @@ -229,10 +229,10 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckPositiveWidth, NameOf(bottomWidth)) End If If topLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(topLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(topLength)) End If If topWidth < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(topWidth)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(topWidth)) End If If topLength >= bottomLength Then Throw New ArgumentException(My.Resources.String2, NameOf(topLength)) @@ -241,7 +241,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.String3, NameOf(topWidth)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If End Sub diff --git a/Geometry/ThreeDimensional/Prism.vb b/Geometry/ThreeDimensional/Prism.vb index 5976571..3359cd5 100644 --- a/Geometry/ThreeDimensional/Prism.vb +++ b/Geometry/ThreeDimensional/Prism.vb @@ -30,7 +30,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(baseArea)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return baseArea * height End Function @@ -47,7 +47,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(basePerimeter)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return basePerimeter * height End Function @@ -68,7 +68,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(basePerimeter)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return (2.0 * baseArea) + LateralArea(basePerimeter, height) End Function @@ -103,7 +103,7 @@ Namespace ThreeDimensional Public Shared Function TriangularPrismVolume(sideA As Double, sideB As Double, sideC As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return Volume(TriangularBaseArea(sideA, sideB, sideC), height) End Function @@ -119,7 +119,7 @@ Namespace ThreeDimensional Public Shared Function TriangularPrismSurfaceArea(sideA As Double, sideB As Double, sideC As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim baseArea = TriangularBaseArea(sideA, sideB, sideC) Dim basePerimeter = sideA + sideB + sideC @@ -135,7 +135,7 @@ Namespace ThreeDimensional Public Shared Function RegularPolygonBaseArea(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideLength)) End If ValidateSideCount(sideCount) @@ -155,7 +155,7 @@ Namespace ThreeDimensional Public Shared Function RegularPolygonPrismVolume(sideLength As Double, sideCount As Integer, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim baseArea = RegularPolygonBaseArea(sideLength, sideCount) Return Volume(baseArea, height) @@ -171,7 +171,7 @@ Namespace ThreeDimensional Public Shared Function RegularPolygonPrismSurfaceArea(sideLength As Double, sideCount As Integer, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim baseArea = RegularPolygonBaseArea(sideLength, sideCount) Dim basePerimeter = sideCount * sideLength diff --git a/Geometry/ThreeDimensional/Pyramid.vb b/Geometry/ThreeDimensional/Pyramid.vb index bedf334..154f2dd 100644 --- a/Geometry/ThreeDimensional/Pyramid.vb +++ b/Geometry/ThreeDimensional/Pyramid.vb @@ -27,10 +27,10 @@ Namespace ThreeDimensional Public Shared Function BaseArea(length As Double, width As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If Return length * width End Function @@ -45,13 +45,13 @@ Namespace ThreeDimensional Public Shared Function Volume(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -68,10 +68,10 @@ Namespace ThreeDimensional Public Shared Function SlantHeightLengthFace(width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim halfWidth = width / 2.0 @@ -87,10 +87,10 @@ Namespace ThreeDimensional Public Shared Function SlantHeightWidthFace(length As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim halfLength = length / 2.0 @@ -107,13 +107,13 @@ Namespace ThreeDimensional Public Shared Function LateralArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim slantLen = SlantHeightLengthFace(width, height) @@ -131,13 +131,13 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(length As Double, width As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return BaseArea(length, width) + LateralArea(length, width, height) @@ -235,13 +235,13 @@ Namespace ThreeDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, cz As Double, length As Double, width As Double, height As Double) As Tuple(Of Double, Double, Double)() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If length < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(length)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(length)) End If If width < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(width)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(width)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim halfLength = length / 2.0 @@ -270,10 +270,10 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckPositiveWidth, NameOf(bottomWidth)) End If If topLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(topLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(topLength)) End If If topWidth < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(topWidth)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(topWidth)) End If If topLength >= bottomLength Then Throw New ArgumentException(My.Resources.VerifyTopLengthLessThanBottom, NameOf(topLength)) @@ -282,7 +282,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.VerifyTopWidthLessThanBottom, NameOf(topWidth)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If End Sub diff --git a/Geometry/ThreeDimensional/Sphere.vb b/Geometry/ThreeDimensional/Sphere.vb index 4d70084..3aacd80 100644 --- a/Geometry/ThreeDimensional/Sphere.vb +++ b/Geometry/ThreeDimensional/Sphere.vb @@ -26,7 +26,7 @@ Namespace ThreeDimensional Public Shared Function Volume(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -42,7 +42,7 @@ Namespace ThreeDimensional Public Shared Function SurfaceArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 4.0 * Math.PI * radius * radius End Function @@ -55,7 +55,7 @@ Namespace ThreeDimensional Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * radius End Function @@ -68,7 +68,7 @@ Namespace ThreeDimensional Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diameter < 0 Then - Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiameter, NameOf(diameter)) End If Return diameter / 2.0 End Function @@ -81,7 +81,7 @@ Namespace ThreeDimensional Public Shared Function GreatCircleCircumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * Math.PI * radius End Function @@ -94,7 +94,7 @@ Namespace ThreeDimensional Public Shared Function GreatCircleArea(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return Math.PI * radius * radius End Function @@ -144,7 +144,7 @@ Namespace ThreeDimensional Public Shared Function PointOnSphere(centerX As Double, centerY As Double, centerZ As Double, radius As Double, polarAngleRadians As Double, azimuthRadians As Double) As Tuple(Of Double, Double, Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If polarAngleRadians < 0 OrElse polarAngleRadians > Math.PI Then Throw New ArgumentException(My.Resources.IsPolarAngleInBounds, NameOf(polarAngleRadians)) @@ -165,10 +165,10 @@ Namespace ThreeDimensional Private Shared Sub ValidateCapInputs(radius As Double, capHeight As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius <= 0 Then - Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckPositiveRadius, NameOf(radius)) End If If capHeight < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(capHeight)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(capHeight)) End If If capHeight > 2.0 * radius Then Throw New ArgumentException(My.Resources.CheckCapHeightLimit, NameOf(capHeight)) diff --git a/Geometry/TwoDimensional/Circle.vb b/Geometry/TwoDimensional/Circle.vb index 854e8c3..80755e0 100644 --- a/Geometry/TwoDimensional/Circle.vb +++ b/Geometry/TwoDimensional/Circle.vb @@ -28,7 +28,7 @@ Namespace TwoDimensional Public Shared Function Area(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return Math.PI * radius * radius @@ -52,7 +52,7 @@ Namespace TwoDimensional Public Shared Function Circumference(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * Math.PI * radius End Function @@ -75,7 +75,7 @@ Namespace TwoDimensional Public Shared Function DiameterFromRadius(radius As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * radius End Function @@ -88,7 +88,7 @@ Namespace TwoDimensional Public Shared Function RadiusFromDiameter(diameter As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diameter < 0 Then - Throw New ArgumentException(My.Resources.DiameterIsNegative, NameOf(diameter)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiameter, NameOf(diameter)) End If Return diameter / 2.0 End Function @@ -106,7 +106,7 @@ Namespace TwoDimensional Public Shared Function ArcLength(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return radius * angleRadians End Function @@ -132,7 +132,7 @@ Namespace TwoDimensional Public Shared Function SectorArea(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 0.5 * radius * radius * angleRadians End Function @@ -158,7 +158,7 @@ Namespace TwoDimensional Public Shared Function ChordLength(radius As Double, angleRadians As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Return 2.0 * radius * Math.Sin(angleRadians / 2.0) End Function @@ -172,7 +172,7 @@ Namespace TwoDimensional Public Shared Function ChordLengthFromSagitta(radius As Double, sagitta As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If If sagitta < 0 Or sagitta > radius Then Throw New ArgumentException(My.Resources.SagittaHeightInvalid, NameOf(sagitta)) @@ -194,7 +194,7 @@ Namespace TwoDimensional Public Shared Function AngleFromArcLength(radius As Double, arcLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius <= 0 Then - Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckPositiveRadius, NameOf(radius)) End If Return arcLength / radius End Function @@ -208,7 +208,7 @@ Namespace TwoDimensional Public Shared Function AngleFromChordLength(radius As Double, chordLength As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius <= 0 Then - Throw New ArgumentException(My.Resources.RadiusIfZeroOrLess, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckPositiveRadius, NameOf(radius)) End If If chordLength < 0 OrElse chordLength > 2.0 * radius Then Throw New ArgumentException(My.Resources.ChordLengthInvalid, NameOf(chordLength)) @@ -232,7 +232,7 @@ Namespace TwoDimensional Public Shared Function PointOnCircle(cx As Double, cy As Double, radius As Double, angleRadians As Double) As PointF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Dim x As Single = CSng(cx + (radius * Math.Cos(angleRadians))) @@ -250,7 +250,7 @@ Namespace TwoDimensional Public Shared Function BoundingBox(cx As Double, cy As Double, radius As Double) As RectangleF ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If radius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(radius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(radius)) End If Dim x As Single = CSng(cx - radius) Dim y As Single = CSng(cy - radius) diff --git a/Geometry/TwoDimensional/Kite.vb b/Geometry/TwoDimensional/Kite.vb index c925a64..f9c7ab6 100644 --- a/Geometry/TwoDimensional/Kite.vb +++ b/Geometry/TwoDimensional/Kite.vb @@ -48,10 +48,10 @@ Namespace TwoDimensional Public Shared Function Perimeter(sideA As Double, sideB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideA < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideA)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideA)) End If If sideB < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideB)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideB)) End If Return 2.0 * (sideA + sideB) End Function @@ -65,10 +65,10 @@ Namespace TwoDimensional Public Shared Function AreaFromBaseHeight(baseLength As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(baseLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(baseLength)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return baseLength * height End Function @@ -85,7 +85,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If baseLength <= 0 Then - Throw New ArgumentException("Die Grundseite muss größer als 0 sein.", NameOf(baseLength)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(baseLength)) End If Return area / baseLength End Function @@ -102,19 +102,19 @@ Namespace TwoDimensional Public Shared Function IsSymmetricBySides(sideA As Double, sideB As Double, sideC As Double, sideD As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideA < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideA)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideA)) End If If sideB < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideB)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideB)) End If If sideC < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideC)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideC)) End If If sideD < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideD)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideD)) End If If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim firstPair = Math.Abs(sideA - sideB) <= tolerance AndAlso Math.Abs(sideC - sideD) <= tolerance @@ -209,7 +209,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim l0 = Distance(vertices(0), vertices(1)) diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index a41f8f2..2065ca7 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -32,7 +32,7 @@ Namespace TwoDimensional Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) End If If h < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(h)) End If Return b * h @@ -68,7 +68,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If b <= 0 Then - Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If Return area / b @@ -109,10 +109,10 @@ Namespace TwoDimensional Public Shared Function DiagonalBySidesAndAngle(a As Double, b As Double, includedAngleRadians As Double) As Double() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If a <= 0 Then - Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(a)) End If If b <= 0 Then - Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If If includedAngleRadians <= 0 OrElse includedAngleRadians >= Math.PI Then Throw New ArgumentException("Der eingeschlossene Winkel muss zwischen 0 und PI liegen.", NameOf(includedAngleRadians)) @@ -136,16 +136,16 @@ Namespace TwoDimensional Public Shared Function InteriorAngleFromSidesAndDiagonals(a As Double, b As Double, d1 As Double, d2 As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If a <= 0 Then - Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(a)) End If If b <= 0 Then - Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If If d1 <= 0 Then - Throw New ArgumentException("Diagonale d1 muss größer als 0 sein.", NameOf(d1)) + Throw New ArgumentException(My.Resources.CheckPositiveDiagonal, NameOf(d1)) End If If d2 <= 0 Then - Throw New ArgumentException("Diagonale d2 muss größer als 0 sein.", NameOf(d2)) + Throw New ArgumentException(My.Resources.CheckPositiveDiagonal, NameOf(d2)) End If Dim denominator = 4.0 * a * b @@ -188,10 +188,10 @@ Namespace TwoDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, a As Double, b As Double, includedAngleRadians As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If a <= 0 Then - Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(a)) End If If b <= 0 Then - Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If If includedAngleRadians <= 0 OrElse includedAngleRadians >= Math.PI Then Throw New ArgumentException("Der eingeschlossene Winkel muss zwischen 0 und PI liegen.", NameOf(includedAngleRadians)) @@ -277,7 +277,7 @@ Namespace TwoDimensional Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) End If If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim midpointDiagonal1 = Center(vertices(0).X, vertices(0).Y, vertices(2).X, vertices(2).Y) diff --git a/Geometry/TwoDimensional/Polygon.vb b/Geometry/TwoDimensional/Polygon.vb index c5aeb41..bd1637a 100644 --- a/Geometry/TwoDimensional/Polygon.vb +++ b/Geometry/TwoDimensional/Polygon.vb @@ -66,7 +66,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices, 3) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim hasPositive As Boolean = False @@ -99,7 +99,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices, 3) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If If Not IsConvex(vertices, tolerance) Then Return False diff --git a/Geometry/TwoDimensional/Rectangle.vb b/Geometry/TwoDimensional/Rectangle.vb index 822b67b..71ce34f 100644 --- a/Geometry/TwoDimensional/Rectangle.vb +++ b/Geometry/TwoDimensional/Rectangle.vb @@ -29,10 +29,10 @@ Namespace TwoDimensional Public Shared Function Area(w As Double, h As Double) As Double ' Guard-Clauses: negative Werte sind nicht erlaubt If w < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(w)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(w)) End If If h < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(h)) End If Return w * h End Function @@ -46,10 +46,10 @@ Namespace TwoDimensional Public Shared Function Perimeter(w As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If w < 0 Then - Throw New ArgumentException(My.Resources.WidthIsNegative, NameOf(w)) + Throw New ArgumentException(My.Resources.CheckNonNegativeWidth, NameOf(w)) End If If h < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(h)) End If Return 2.0 * (w + h) End Function @@ -256,7 +256,7 @@ Namespace TwoDimensional Public Shared Function AreaSquare(s As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If s < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(s)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(s)) End If Return s * s End Function @@ -267,7 +267,7 @@ Namespace TwoDimensional Public Shared Function PerimeterSquare(s As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If s < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(s)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(s)) End If Return 4.0 * s End Function diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index a199382..0b49802 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -29,7 +29,7 @@ Namespace TwoDimensional Public Shared Function Perimeter(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideLength)) End If ValidateSideCount(sideCount) Return sideCount * sideLength @@ -70,7 +70,7 @@ Namespace TwoDimensional Public Shared Function Apothem(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideLength)) End If ValidateSideCount(sideCount) @@ -87,7 +87,7 @@ Namespace TwoDimensional Public Shared Function Circumradius(sideLength As Double, sideCount As Integer) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If sideLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(sideLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(sideLength)) End If ValidateSideCount(sideCount) @@ -140,7 +140,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateSideCount(sideCount) If circumradius < 0 Then - Throw New ArgumentException(My.Resources.RadiusIsNegative, NameOf(circumradius)) + Throw New ArgumentException(My.Resources.CheckNonNegativeRadius, NameOf(circumradius)) End If Dim result(sideCount - 1) As PointF @@ -204,7 +204,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices, 3) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If If AreaFromVertices(vertices) <= tolerance Then Return False diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index 894ecf9..f4402e0 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -29,10 +29,10 @@ Namespace TwoDimensional Public Shared Function AreaFromBaseHeight(baseLength As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseLength < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(baseLength)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(baseLength)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Return baseLength * height End Function @@ -64,7 +64,7 @@ Namespace TwoDimensional Public Shared Function Perimeter(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return 4.0 * side End Function @@ -119,7 +119,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If perimeter <= 0 Then - Throw New ArgumentException("Der Umfang muss größer als 0 sein.", NameOf(perimeter)) + Throw New ArgumentException(My.Resources.CheckPositiveCircumference, NameOf(perimeter)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen Return (2.0 * area) / perimeter @@ -206,7 +206,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim lengths(3) As Double diff --git a/Geometry/TwoDimensional/Square.vb b/Geometry/TwoDimensional/Square.vb index 3c4e90b..4988a38 100644 --- a/Geometry/TwoDimensional/Square.vb +++ b/Geometry/TwoDimensional/Square.vb @@ -28,7 +28,7 @@ Namespace TwoDimensional Public Shared Function Area(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side * side End Function @@ -41,7 +41,7 @@ Namespace TwoDimensional Public Shared Function Perimeter(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return 4.0 * side End Function @@ -54,7 +54,7 @@ Namespace TwoDimensional Public Shared Function Diagonal(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side * Math.Sqrt(2.0) End Function @@ -80,7 +80,7 @@ Namespace TwoDimensional Public Shared Function Inradius(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side / 2.0 End Function @@ -93,7 +93,7 @@ Namespace TwoDimensional Public Shared Function Circumradius(side As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Return side / Math.Sqrt(2.0) End Function @@ -113,7 +113,7 @@ Namespace TwoDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, side As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If side < 0 Then - Throw New ArgumentException(My.Resources.LengthIsNegative, NameOf(side)) + Throw New ArgumentException(My.Resources.CheckNonNegativeLength, NameOf(side)) End If Dim halfSide = side / 2.0 @@ -183,7 +183,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim lengths(3) As Double diff --git a/Geometry/TwoDimensional/Trapezoid.vb b/Geometry/TwoDimensional/Trapezoid.vb index 38ce40c..766ecf9 100644 --- a/Geometry/TwoDimensional/Trapezoid.vb +++ b/Geometry/TwoDimensional/Trapezoid.vb @@ -36,7 +36,7 @@ Namespace TwoDimensional Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -55,16 +55,16 @@ Namespace TwoDimensional Public Shared Function Perimeter(baseA As Double, legB As Double, baseC As Double, legD As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseA <= 0 Then - Throw New ArgumentException("Grundseite a muss größer als 0 sein.", NameOf(baseA)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(baseA)) End If If legB <= 0 Then - Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(legB)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(legB)) End If If baseC <= 0 Then - Throw New ArgumentException("Grundseite c muss größer als 0 sein.", NameOf(baseC)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(baseC)) End If If legD <= 0 Then - Throw New ArgumentException("Seite d muss größer als 0 sein.", NameOf(legD)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(legD)) End If Return baseA + legB + baseC + legD @@ -133,7 +133,7 @@ Namespace TwoDimensional Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) End If If height < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(height)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If Dim halfDiff = Math.Abs(baseA - baseB) / 2.0 @@ -150,13 +150,13 @@ Namespace TwoDimensional Public Shared Function IsIsosceles(legB As Double, legD As Double, Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If legB <= 0 Then - Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(legB)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(legB)) End If If legD <= 0 Then - Throw New ArgumentException("Seite d muss größer als 0 sein.", NameOf(legD)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(legD)) End If If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Return Math.Abs(legB - legD) <= tolerance @@ -179,13 +179,13 @@ Namespace TwoDimensional Public Shared Function VerticesFromCenter(cx As Double, cy As Double, baseA As Double, baseB As Double, height As Double, rotationRadians As Double) As PointF() ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseA <= 0 Then - Throw New ArgumentException("Grundseite a muss größer als 0 sein.", NameOf(baseA)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(baseA)) End If If baseB <= 0 Then - Throw New ArgumentException("Grundseite c muss größer als 0 sein.", NameOf(baseB)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(baseB)) End If If height <= 0 Then - Throw New ArgumentException("Höhe muss größer als 0 sein.", NameOf(height)) + Throw New ArgumentException(My.Resources.CheckPositiveHeight, NameOf(height)) End If Dim halfA = baseA / 2.0 @@ -258,7 +258,7 @@ Namespace TwoDimensional ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. ValidateVertices(vertices) If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If Dim ab = New PointF(vertices(1).X - vertices(0).X, vertices(1).Y - vertices(0).Y) diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index c1914a6..6e25a44 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -32,7 +32,7 @@ Namespace TwoDimensional Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) End If If h < 0 Then - Throw New ArgumentException(My.Resources.HeightIsNegative, NameOf(h)) + Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(h)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -65,7 +65,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If b <= 0 Then - Throw New ArgumentException("Grundseite muss größer als 0 sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen @@ -177,7 +177,7 @@ Namespace TwoDimensional Public Shared Function IsValidTriangleFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If tolerance <= 0 Then - Throw New ArgumentException("Die Toleranz muss größer als 0 sein.", NameOf(tolerance)) + Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) End If ValidateVertices(vertices) @@ -191,13 +191,13 @@ Namespace TwoDimensional Private Shared Sub ValidateSides(a As Double, b As Double, c As Double) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If a <= 0 Then - Throw New ArgumentException("Seite a muss größer als 0 sein.", NameOf(a)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(a)) End If If b <= 0 Then - Throw New ArgumentException("Seite b muss größer als 0 sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If If c <= 0 Then - Throw New ArgumentException("Seite c muss größer als 0 sein.", NameOf(c)) + Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(c)) End If If a + b <= c OrElse a + c <= b OrElse b + c <= a Then Throw New ArgumentException(My.Resources.InvalidTriangleSides) From 4a0039677d401acb30f4bd52ee46765dd1206445 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Thu, 8 Oct 2026 19:06:47 +0200 Subject: [PATCH 19/22] Validierungsfehler zentralisiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue Lokalisierungseinträge für CheckNonNegativeSide, CheckVerticesNotNull und RequireExactlyFourVertices ergänzt und die Geometrieklassen Cube, Kite, Parallelogram, Polygon, Rectangle, Rhombus, Square, Trapezoid und Triangle auf die zentralen Ressourcen umgestellt. --- Geometry/My Project/Resources.Designer.vb | 27 +++++++++++++++++++++++ Geometry/My Project/Resources.resx | 9 ++++++++ Geometry/ThreeDimensional/Cube.vb | 2 +- Geometry/TwoDimensional/Kite.vb | 4 ++-- Geometry/TwoDimensional/Parallelogram.vb | 16 +++++++------- Geometry/TwoDimensional/Polygon.vb | 2 +- Geometry/TwoDimensional/Rectangle.vb | 2 +- Geometry/TwoDimensional/Rhombus.vb | 4 ++-- Geometry/TwoDimensional/Square.vb | 6 ++--- Geometry/TwoDimensional/Trapezoid.vb | 20 ++++++++--------- Geometry/TwoDimensional/Triangle.vb | 4 ++-- 11 files changed, 66 insertions(+), 30 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 4a5f97a..1f956ee 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -132,6 +132,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Seite darf nicht negativ sein. ähnelt. + ''' + Friend ReadOnly Property CheckNonNegativeSide() As String + Get + Return ResourceManager.GetString("CheckNonNegativeSide", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Das Volumen darf nicht negativ sein. ähnelt. ''' @@ -240,6 +249,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Eckpunkte dürfen nicht Nothing sein. ähnelt. + ''' + Friend ReadOnly Property CheckVerticesNotNull() As String + Get + Return ResourceManager.GetString("CheckVerticesNotNull", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenlänge ist ungültig. ähnelt. ''' @@ -276,6 +294,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Es müssen genau 4 Eckpunkte angegeben werden. ähnelt. + ''' + Friend ReadOnly Property RequireExactlyFourVertices() As String + Get + Return ResourceManager.GetString("RequireExactlyFourVertices", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenhöhe ist ungültig. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index e6d1651..d2cf95f 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -216,4 +216,13 @@ Die Diagonale muss grösser als Null sein. + + Die Seite darf nicht negativ sein. + + + Die Eckpunkte dürfen nicht Nothing sein. + + + Es müssen genau 4 Eckpunkte angegeben werden. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cube.vb b/Geometry/ThreeDimensional/Cube.vb index 7d7cd73..ccb7db8 100644 --- a/Geometry/ThreeDimensional/Cube.vb +++ b/Geometry/ThreeDimensional/Cube.vb @@ -104,7 +104,7 @@ Namespace ThreeDimensional Public Shared Function SideFromSpaceDiagonal(spaceDiagonal As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If spaceDiagonal < 0 Then - Throw New ArgumentException("Die Raumdiagonale darf nicht negativ sein.", NameOf(spaceDiagonal)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(spaceDiagonal)) End If Return spaceDiagonal / Math.Sqrt(3.0) End Function diff --git a/Geometry/TwoDimensional/Kite.vb b/Geometry/TwoDimensional/Kite.vb index f9c7ab6..9926ff0 100644 --- a/Geometry/TwoDimensional/Kite.vb +++ b/Geometry/TwoDimensional/Kite.vb @@ -229,10 +229,10 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 4 Then - Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireExactlyFourVertices, NameOf(vertices)) End If End Sub diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index 2065ca7..95211d6 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -29,7 +29,7 @@ Namespace TwoDimensional Public Shared Function Area(b As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If b < 0 Then - Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(b)) End If If h < 0 Then Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(h)) @@ -47,10 +47,10 @@ Namespace TwoDimensional Public Shared Function Perimeter(a As Double, b As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If a < 0 Then - Throw New ArgumentException("Seite a darf nicht negativ sein.", NameOf(a)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(a)) End If If b < 0 Then - Throw New ArgumentException("Seite b darf nicht negativ sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(b)) End If Return 2.0 * (a + b) @@ -90,7 +90,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeCircumference, NameOf(perimeter)) End If If knownSide < 0 Then - Throw New ArgumentException("Bekannte Seite darf nicht negativ sein.", NameOf(knownSide)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(knownSide)) End If If perimeter <= 2.0 * knownSide Then Throw New ArgumentException("Umfang ist für die angegebene Seite zu klein.", NameOf(perimeter)) @@ -222,7 +222,7 @@ Namespace TwoDimensional Public Shared Function AreaFromVertices(vertices As PointF()) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < 3 Then Throw New ArgumentException("Es müssen mindestens 3 Eckpunkte angegeben werden.", NameOf(vertices)) @@ -245,7 +245,7 @@ Namespace TwoDimensional Public Shared Function PerimeterFromVertices(vertices As PointF()) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < 2 Then Throw New ArgumentException("Es müssen mindestens 2 Eckpunkte angegeben werden.", NameOf(vertices)) @@ -271,10 +271,10 @@ Namespace TwoDimensional Public Shared Function IsParallelogramFromVertices(vertices As PointF(), Optional tolerance As Double = 0.000001) As Boolean ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 4 Then - Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireExactlyFourVertices, NameOf(vertices)) End If If tolerance <= 0 Then Throw New ArgumentException(My.Resources.CheckPositiveTolerance, NameOf(tolerance)) diff --git a/Geometry/TwoDimensional/Polygon.vb b/Geometry/TwoDimensional/Polygon.vb index bd1637a..8c5dc24 100644 --- a/Geometry/TwoDimensional/Polygon.vb +++ b/Geometry/TwoDimensional/Polygon.vb @@ -226,7 +226,7 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF(), minCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < minCount Then Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte angegeben werden.", NameOf(vertices)) diff --git a/Geometry/TwoDimensional/Rectangle.vb b/Geometry/TwoDimensional/Rectangle.vb index 71ce34f..d271727 100644 --- a/Geometry/TwoDimensional/Rectangle.vb +++ b/Geometry/TwoDimensional/Rectangle.vb @@ -286,7 +286,7 @@ Namespace TwoDimensional Public Shared Function FromDiagonalToSide(d As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If d < 0 Then - Throw New ArgumentException("Diagonale darf nicht negativ sein.", NameOf(d)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(d)) End If Return d / Math.Sqrt(2.0) End Function diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index f4402e0..b5a2627 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -230,10 +230,10 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 4 Then - Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireExactlyFourVertices, NameOf(vertices)) End If End Sub diff --git a/Geometry/TwoDimensional/Square.vb b/Geometry/TwoDimensional/Square.vb index 4988a38..90597ce 100644 --- a/Geometry/TwoDimensional/Square.vb +++ b/Geometry/TwoDimensional/Square.vb @@ -67,7 +67,7 @@ Namespace TwoDimensional Public Shared Function SideFromDiagonal(diagonal As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If diagonal < 0 Then - Throw New ArgumentException("Diagonale darf nicht negativ sein.", NameOf(diagonal)) + Throw New ArgumentException(My.Resources.CheckNonNegativeDiagonal, NameOf(diagonal)) End If Return diagonal / Math.Sqrt(2.0) End Function @@ -222,10 +222,10 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 4 Then - Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireExactlyFourVertices, NameOf(vertices)) End If End Sub diff --git a/Geometry/TwoDimensional/Trapezoid.vb b/Geometry/TwoDimensional/Trapezoid.vb index 766ecf9..303e360 100644 --- a/Geometry/TwoDimensional/Trapezoid.vb +++ b/Geometry/TwoDimensional/Trapezoid.vb @@ -30,10 +30,10 @@ Namespace TwoDimensional Public Shared Function Area(baseA As Double, baseB As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseA < 0 Then - Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseA)) End If If baseB < 0 Then - Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseB)) End If If height < 0 Then Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) @@ -79,10 +79,10 @@ Namespace TwoDimensional Public Shared Function Midline(baseA As Double, baseB As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseA < 0 Then - Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseA)) End If If baseB < 0 Then - Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseB)) End If Return (baseA + baseB) / 2.0 @@ -101,10 +101,10 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeArea, NameOf(area)) End If If baseA < 0 Then - Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseA)) End If If baseB < 0 Then - Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseB)) End If Dim denominator = baseA + baseB @@ -127,10 +127,10 @@ Namespace TwoDimensional Public Shared Function LegLengthIsosceles(baseA As Double, baseB As Double, height As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If baseA < 0 Then - Throw New ArgumentException("Grundseite a darf nicht negativ sein.", NameOf(baseA)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseA)) End If If baseB < 0 Then - Throw New ArgumentException("Grundseite c darf nicht negativ sein.", NameOf(baseB)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(baseB)) End If If height < 0 Then Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) @@ -279,10 +279,10 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 4 Then - Throw New ArgumentException("Es müssen genau 4 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireExactlyFourVertices, NameOf(vertices)) End If End Sub diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index 6e25a44..777e7fc 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -29,7 +29,7 @@ Namespace TwoDimensional Public Shared Function Area(b As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If b < 0 Then - Throw New ArgumentException("Grundseite darf nicht negativ sein.", NameOf(b)) + Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(b)) End If If h < 0 Then Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(h)) @@ -207,7 +207,7 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF()) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Die Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 3 Then Throw New ArgumentException("Es müssen genau 3 Eckpunkte angegeben werden.", NameOf(vertices)) From bf50b159de9111f981e22fe83472503987715c82 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Thu, 8 Oct 2026 19:30:02 +0200 Subject: [PATCH 20/22] =?UTF-8?q?Winkelvalidierung=20und=20Ressourcen=20er?= =?UTF-8?q?g=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neue Ressource `IncludedAngleMustBeBetweenZeroAndPi` für die Prüfung eingeschlossener Winkel in `Parallelogram`, `Rhombus` und weiteren Geometrie-Methoden verwendet; in `RegularPolygon` wurde die direkte Fehlermeldung für `Nothing`-Eckpunkte durch `CheckVerticesNotNull` ersetzt. --- Geometry/My Project/Resources.Designer.vb | 9 +++++++++ Geometry/My Project/Resources.resx | 3 +++ Geometry/TwoDimensional/Parallelogram.vb | 4 ++-- Geometry/TwoDimensional/RegularPolygon.vb | 2 +- Geometry/TwoDimensional/Rhombus.vb | 4 ++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 1f956ee..02c45cd 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -267,6 +267,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die ähnelt. + ''' + Friend ReadOnly Property IncludedAngleMustBeBetweenZeroAndPi() As String + Get + Return ResourceManager.GetString("IncludedAngleMustBeBetweenZeroAndPi", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten bilden kein gültiges Dreieck. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index d2cf95f..d0f987d 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -225,4 +225,7 @@ Es müssen genau 4 Eckpunkte angegeben werden. + + + \ No newline at end of file diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index 95211d6..36780a7 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -115,7 +115,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If If includedAngleRadians <= 0 OrElse includedAngleRadians >= Math.PI Then - Throw New ArgumentException("Der eingeschlossene Winkel muss zwischen 0 und PI liegen.", NameOf(includedAngleRadians)) + Throw New ArgumentException(My.Resources.IncludedAngleMustBeBetweenZeroAndPi, NameOf(includedAngleRadians)) End If Dim cosValue = Math.Cos(includedAngleRadians) @@ -194,7 +194,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckPositiveSide, NameOf(b)) End If If includedAngleRadians <= 0 OrElse includedAngleRadians >= Math.PI Then - Throw New ArgumentException("Der eingeschlossene Winkel muss zwischen 0 und PI liegen.", NameOf(includedAngleRadians)) + Throw New ArgumentException(My.Resources.IncludedAngleMustBeBetweenZeroAndPi, NameOf(includedAngleRadians)) End If Dim halfA = a / 2.0 diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index 0b49802..e37b530 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -242,7 +242,7 @@ Namespace TwoDimensional Private Shared Sub ValidateVertices(vertices As PointF(), minCount As Integer) ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If vertices Is Nothing Then - Throw New ArgumentException("Eckpunkte dürfen nicht Nothing sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < minCount Then Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte vorhanden sein.", NameOf(vertices)) diff --git a/Geometry/TwoDimensional/Rhombus.vb b/Geometry/TwoDimensional/Rhombus.vb index b5a2627..32fcae9 100644 --- a/Geometry/TwoDimensional/Rhombus.vb +++ b/Geometry/TwoDimensional/Rhombus.vb @@ -98,7 +98,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(side)) End If If interiorAngleRadians <= 0 OrElse interiorAngleRadians >= Math.PI Then - Throw New ArgumentException("Der Innenwinkel muss zwischen 0 und PI liegen.", NameOf(interiorAngleRadians)) + Throw New ArgumentException(My.Resources.IncludedAngleMustBeBetweenZeroAndPi, NameOf(interiorAngleRadians)) End If Dim halfAngle = interiorAngleRadians / 2.0 @@ -145,7 +145,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckPositiveLength, NameOf(side)) End If If interiorAngleRadians <= 0 OrElse interiorAngleRadians >= Math.PI Then - Throw New ArgumentException("Der Innenwinkel muss zwischen 0 und PI liegen.", NameOf(interiorAngleRadians)) + Throw New ArgumentException(My.Resources.IncludedAngleMustBeBetweenZeroAndPi, NameOf(interiorAngleRadians)) End If Dim halfA = side / 2.0 From 684f624f6d501edc134131c6610855ad8cd12c31 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:08:31 +0200 Subject: [PATCH 21/22] =?UTF-8?q?Parallelogramm-Validierung=20=C3=BCber=20?= =?UTF-8?q?Ressourcen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lokalisierte Fehlermeldungen für Parallelogramm- und Eckpunkt-Validierungen in Parallelogram.vb eingebunden; harte Texte entfernt und Winkelmeldung in My.Resources ergänzt. --- Geometry/My Project/Resources.Designer.vb | 38 ++++++++++++++++++++++- Geometry/My Project/Resources.resx | 14 ++++++++- Geometry/TwoDimensional/Parallelogram.vb | 8 ++--- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 02c45cd..271c5aa 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -268,7 +268,7 @@ Namespace My.Resources End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Der eingeschlossene Winkel muss zwischen Null und Pi liegen. ähnelt. ''' Friend ReadOnly Property IncludedAngleMustBeBetweenZeroAndPi() As String Get @@ -276,6 +276,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten und Diagonalen bilden kein gültiges Parallelogramm. ähnelt. + ''' + Friend ReadOnly Property InvalidParallelogramBySidesAndDiagonals() As String + Get + Return ResourceManager.GetString("InvalidParallelogramBySidesAndDiagonals", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die angegebenen Seiten bilden kein gültiges Dreieck. ähnelt. ''' @@ -303,6 +312,24 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Es müssen mindestens 3 Eckpunkte angegeben werden. ähnelt. + ''' + Friend ReadOnly Property RequireAtLeastThreeVertices() As String + Get + Return ResourceManager.GetString("RequireAtLeastThreeVertices", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Es müssen mindestens 2 Eckpunkte angegeben werden. ähnelt. + ''' + Friend ReadOnly Property RequireAtLeastTwoVertices() As String + Get + Return ResourceManager.GetString("RequireAtLeastTwoVertices", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Es müssen genau 4 Eckpunkte angegeben werden. ähnelt. ''' @@ -366,6 +393,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Umfang ist für die angegebene Seite zu klein. ähnelt. + ''' + Friend ReadOnly Property VerifyPerimeterGreaterThanTwiceKnownSide() As String + Get + Return ResourceManager.GetString("VerifyPerimeterGreaterThanTwiceKnownSide", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die obere Länge muss kleiner als die untere Länge sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index d0f987d..bfa4fe2 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -226,6 +226,18 @@ Es müssen genau 4 Eckpunkte angegeben werden. - + Der eingeschlossene Winkel muss zwischen Null und Pi liegen. + + + Es müssen mindestens 3 Eckpunkte angegeben werden. + + + Umfang ist für die angegebene Seite zu klein. + + + Die angegebenen Seiten und Diagonalen bilden kein gültiges Parallelogramm. + + + Es müssen mindestens 2 Eckpunkte angegeben werden. \ No newline at end of file diff --git a/Geometry/TwoDimensional/Parallelogram.vb b/Geometry/TwoDimensional/Parallelogram.vb index 36780a7..30b8254 100644 --- a/Geometry/TwoDimensional/Parallelogram.vb +++ b/Geometry/TwoDimensional/Parallelogram.vb @@ -93,7 +93,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeSide, NameOf(knownSide)) End If If perimeter <= 2.0 * knownSide Then - Throw New ArgumentException("Umfang ist für die angegebene Seite zu klein.", NameOf(perimeter)) + Throw New ArgumentException(My.Resources.VerifyPerimeterGreaterThanTwiceKnownSide, NameOf(perimeter)) End If Return (perimeter / 2.0) - knownSide @@ -152,7 +152,7 @@ Namespace TwoDimensional Dim cosValue = ((d1 * d1) - (d2 * d2)) / denominator If cosValue < -1.0 OrElse cosValue > 1.0 Then - Throw New ArgumentException("Die angegebenen Seiten und Diagonalen bilden kein gültiges Parallelogramm.") + Throw New ArgumentException(My.Resources.InvalidParallelogramBySidesAndDiagonals) End If Return Math.Acos(cosValue) @@ -225,7 +225,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < 3 Then - Throw New ArgumentException("Es müssen mindestens 3 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireAtLeastThreeVertices, NameOf(vertices)) End If Dim sum As Double = 0.0 @@ -248,7 +248,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < 2 Then - Throw New ArgumentException("Es müssen mindestens 2 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireAtLeastTwoVertices, NameOf(vertices)) End If Dim perimeter As Double = 0.0 From 738e2b86da52d64c7eb69589d5ebe5443043b3f5 Mon Sep 17 00:00:00 2001 From: Andreas Sauer <18749753+Hanibal1963@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:55:38 +0200 Subject: [PATCH 22/22] =?UTF-8?q?Ressourcen=20f=C3=BCr=20Fehlermeldungen?= =?UTF-8?q?=20zentralisiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Versionsnummer auf 1.2026.1009.1 angehoben, fehlende Ressourcen ergänzt und harte Fehlermeldungs-Strings in Geometry-Klassen durch My.Resources ersetzt; ResXManager-Konfiguration für de-DE ergänzt und sprachliche Korrekturen vorgenommen. --- Geometry/My Project/AssemblyInfo.vb | 4 +- Geometry/My Project/Resources.Designer.vb | 47 ++++++++++++++++++++++- Geometry/My Project/Resources.resx | 17 +++++++- Geometry/ThreeDimensional/Cone.vb | 2 +- Geometry/TwoDimensional/Polygon.vb | 4 +- Geometry/TwoDimensional/Rectangle.vb | 2 +- Geometry/TwoDimensional/RegularPolygon.vb | 2 +- Geometry/TwoDimensional/Trapezoid.vb | 2 +- Geometry/TwoDimensional/Triangle.vb | 2 +- ResXManager.config.xml | 4 ++ 10 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 ResXManager.config.xml diff --git a/Geometry/My Project/AssemblyInfo.vb b/Geometry/My Project/AssemblyInfo.vb index 22edb48..219b5c8 100644 --- a/Geometry/My Project/AssemblyInfo.vb +++ b/Geometry/My Project/AssemblyInfo.vb @@ -17,6 +17,6 @@ Imports System.Runtime.InteropServices - - + + diff --git a/Geometry/My Project/Resources.Designer.vb b/Geometry/My Project/Resources.Designer.vb index 271c5aa..abec2e8 100644 --- a/Geometry/My Project/Resources.Designer.vb +++ b/Geometry/My Project/Resources.Designer.vb @@ -196,7 +196,7 @@ Namespace My.Resources End Property ''' - ''' Sucht eine lokalisierte Zeichenfolge, die Die höhe muss grösser als Null sein. ähnelt. + ''' Sucht eine lokalisierte Zeichenfolge, die Die Höhe muss grösser als Null sein. ähnelt. ''' Friend ReadOnly Property CheckPositiveHeight() As String Get @@ -339,6 +339,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Es müssen genau 3 Eckpunkte angegeben werden. ähnelt. + ''' + Friend ReadOnly Property RequireExactlyThreeVertices() As String + Get + Return ResourceManager.GetString("RequireExactlyThreeVertices", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Die Sehnenhöhe ist ungültig. ähnelt. ''' @@ -375,6 +384,42 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die t muss im Bereich 0 bis 1 liegen. ähnelt. + ''' + Friend ReadOnly Property String4() As String + Get + Return ResourceManager.GetString("String4", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Summe der Grundseiten muss größer als Null sein. ähnelt. + ''' + Friend ReadOnly Property String5() As String + Get + Return ResourceManager.GetString("String5", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Die Eckpunkte dürfen kein degeneriertes Polygon bilden. ähnelt. + ''' + Friend ReadOnly Property String6() As String + Get + Return ResourceManager.GetString("String6", resourceCulture) + End Get + End Property + + ''' + ''' Sucht eine lokalisierte Zeichenfolge, die Es müssen mindestens {0} Eckpunkte angegeben werden. ähnelt. + ''' + Friend ReadOnly Property String7() As String + Get + Return ResourceManager.GetString("String7", resourceCulture) + End Get + End Property + ''' ''' Sucht eine lokalisierte Zeichenfolge, die Der Innenradius muss kleiner als der Außenradius sein. ähnelt. ''' diff --git a/Geometry/My Project/Resources.resx b/Geometry/My Project/Resources.resx index bfa4fe2..9c34ffe 100644 --- a/Geometry/My Project/Resources.resx +++ b/Geometry/My Project/Resources.resx @@ -211,7 +211,7 @@ Der Umfang muss grösser als Null sein. - Die höhe muss grösser als Null sein. + Die Höhe muss grösser als Null sein. Die Diagonale muss grösser als Null sein. @@ -240,4 +240,19 @@ Es müssen mindestens 2 Eckpunkte angegeben werden. + + Es müssen genau 3 Eckpunkte angegeben werden. + + + t muss im Bereich 0 bis 1 liegen. + + + Die Summe der Grundseiten muss größer als Null sein. + + + Die Eckpunkte dürfen kein degeneriertes Polygon bilden. + + + Es müssen mindestens {0} Eckpunkte angegeben werden. + \ No newline at end of file diff --git a/Geometry/ThreeDimensional/Cone.vb b/Geometry/ThreeDimensional/Cone.vb index 21079f3..0cb65d7 100644 --- a/Geometry/ThreeDimensional/Cone.vb +++ b/Geometry/ThreeDimensional/Cone.vb @@ -197,7 +197,7 @@ Namespace ThreeDimensional Throw New ArgumentException(My.Resources.CheckNonNegativeHeight, NameOf(height)) End If If t < 0 OrElse t > 1 Then - Throw New ArgumentException("t muss im Bereich 0 bis 1 liegen.", NameOf(t)) + Throw New ArgumentException(My.Resources.String4, NameOf(t)) End If Dim currentRadius = radius * (1.0 - t) diff --git a/Geometry/TwoDimensional/Polygon.vb b/Geometry/TwoDimensional/Polygon.vb index 8c5dc24..cc66575 100644 --- a/Geometry/TwoDimensional/Polygon.vb +++ b/Geometry/TwoDimensional/Polygon.vb @@ -141,7 +141,7 @@ Namespace TwoDimensional Next If Math.Abs(signedArea2) <= Double.Epsilon Then - Throw New ArgumentException("Die Eckpunkte dürfen kein degeneriertes Polygon bilden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.String6, NameOf(vertices)) End If Dim factor = 1.0 / (3.0 * signedArea2) @@ -229,7 +229,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < minCount Then - Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.String7.Replace("{0}", minCount.ToString()), NameOf(vertices)) End If End Sub diff --git a/Geometry/TwoDimensional/Rectangle.vb b/Geometry/TwoDimensional/Rectangle.vb index d271727..abb90fd 100644 --- a/Geometry/TwoDimensional/Rectangle.vb +++ b/Geometry/TwoDimensional/Rectangle.vb @@ -75,7 +75,7 @@ Namespace TwoDimensional Public Shared Function AspectRatio(w As Double, h As Double) As Double ' Prüft Eingaben und führt den Berechnungsschritt dieser Methode aus. If h = 0 Then - Throw New ArgumentException("Höhe darf nicht 0 sein.", NameOf(h)) + Throw New ArgumentException(My.Resources.CheckPositiveHeight, NameOf(h)) End If Return w / h End Function diff --git a/Geometry/TwoDimensional/RegularPolygon.vb b/Geometry/TwoDimensional/RegularPolygon.vb index e37b530..d0a893a 100644 --- a/Geometry/TwoDimensional/RegularPolygon.vb +++ b/Geometry/TwoDimensional/RegularPolygon.vb @@ -245,7 +245,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length < minCount Then - Throw New ArgumentException($"Es müssen mindestens {minCount} Eckpunkte vorhanden sein.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.String7.Replace("{0}", minCount.ToString()), NameOf(vertices)) End If End Sub diff --git a/Geometry/TwoDimensional/Trapezoid.vb b/Geometry/TwoDimensional/Trapezoid.vb index 303e360..c03527b 100644 --- a/Geometry/TwoDimensional/Trapezoid.vb +++ b/Geometry/TwoDimensional/Trapezoid.vb @@ -109,7 +109,7 @@ Namespace TwoDimensional Dim denominator = baseA + baseB If denominator <= 0 Then - Throw New ArgumentException("Die Summe der Grundseiten muss größer als 0 sein.") + Throw New ArgumentException(My.Resources.String5) End If #Disable Warning IDE0047 ' Unnötige Klammern entfernen diff --git a/Geometry/TwoDimensional/Triangle.vb b/Geometry/TwoDimensional/Triangle.vb index 777e7fc..6d6a4e1 100644 --- a/Geometry/TwoDimensional/Triangle.vb +++ b/Geometry/TwoDimensional/Triangle.vb @@ -210,7 +210,7 @@ Namespace TwoDimensional Throw New ArgumentException(My.Resources.CheckVerticesNotNull, NameOf(vertices)) End If If vertices.Length <> 3 Then - Throw New ArgumentException("Es müssen genau 3 Eckpunkte angegeben werden.", NameOf(vertices)) + Throw New ArgumentException(My.Resources.RequireExactlyThreeVertices, NameOf(vertices)) End If End Sub diff --git a/ResXManager.config.xml b/ResXManager.config.xml new file mode 100644 index 0000000..a186864 --- /dev/null +++ b/ResXManager.config.xml @@ -0,0 +1,4 @@ + + + de-DE +True \ No newline at end of file