Skip to content

Commit

Permalink
Added interfaces to the Path classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jan 28, 2024
1 parent fd51ca4 commit 47fd561
Show file tree
Hide file tree
Showing 32 changed files with 383 additions and 135 deletions.
20 changes: 10 additions & 10 deletions src/Magick.NET.Core/Drawables/Paths/Args/PathArc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public PathArc(double x, double y, double radiusX, double radiusY, double rotati
UseSweep = useSweep;
}

/// <summary>
/// Gets or sets the X offset from origin.
/// </summary>
public double X { get; set; }

/// <summary>
/// Gets or sets the Y offset from origin.
/// </summary>
public double Y { get; set; }

/// <summary>
/// Gets or sets the X radius.
/// </summary>
Expand All @@ -67,14 +77,4 @@ public PathArc(double x, double y, double radiusX, double radiusY, double rotati
/// Gets or sets a value indicating whether the arc should be drawn matching a clock-wise rotation.
/// </summary>
public bool UseSweep { get; set; }

/// <summary>
/// Gets or sets the X offset from origin.
/// </summary>
public double X { get; set; }

/// <summary>
/// Gets or sets the Y offset from origin.
/// </summary>
public double Y { get; set; }
}
3 changes: 0 additions & 3 deletions src/Magick.NET.Core/Drawables/Paths/IPath.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System.Diagnostics.CodeAnalysis;

namespace ImageMagick;

/// <summary>
/// Marker interface for paths.
/// </summary>
[SuppressMessage("Design", "CA1040:Avoid empty interfaces", Justification = "This is a marker interface.")]
public interface IPath
{
}
24 changes: 24 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathArc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System.Collections.Generic;

namespace ImageMagick;

/// <summary>
/// Draws an elliptical arc from the current point to (X, Y) using absolute coordinates. The size
/// and orientation of the ellipse are defined by two radii(RadiusX, RadiusY) and an RotationX,
/// which indicates how the ellipse as a whole is rotated relative to the current coordinate
/// system. The center of the ellipse is calculated automagically to satisfy the constraints
/// imposed by the other parameters. UseLargeArc and UseSweep contribute to the automatic
/// calculations and help determine how the arc is drawn. If UseLargeArc is true then draw the
/// larger of the available arcs. If UseSweep is true, then draw the arc matching a clock-wise
/// rotation.
/// </summary>
public interface IPathArc : IPath
{
/// <summary>
/// Gets the coordinates.
/// </summary>
IReadOnlyList<PathArc> Coordinates { get; }
}
13 changes: 13 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathClose.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Adds a path element to the current path which closes the current subpath by drawing a straight
/// line from the current point to the current subpath's most recent starting point (usually, the
/// most recent moveto point).
/// </summary>
public interface IPathClose : IPath
{
}
28 changes: 28 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathCurveTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Draws a cubic Bezier curve from the current point to (x, y) using (x1, y1) as the control point
/// at the beginning of the curve and (x2, y2) as the control point at the end of the curve using
/// absolute coordinates. At the end of the command, the new current point becomes the final (x, y)
/// coordinate pair used in the polybezier.
/// </summary>
public interface IPathCurveTo : IPath
{
/// <summary>
/// Gets the coordinate of control point for curve beginning.
/// </summary>
PointD ControlPointStart { get; }

/// <summary>
/// Gets the coordinate of control point for curve ending.
/// </summary>
PointD ControlPointEnd { get; }

/// <summary>
/// Gets the coordinate of the end of the curve.
/// </summary>
PointD End { get; }
}
18 changes: 18 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathLineTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System.Collections.Generic;

namespace ImageMagick;

