Dolgov D.A. Lab Work 8 #8

Closed
devil_1nc wants to merge 4 commits from LabWork08 into LabWork07
5 changed files with 149 additions and 0 deletions
Showing only changes of commit 2f2d878c4f - Show all commits

View File

@ -17,6 +17,7 @@ namespace ProjectPlane
public float Step => _plane?.Plane?.Step ?? 0;
public DrawingPlane GetPlane => _plane;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _plane?.GetCurrentPosition() ?? default;

View File

@ -132,6 +132,11 @@ namespace ProjectPlane
_setPlanes.Insert(DrawingObject.Create(rec) as T);
}
}
public void Sort(IComparer<T> comparer)
{
_setPlanes.SortSet(comparer);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
internal class PlaneCompareByColor : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject? x, IDrawingObject? y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xPlane = x as DrawingObject;
var yPlane = y as DrawingObject;
if (xPlane == null && yPlane == null)
{
return 0;
}
if (xPlane == null && yPlane != null)
{
return 1;
}
if (xPlane != null && yPlane == null)
{
return -1;
}
if (xPlane.GetPlane.Plane.BodyColor.R.CompareTo(yPlane.GetPlane.Plane.BodyColor.R) != 0)
{
return xPlane.GetPlane.Plane.BodyColor.R.CompareTo(yPlane.GetPlane.Plane.BodyColor.R);
}
if (xPlane.GetPlane.Plane.BodyColor.G.CompareTo(yPlane.GetPlane.Plane.BodyColor.G) != 0)
{
return xPlane.GetPlane.Plane.BodyColor.G.CompareTo(yPlane.GetPlane.Plane.BodyColor.G);
}
if (xPlane.GetPlane.Plane.BodyColor.B.CompareTo(yPlane.GetPlane.Plane.BodyColor.B) != 0)
{
return xPlane.GetPlane.Plane.BodyColor.B.CompareTo(yPlane.GetPlane.Plane.BodyColor.B);
}
if (xPlane.GetPlane.Plane is EntityWarPlane xWarmlyEntity && yPlane.GetPlane.Plane is EntityWarPlane yWarmlyEntity)
{
if (xWarmlyEntity.DopColor.R.CompareTo(yWarmlyEntity.DopColor.R) != 0)
{
return xWarmlyEntity.DopColor.R.CompareTo(yWarmlyEntity.DopColor.R);
}
if (xWarmlyEntity.DopColor.G.CompareTo(yWarmlyEntity.DopColor.G) != 0)
{
return xWarmlyEntity.DopColor.G.CompareTo(yWarmlyEntity.DopColor.G);
}
if (xWarmlyEntity.DopColor.B.CompareTo(yWarmlyEntity.DopColor.B) != 0)
{
return xWarmlyEntity.DopColor.B.CompareTo(yWarmlyEntity.DopColor.B);
}
}
var speedCompare = xPlane.GetPlane.Plane.Speed.CompareTo(yPlane.GetPlane.Plane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xPlane.GetPlane.Plane.Weight.CompareTo(yPlane.GetPlane.Plane.Weight);
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectPlane
{
internal class PlaneCompareByType : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject? x, IDrawingObject? y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xPlane = x as DrawingObject;
var yPlane = y as DrawingObject;
if (xPlane == null && yPlane == null)
{
return 0;
}
if (xPlane == null && yPlane != null)
{
return 1;
}
if (xPlane != null && yPlane == null)
{
return -1;
}
if (xPlane.GetPlane.GetType().Name != yPlane.GetPlane.GetType().Name)
{
if (xPlane.GetPlane.GetType().Name == "DrawingPlane")
{
return -1;
}
return 1;
}
var speedCompare =
xPlane.GetPlane.Plane.Speed.CompareTo(yPlane.GetPlane.Plane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xPlane.GetPlane.Plane.Weight.CompareTo(yPlane.GetPlane.Plane.Weight);
}
}
}

View File

@ -101,5 +101,14 @@ namespace ProjectPlane
}
}
}
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
}
}