Files
Shrlalgo.RvKits/ShrlAlgoToolkit.RevitAddins/RvIndependent/MetroGauges/LandXMLData/CrossSectionPoint.cs
2025-04-24 20:56:44 +08:00

170 lines
4.7 KiB
C#

using System.Xml.Serialization;
namespace ShrlAlgoToolkit.RevitAddins.RvIndependent.MetroGauges.LandXMLData
{
[XmlType("CrossSectPnt")]
[Serializable]
public class CrossSectionPoint : TextPoint2D
{
public CrossSectionPoint()
{
Code = null;
Edge = Index = 0;
}
public CrossSectionPoint(CrossSectionPoint source)
: base(source)
{
Code = source.Code;
Edge = source.Edge;
Index = source.Index;
}
[XmlIgnore]
public string CodeIndex => Code + " " + Index;
[XmlAttribute("edge")]
public int Edge { get; set; }
[XmlAttribute("i")]
public int Index { get; set; }
[XmlAttribute("code")]
public string Code { get; set; }
public override bool Equals(object obj)
{
return Equals(obj as CrossSectionPoint);
}
public bool Equals(CrossSectionPoint csp)
{
return !ReferenceEquals(csp, null) && ValuesEqual(this, csp);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public static CrossSectionPoint operator +(CrossSectionPoint p1, CrossSectionPoint p2)
{
if (p1 != null)
{
if (p2 != null)
{
return new CrossSectionPoint
{
X = p1.X + p2.X,
Y = p1.Y + p2.Y,
Z = p1.Z + p2.Z,
_first = p1._first + p2._first,
Second = p1._second + p2._second
};
}
return p1;
}
if (p2 != null)
{
return p2;
}
return null;
}
public static bool operator ==(CrossSectionPoint p1, CrossSectionPoint p2)
{
return ReferenceEquals(p1, p2) || (!ReferenceEquals(p1, null) && !ReferenceEquals(p2, null) && ValuesEqual(p1, p2));
}
public static bool operator !=(CrossSectionPoint p1, CrossSectionPoint p2)
{
return !ReferenceEquals(p1, p2) && (ReferenceEquals(p1, null) || ReferenceEquals(p2, null) || !ValuesEqual(p1, p2));
}
public static CrossSectionPoint operator *(double f1, CrossSectionPoint p2)
{
if (p2 != null)
{
return new CrossSectionPoint
{
X = f1 * p2.X,
Y = f1 * p2.Y,
Z = f1 * p2.Z,
_first = f1 * p2._first,
Second = f1 * p2._second
};
}
return null;
}
public static CrossSectionPoint operator -(CrossSectionPoint p1, CrossSectionPoint p2)
{
if (p1 != null)
{
if (p2 != null)
{
return new CrossSectionPoint
{
X = p1.X - p2.X,
Y = p1.Y - p2.Y,
Z = p1.Z - p2.Z,
_first = p1._first - p2._first,
Second = p1._second - p2._second
};
}
return p1;
}
if (p2 != null)
{
return new CrossSectionPoint
{
X = -p2.X,
Y = -p2.Y,
Z = -p2.Z,
_first = -p1._first,
Second = -p2._second
};
}
return null;
}
public string SeekCode(CrossSection crossSection)
{
string[] array = crossSection.DesignShapes
.SelectMany(ds => from p in ds.CrossSectionPoints where p != this && p.Text == Text && p.X == X && p.Y == Y && p.Z == Z select p.Code)
.ToArray();
if (array.Length <= 0)
{
return null;
}
return array[0];
}
public static bool ValuesEqual(CrossSectionPoint p1, CrossSectionPoint p2)
{
return p1.Code == p2.Code && TextPoint2D.ValuesEqual(p1, p2);
}
public class SectionPointComparer : IEqualityComparer<CrossSectionPoint>
{
public bool Equals(CrossSectionPoint x, CrossSectionPoint y)
{
return x.First == y.First && x.Second == y.Second;
}
public int GetHashCode(CrossSectionPoint obj)
{
return obj.GetHashCode();
}
}
}
}