/// <summary>
/// Draws a line path from the current point to the given coordinate using absolute coordinates.
/// The coordinate then becomes the new current point.
/// </summary>
public interface IPathLineTo : IPath
{
/// <summary>
/// Gets the coordinates.
/// </summary>
IReadOnlyList<PointD> Coordinates { get; }
}
16 changes: 16 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathLineToHorizontal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Draws a horizontal line path from the current point to the target point using absolute
/// coordinates. The target point then becomes the new current point.
/// </summary>
public interface IPathLineToHorizontal : IPath
{
/// <summary>
/// Gets the X coordinate.
/// </summary>
double X { get; }
}
16 changes: 16 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathLineToVertical.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Draws a vertical line path from the current point to the target point using absolute
/// coordinates. The target point then becomes the new current point.
/// </summary>
public interface IPathLineToVertical : IPath
{
/// <summary>
/// Gets the Y coordinate.
/// </summary>
double Y { get; }
}
16 changes: 16 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathMoveTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Starts a new sub-path at the given coordinate using absolute coordinates. The current point
/// then becomes the specified coordinate.
/// </summary>
public interface IPathMoveTo : IPath
{
/// <summary>
/// Gets the coordinate.
/// </summary>
PointD Coordinate { get; }
}
22 changes: 22 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathQuadraticCurveTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Draws a quadratic Bezier curve from the current point to (x, y) using (x1, y1) as the control
/// point using absolute coordinates. At the end of the command, the new current point becomes
/// the final (x, y) coordinate pair used in the polybezier.
/// </summary>
public interface IPathQuadraticCurveTo : IPath
{
/// <summary>
/// Gets the coordinate of control point.
/// </summary>
PointD ControlPoint { get; }

/// <summary>
/// Gets the coordinate of final point.
/// </summary>
PointD End { get; }
}
27 changes: 27 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathSmoothCurveTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Draws a cubic Bezier curve from the current point to (x,y) using absolute coordinates. The
/// first control point is assumed to be the reflection of the second control point on the
/// previous command relative to the current point. (If there is no previous command or if the
/// previous command was not an PathCurveToAbs, PathCurveToRel, PathSmoothCurveToAbs or
/// PathSmoothCurveToRel, assume the first control point is coincident with the current point.)
/// (x2,y2) is the second control point (i.e., the control point at the end of the curve). At
/// the end of the command, the new current point becomes the final (x,y) coordinate pair used
/// in the polybezier.
/// </summary>
public interface IPathSmoothCurveTo : IPath
{
/// <summary>
/// Gets the coordinate of second point.
/// </summary>
PointD ControlPoint { get; }

/// <summary>
/// Gets the coordinate of final point.
/// </summary>
PointD End { get; }
}
21 changes: 21 additions & 0 deletions src/Magick.NET.Core/Drawables/Paths/IPathSmoothQuadraticCurveTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

namespace ImageMagick;

/// <summary>
/// Draws a quadratic Bezier curve (using absolute coordinates) from the current point to (X, Y).
/// The control point is assumed to be the reflection of the control point on the previous
/// command relative to the current point. (If there is no previous command or if the previous
/// command was not a PathQuadraticCurveToAbs, PathQuadraticCurveToRel,
/// PathSmoothQuadraticCurveToAbs or PathSmoothQuadraticCurveToRel, assume the control point is
/// coincident with the current point.). At the end of the command, the new current point becomes
/// the final (X,Y) coordinate pair used in the polybezier.
/// </summary>
public interface IPathSmoothQuadraticCurveTo : IPath
{
/// <summary>
/// Gets the coordinate of final point.
/// </summary>
PointD End { get; }
}
8 changes: 4 additions & 4 deletions src/Magick.NET/Drawables/DrawingWand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ public void PathLineToRel(IEnumerable<PointD> coordinates)
}
}

public void PathMoveToAbs(double x, double y)
=> _nativeInstance.PathMoveToAbs(x, y);
public void PathMoveToAbs(PointD coordinate)
=> _nativeInstance.PathMoveToAbs(coordinate.X, coordinate.Y);

public void PathMoveToRel(double x, double y)
=> _nativeInstance.PathMoveToRel(x, y);
public void PathMoveToRel(PointD coordinate)
=> _nativeInstance.PathMoveToRel(coordinate.X, coordinate.Y);

