Skip to content

Instantly share code, notes, and snippets.

@GER-NaN
Created January 10, 2017 14:40
Show Gist options
  • Save GER-NaN/ec818fca8732b025b5e3c0e771398171 to your computer and use it in GitHub Desktop.
Save GER-NaN/ec818fca8732b025b5e3c0e771398171 to your computer and use it in GitHub Desktop.
Extensions to the System.Drawing.Point class
using System;
using System.Drawing;
//Extensions to the System.Drawing.Point class
public static class PointExtensions
{
/// <summary>Formatted as (x,y) where x and y are the unformatted value.</summary>
public static string PrintStr(this Point p)
{
return $"({p.X},{p.Y})";
}
/// <summary>The (Euclidean) distance between the 2 points</summary>
public static double Distance(this Point p, Point q)
{
double dx = p.X - q.X;
double dy = p.Y - q.Y;
var dist = Math.Sqrt(dx * dx + dy * dy);
return dist;
}
/// <summary>The midpoint between the two Points.</summary>
public static Point MidPoint(this Point p, Point q)
{
int midX = (p.X + q.X) / 2;
int midY = (p.Y + q.Y) / 2;
return new Point(midX, midY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment