mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 00:38:47 +00:00
Fix CA2225 violations
This commit is contained in:
parent
c27334bdc8
commit
398b0c58b1
@ -162,6 +162,27 @@ public readonly struct Circle : IEquatable<Circle>, IComparable<Circle>, ICompar
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Circle" /> to a <see cref="CircleF" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted circle.</returns>
|
||||
public static explicit operator Circle(CircleF circle)
|
||||
{
|
||||
return Circle.FromCircleF(circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Circle" /> to a <see cref="CircleF" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted circle.</returns>
|
||||
public static Circle FromCircleF(CircleF circle)
|
||||
{
|
||||
PointF center = circle.Center;
|
||||
return new Circle(new Point((int)center.X, (int)center.Y), (int)circle.Radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance to another <see cref="Circle" />.
|
||||
/// </summary>
|
||||
|
@ -174,17 +174,6 @@ public readonly struct CircleF : IEquatable<CircleF>, IComparable<CircleF>, ICom
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Circle" /> to a <see cref="CircleF" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted circle.</returns>
|
||||
public static explicit operator Circle(CircleF circle)
|
||||
{
|
||||
PointF center = circle.Center;
|
||||
return new Circle(new Point((int)center.X, (int)center.Y), (int)circle.Radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts a <see cref="Circle" /> to a <see cref="CircleF" />.
|
||||
/// </summary>
|
||||
@ -192,7 +181,17 @@ public readonly struct CircleF : IEquatable<CircleF>, IComparable<CircleF>, ICom
|
||||
/// <returns>The converted circle.</returns>
|
||||
public static implicit operator CircleF(Circle circle)
|
||||
{
|
||||
return new CircleF(circle.Center, circle.Radius);
|
||||
return FromCircle(circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Circle" /> to a <see cref="CircleF" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted circle.</returns>
|
||||
public static CircleF FromCircle(Circle circle)
|
||||
{
|
||||
return new Circle(circle.Center, circle.Radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -132,10 +132,41 @@ public readonly struct Ellipse : IEquatable<Ellipse>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static implicit operator Ellipse(in Circle circle)
|
||||
{
|
||||
return FromCircle(circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts an <see cref="EllipseF" /> to an <see cref="Ellipse" />.
|
||||
/// </summary>
|
||||
/// <param name="ellipse">The ellipse to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static explicit operator Ellipse(in EllipseF ellipse)
|
||||
{
|
||||
return FromEllipseF(ellipse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Circle" /> to an <see cref="Ellipse" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static Ellipse FromCircle(in Circle circle)
|
||||
{
|
||||
return new Ellipse(circle.Center, new Size(circle.Radius, circle.Radius));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an <see cref="EllipseF" /> to an <see cref="Ellipse" />.
|
||||
/// </summary>
|
||||
/// <param name="ellipse">The ellipse to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static Ellipse FromEllipseF(in EllipseF ellipse)
|
||||
{
|
||||
PointF center = ellipse.Center;
|
||||
return new Ellipse((int)center.X, (int)center.Y, (int)ellipse.HorizontalRadius, (int)ellipse.VerticalRadius);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
|
@ -161,7 +161,7 @@ public readonly struct EllipseF : IEquatable<EllipseF>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static implicit operator EllipseF(in Circle circle)
|
||||
{
|
||||
return new EllipseF(circle.Center, new SizeF(circle.Radius, circle.Radius));
|
||||
return FromCircle(circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -171,7 +171,7 @@ public readonly struct EllipseF : IEquatable<EllipseF>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static implicit operator EllipseF(in CircleF circle)
|
||||
{
|
||||
return new EllipseF(circle.Center, new SizeF(circle.Radius, circle.Radius));
|
||||
return FromCircleF(circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -181,18 +181,37 @@ public readonly struct EllipseF : IEquatable<EllipseF>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static implicit operator EllipseF(in Ellipse ellipse)
|
||||
{
|
||||
return new EllipseF(ellipse.Center, ellipse.Radius);
|
||||
return FromEllipse(ellipse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts an <see cref="EllipseF" /> to an <see cref="Ellipse" />.
|
||||
/// Converts a <see cref="Circle" /> to an <see cref="EllipseF" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static EllipseF FromCircle(in Circle circle)
|
||||
{
|
||||
return new EllipseF(circle.Center, new SizeF(circle.Radius, circle.Radius));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="CircleF" /> to an <see cref="EllipseF" />.
|
||||
/// </summary>
|
||||
/// <param name="circle">The circle to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static EllipseF FromCircleF(in CircleF circle)
|
||||
{
|
||||
return new EllipseF(circle.Center, new SizeF(circle.Radius, circle.Radius));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an <see cref="Ellipse" /> to an <see cref="EllipseF" />.
|
||||
/// </summary>
|
||||
/// <param name="ellipse">The ellipse to convert.</param>
|
||||
/// <returns>The converted ellipse.</returns>
|
||||
public static explicit operator Ellipse(in EllipseF ellipse)
|
||||
public static EllipseF FromEllipse(in Ellipse ellipse)
|
||||
{
|
||||
PointF center = ellipse.Center;
|
||||
return new Ellipse((int)center.X, (int)center.Y, (int)ellipse.HorizontalRadius, (int)ellipse.VerticalRadius);
|
||||
return new EllipseF(ellipse.Center, ellipse.Radius);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
namespace X10D.Drawing;
|
||||
|
||||
@ -152,6 +153,50 @@ public readonly struct Line : IEquatable<Line>, IComparable<Line>, IComparable
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static explicit operator Line(in LineF line)
|
||||
{
|
||||
return FromLineF(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Line3D" /> to a <see cref="Line" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static explicit operator Line(in Line3D line)
|
||||
{
|
||||
return FromLine3D(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Line3D" /> to a <see cref="Line" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static Line FromLine3D(in Line3D line)
|
||||
{
|
||||
Vector3 start = line.Start;
|
||||
Vector3 end = line.End;
|
||||
return new Line(new Point((int)start.X, (int)start.Y), new Point((int)end.X, (int)end.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static Line FromLineF(in LineF line)
|
||||
{
|
||||
PointF start = line.Start;
|
||||
PointF end = line.End;
|
||||
return new Line(new Point((int)start.X, (int)start.Y), new Point((int)end.X, (int)end.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance to another object.
|
||||
/// </summary>
|
||||
|
@ -158,30 +158,6 @@ public readonly struct Line3D : IEquatable<Line3D>, IComparable<Line3D>, ICompar
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Line3D" /> to a <see cref="Line" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static explicit operator Line(in Line3D line)
|
||||
{
|
||||
Vector3 start = line.Start;
|
||||
Vector3 end = line.End;
|
||||
return new Line(new Point((int)start.X, (int)start.Y), new Point((int)end.X, (int)end.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Line3D" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static explicit operator LineF(in Line3D line)
|
||||
{
|
||||
Vector3 start = line.Start;
|
||||
Vector3 end = line.End;
|
||||
return new LineF(new PointF(start.X, start.Y), new PointF(end.X, end.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
@ -189,9 +165,7 @@ public readonly struct Line3D : IEquatable<Line3D>, IComparable<Line3D>, ICompar
|
||||
/// <returns>The converted line.</returns>
|
||||
public static implicit operator Line3D(in Line line)
|
||||
{
|
||||
Point start = line.Start;
|
||||
Point end = line.End;
|
||||
return new Line3D(new Vector3(start.X, start.Y, 0), new Vector3(end.X, end.Y, 0));
|
||||
return FromLine(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -200,6 +174,28 @@ public readonly struct Line3D : IEquatable<Line3D>, IComparable<Line3D>, ICompar
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static implicit operator Line3D(in LineF line)
|
||||
{
|
||||
return FromLineF(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static Line3D FromLine(in Line line)
|
||||
{
|
||||
Point start = line.Start;
|
||||
Point end = line.End;
|
||||
return new Line3D(new Vector3(start.X, start.Y, 0), new Vector3(end.X, end.Y, 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="LineF" /> to a <see cref="Line3D" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static Line3D FromLineF(in LineF line)
|
||||
{
|
||||
PointF start = line.Start;
|
||||
PointF end = line.End;
|
||||
|
@ -164,28 +164,48 @@ public readonly struct LineF : IEquatable<LineF>, IComparable<LineF>, IComparabl
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static explicit operator Line(in LineF line)
|
||||
{
|
||||
PointF start = line.Start;
|
||||
PointF end = line.End;
|
||||
return new Line(new Point((int)start.X, (int)start.Y), new Point((int)end.X, (int)end.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static implicit operator LineF(in Line line)
|
||||
{
|
||||
return FromLine(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Line3D" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static explicit operator LineF(in Line3D line)
|
||||
{
|
||||
return FromLine3D(line);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Line" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static LineF FromLine(in Line line)
|
||||
{
|
||||
return new LineF(line.Start, line.End);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Line3D" /> to a <see cref="LineF" />.
|
||||
/// </summary>
|
||||
/// <param name="line">The line to convert.</param>
|
||||
/// <returns>The converted line.</returns>
|
||||
public static LineF FromLine3D(in Line3D line)
|
||||
{
|
||||
Vector3 start = line.Start;
|
||||
Vector3 end = line.End;
|
||||
return new LineF(new PointF(start.X, start.Y), new PointF(end.X, end.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance to another object.
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
|
||||
namespace X10D.Drawing;
|
||||
|
||||
@ -133,6 +133,43 @@ public class Polygon : IEquatable<Polygon>
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Polygon" /> to a <see cref="PolygonF" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polygon to convert.</param>
|
||||
/// <returns>The converted polygon.</returns>
|
||||
public static explicit operator Polygon?(PolygonF? polygon)
|
||||
{
|
||||
return polygon is null ? null : FromPolygonF(polygon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Polygon" /> to a <see cref="PolygonF" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polygon to convert.</param>
|
||||
/// <returns>The converted polygon.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="polygon" /> is <see langword="null" />.</exception>
|
||||
public static Polygon FromPolygonF(PolygonF polygon)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(polygon);
|
||||
#else
|
||||
if (polygon is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(polygon));
|
||||
}
|
||||
#endif
|
||||
|
||||
var vertices = new List<Point>();
|
||||
|
||||
foreach (PointF vertex in polygon.Vertices)
|
||||
{
|
||||
vertices.Add(new Point((int)vertex.X, (int)vertex.Y));
|
||||
}
|
||||
|
||||
return new Polygon(vertices);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a vertex to this polygon.
|
||||
/// </summary>
|
||||
|
@ -163,20 +163,13 @@ public class PolygonF
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly converts a <see cref="Polygon" /> to a <see cref="PolygonF" />.
|
||||
/// Implicitly converts a <see cref="Polygon" /> to a <see cref="PolygonF" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polygon to convert.</param>
|
||||
/// <returns>The converted polygon.</returns>
|
||||
public static explicit operator Polygon(PolygonF polygon)
|
||||
public static implicit operator PolygonF?(Polygon? polygon)
|
||||
{
|
||||
var vertices = new List<Point>();
|
||||
|
||||
foreach (PointF vertex in polygon.Vertices)
|
||||
{
|
||||
vertices.Add(new Point((int)vertex.X, (int)vertex.Y));
|
||||
}
|
||||
|
||||
return new Polygon(vertices);
|
||||
return polygon is null ? null : FromPolygon(polygon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -184,8 +177,18 @@ public class PolygonF
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polygon to convert.</param>
|
||||
/// <returns>The converted polygon.</returns>
|
||||
public static implicit operator PolygonF(Polygon polygon)
|
||||
/// <exception cref="ArgumentNullException"><paramref name="polygon" /> is <see langword="null" />.</exception>
|
||||
public static PolygonF FromPolygon(Polygon polygon)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(polygon);
|
||||
#else
|
||||
if (polygon is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(polygon));
|
||||
}
|
||||
#endif
|
||||
|
||||
var vertices = new List<PointF>();
|
||||
|
||||
foreach (Point vertex in polygon.Vertices)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
namespace X10D.Drawing;
|
||||
@ -135,10 +135,44 @@ public class Polyhedron : IEquatable<Polyhedron>
|
||||
/// Implicitly converts a <see cref="Polygon" /> to a <see cref="Polyhedron" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polyhedron to convert.</param>
|
||||
/// <returns>The converted polyhedron.</returns>
|
||||
public static implicit operator Polyhedron(Polygon polygon)
|
||||
/// <returns>
|
||||
/// The converted polyhedron, or <see langword="null" /> if <paramref name="polygon" /> is <see langword="null" />.
|
||||
/// </returns>
|
||||
public static implicit operator Polyhedron?(Polygon? polygon)
|
||||
{
|
||||
List<Vector3> vertices = new List<Vector3>();
|
||||
return polygon is null ? null : FromPolygon(polygon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts a <see cref="PolygonF" /> to a <see cref="Polyhedron" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polyhedron to convert.</param>
|
||||
/// <returns>
|
||||
/// The converted polyhedron, or <see langword="null" /> if <paramref name="polygon" /> is <see langword="null" />.
|
||||
/// </returns>
|
||||
public static implicit operator Polyhedron?(PolygonF? polygon)
|
||||
{
|
||||
return polygon is null ? null : FromPolygonF(polygon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Polygon" /> to a <see cref="Polyhedron" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polyhedron to convert.</param>
|
||||
/// <returns>The converted polyhedron.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="polygon" /> is <see langword="null" />.</exception>
|
||||
public static Polyhedron FromPolygon(Polygon polygon)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(polygon);
|
||||
#else
|
||||
if (polygon is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(polygon));
|
||||
}
|
||||
#endif
|
||||
|
||||
var vertices = new List<Vector3>();
|
||||
|
||||
foreach (Point vertex in polygon.Vertices)
|
||||
{
|
||||
@ -149,13 +183,23 @@ public class Polyhedron : IEquatable<Polyhedron>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implicitly converts a <see cref="PolygonF" /> to a <see cref="Polyhedron" />.
|
||||
/// Converts a <see cref="PolygonF" /> to a <see cref="Polyhedron" />.
|
||||
/// </summary>
|
||||
/// <param name="polygon">The polyhedron to convert.</param>
|
||||
/// <returns>The converted polyhedron.</returns>
|
||||
public static implicit operator Polyhedron(PolygonF polygon)
|
||||
/// <exception cref="ArgumentNullException"><paramref name="polygon" /> is <see langword="null" />.</exception>
|
||||
public static Polyhedron FromPolygonF(PolygonF polygon)
|
||||
{
|
||||
List<Vector3> vertices = new List<Vector3>();
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(polygon);
|
||||
#else
|
||||
if (polygon is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(polygon));
|
||||
}
|
||||
#endif
|
||||
|
||||
var vertices = new List<Vector3>();
|
||||
|
||||
foreach (PointF vertex in polygon.Vertices)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user