public void PathQuadraticCurveToAbs(PointD controlPoint, PointD endPoint)
=> _nativeInstance.PathQuadraticCurveToAbs(controlPoint.X, controlPoint.Y, endPoint.X, endPoint.Y);
Expand Down
19 changes: 9 additions & 10 deletions src/Magick.NET/Drawables/Paths/PathArcAbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,31 @@ namespace ImageMagick;
/// larger of the available arcs. If UseSweep is true, then draw the arc matching a clock-wise
/// rotation.
/// </summary>
public sealed class PathArcAbs : IPath, IDrawingWand
public sealed class PathArcAbs : IPathArc, IDrawingWand
{
private readonly PathArcCoordinates _coordinates;

/// <summary>
/// Initializes a new instance of the <see cref="PathArcAbs"/> class.
/// </summary>
/// <param name="coordinates">The coordinates to use.</param>
public PathArcAbs(params PathArc[] coordinates)
{
_coordinates = new PathArcCoordinates(coordinates);
}
=> Coordinates = new PathArcCoordinates(coordinates);

/// <summary>
/// Initializes a new instance of the <see cref="PathArcAbs"/> class.
/// </summary>
/// <param name="coordinates">The coordinates to use.</param>
public PathArcAbs(IEnumerable<PathArc> coordinates)
{
_coordinates = new PathArcCoordinates(coordinates);
}
=> Coordinates = new PathArcCoordinates(coordinates);

/// <summary>
/// Gets the coordinates.
/// </summary>
public IReadOnlyList<PathArc> Coordinates { get; }

/// <summary>
/// Draws this instance with the drawing wand.
/// </summary>
/// <param name="wand">The want to draw on.</param>
void IDrawingWand.Draw(DrawingWand wand)
=> wand?.PathArcAbs(_coordinates.ToList());
=> wand?.PathArcAbs(Coordinates);
}
19 changes: 9 additions & 10 deletions src/Magick.NET/Drawables/Paths/PathArcRel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,31 @@ namespace ImageMagick;
/// larger of the available arcs. If UseSweep is true, then draw the arc matching a clock-wise
/// rotation.
/// </summary>
public sealed class PathArcRel : IPath, IDrawingWand
public sealed class PathArcRel : IPathArc, IDrawingWand
{
private readonly PathArcCoordinates _coordinates;

/// <summary>
/// Initializes a new instance of the <see cref="PathArcRel"/> class.
/// </summary>
/// <param name="coordinates">The coordinates to use.</param>
public PathArcRel(params PathArc[] coordinates)
{
_coordinates = new PathArcCoordinates(coordinates);
}
=> Coordinates = new PathArcCoordinates(coordinates);

/// <summary>
/// Initializes a new instance of the <see cref="PathArcRel"/> class.
/// </summary>
/// <param name="coordinates">The coordinates to use.</param>
public PathArcRel(IEnumerable<PathArc> coordinates)
{
_coordinates = new PathArcCoordinates(coordinates);
}
=> Coordinates = new PathArcCoordinates(coordinates);

/// <summary>
/// Gets the coordinates.
/// </summary>
public IReadOnlyList<PathArc> Coordinates { get; }

/// <summary>
/// Draws this instance with the drawing wand.
/// </summary>
/// <param name="wand">The want to draw on.</param>
void IDrawingWand.Draw(DrawingWand wand)
=> wand?.PathArcRel(_coordinates.ToList());
=> wand?.PathArcRel(Coordinates);
}
2 changes: 1 addition & 1 deletion src/Magick.NET/Drawables/Paths/PathClose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ImageMagick;
/// line from the current point to the current subpath's most recent starting point (usually, the
/// most recent moveto point).
/// </summary>
public sealed class PathClose : IPath, IDrawingWand
public sealed class PathClose : IPathClose, IDrawingWand
{
/// <summary>
/// Initializes a new instance of the <see cref="PathClose"/> class.
Expand Down
Loading

0 comments on commit 47fd561

Please sign in to comment.