Reconfiguration added orientation switching

This commit is contained in:
Dawid Pietrykowski 2022-09-08 22:38:15 +02:00
parent ccec674836
commit c8d049b5ac

View File

@ -393,15 +393,67 @@ namespace Parking
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize,
!spot.AlignToTop);
if (Math.Abs(spotBorder - nextBorder) < 5.5f)
continue;
continue; // Try parallel
}
else {
float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
!spot.AlignToTop);
float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
!spot.AlignToTop);
if(nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize])
continue;
if (nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize]) {
// Try perpendicular
float bottomBorder = position.y - 2.25f / 2.0f;
float topBorder = position.y + 2.25f / 2.0f;
if (spot.AlignToTop) {
float newBottomBorder = topBorder - _spotHeights[size];
float newTopBorder = topBorder;
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular,
newSize,
!spot.AlignToTop);
if (Math.Abs(nextBorder - newBottomBorder) < 5.5f) {
continue;
}
}
else {
float newBottomBorder = bottomBorder;
float newTopBorder = bottomBorder + _spotHeights[size];
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular,
newSize,
!spot.AlignToTop);
if (Math.Abs(newTopBorder - nextBorder) < 5.5f) {
continue;
}
}
newPosition.y = bottomBorder + _spotHeights[(int) newSize] / 2.0f;
float newX = nextBorderRight;
if (spot.Lane == 0) {
// float xRelativeToRight = newX - Width / 2.0f;
// xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f;
// newX = xRelativeToRight + Width / 2.0f;
float xRelativeToRight = -(newX - Width / 2.0f);
// xRelativeToRight -= (xRelativeToRight - 2.25f / 2.0f) % 2.25f;
xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f;
xRelativeToRight += 2.25f;
xRelativeToRight = Math.Max(xRelativeToRight, 2.25f / 2.0f);
newX = (-xRelativeToRight + Width / 2.0f);
}
else {
float xRelativeToLeft = newX + Width / 2.0f;
xRelativeToLeft -= (xRelativeToLeft + 2.25f / 2.0f) % 2.25f;
newX = xRelativeToLeft - Width / 2.0f;
}
if(spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f)
continue;
newPosition.x = newX;
spot.Flipped = currentLaneSpots.FindIndex(spotPredicate => spotPredicate == spot) % 2 == 0;
rotation *= Quaternion.Euler(0, 0, spot.Flipped ? 90 : -90);
spot.Perpendicular = true;
}
}
}
@ -459,8 +511,10 @@ namespace Parking
sizeOffset = 2.25f / 2.0f;
else
sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f;
allBorders.Add(spotPosition.x + sizeOffset);
allBorders.Add(spotPosition.x - sizeOffset);
if(right)
allBorders.Add(spotPosition.x - sizeOffset);
else
allBorders.Add(spotPosition.x + sizeOffset);
}
allBorders.Sort();
@ -470,7 +524,7 @@ namespace Parking
if (perpendicular)
return position.x + (right ? 1 : -1) * _spotHeights[(int) size] / 2.0f;
return position.x + (right ? 1 : -1) * 2.25f / 2.0f;
return (right ? 1 : -1) * Width / 2.0f;
}
@ -547,16 +601,18 @@ namespace Parking
}
float currentX;
if (i != 0) currentX = -Width / 2f - 2.25f / 2f + 2.25f;
if (i != 0) currentX = -Width / 2f;
else currentX = Width / 2f; // + 5.5f - 2.25f / 2f + 2.25f + 1.75f;
bool flipped = false;
for (int j = 0; j < spotMap[i].Count; j++) {
if (!spotMap[i][j].Perpendicular && i == 0 && j == 0)
currentX -= spotSizes[(int) spotMap[i][j].Size] / 2.0f;
else if (spotMap[i][j].Perpendicular && i == 0 && j == 0)
currentX -= 2.25f / 2.0f;
// if (!spotMap[i][j].Perpendicular)
// currentX -= spotSizes[(int) spotMap[i][j].Size] / 2.0f;
// else if (spotMap[i][j].Perpendicular)
// currentX -= 2.25f / 2.0f;
currentX += (i != 0 ? 1 : -1) *
(spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f);
spotMap[i][j].Flipped = flipped;
bool alignTop = i % 2 != 0;
@ -594,7 +650,7 @@ namespace Parking
spotMap[i][j].Lane = i;
currentX += (i != 0 ? 1 : -1) *
(spotMap[i][j].Perpendicular ? 2.25f : spotSizes[(int) spotMap[i][j].Size]);
(spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f);
flipped = !flipped;
}