CPF/CPF/PointField.cs
2023-11-21 23:05:03 +08:00

68 lines
1.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CPF.Drawing;
using System;
using System.Collections.Generic;
using System.Text;
namespace CPF
{
/// <summary>
/// 支持单位百分比的Point格式10,10 10%,10%
/// </summary>
public struct PointField
{
public PointField(FloatField x, FloatField y)
{
X = x;
Y = y;
}
public FloatField X { get; set; }
public FloatField Y { get; set; }
public override bool Equals(object obj)
{
if (obj is PointField)
{
var o = (PointField)obj;
return o.X.Equals(X) && o.Y.Equals(Y);
}
return false;
}
public static implicit operator PointField(string n)
{
if (n.IndexOf(',') < 0)
{
throw new Exception("PointValue 字符串格式错误 :" + n);
}
else
{
var tem = n.Split(',');
try
{
return new PointField { X = tem[0], Y = tem[1] };
}
catch (Exception)
{
throw new Exception("PointValue 字符串格式错误 :" + n);
}
}
}
public static implicit operator PointField(Point point)
{
return new PointField(point.X, point.Y);
}
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
public override string ToString()
{
return X.ToString() + "," + Y.ToString();
}
}
}