Unnamed
public text v1 · immutablepublic void CalculatePosition()
{
int intLeftMostPoint = 10000;
int intTopMostPoint = 10000;
foreach (Shape sh in shapes)
{
if (sh is Rect || sh is Ellipse || sh is Text)
{
intLeftMostPoint = sh.X;
intTopMostPoint = sh.Y;
}
else if (sh is Polygon)
{
intLeftMostPoint = ((Polygon)sh).PointList[0].X;
intTopMostPoint = ((Polygon)sh).PointList[0].Y;
foreach (Point p in ((Polygon)sh).PointList)
{
if (p.X < intLeftMostPoint)
{
intLeftMostPoint = p.X;
}
if (p.Y < intTopMostPoint)
{
intTopMostPoint = p.Y;
}
}
}
else if (sh is Line)
{
intLeftMostPoint = ((Line)sh).PointList[0].X;
intTopMostPoint = ((Line)sh).PointList[0].Y;
foreach (Point p in ((Line)sh).PointList)
{
if (p.X < intLeftMostPoint)
{
intLeftMostPoint = p.X;
}
if (p.Y < intTopMostPoint)
{
intTopMostPoint = p.Y;
}
}
}
if (intLeftMostPoint < this.X)
{
this.position = new Point(intLeftMostPoint, this.Y);
}
if (intTopMostPoint < this.Y)
{
this.position = new Point(this.X, intTopMostPoint);
}
}
}