// Align elements within a line. Note that this does not modify LayoutBounds. So if we get
        // repeated measures, the LayoutBounds remain the same in each layout.
        private void PerformLineAlignment(
            int lineStartIndex,
            int countInLine,
            double spaceAtLineStart,
            double spaceAtLineEnd,
            double lineSize,
            LineAlignment lineAlignment,
            bool isWrapping,
            Size finalSize,
            string layoutId)
        {
            for (int rangeIndex = lineStartIndex; rangeIndex < lineStartIndex + countInLine; ++rangeIndex)
            {
                var bounds = m_elementManager.GetLayoutBoundsForRealizedIndex(rangeIndex);
                OM.SetMajorSize(ref bounds, lineSize);

                if (!m_scrollOrientationSameAsFlow)
                {
                    // Note: Space at start could potentially be negative
                    if (spaceAtLineStart != 0 || spaceAtLineEnd != 0)
                    {
                        double totalSpace = spaceAtLineStart + spaceAtLineEnd;
                        switch (lineAlignment)
                        {
                        case LineAlignment.Start:
                        {
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) - spaceAtLineStart);
                            break;
                        }

                        case LineAlignment.End:
                        {
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) + spaceAtLineEnd);
                            break;
                        }

                        case LineAlignment.Center:
                        {
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) - spaceAtLineStart);
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) + totalSpace / 2);
                            break;
                        }

                        case LineAlignment.SpaceAround:
                        {
                            double interItemSpace = countInLine >= 1 ? totalSpace / (countInLine * 2) : 0;
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) - spaceAtLineStart);
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) + interItemSpace * ((rangeIndex - lineStartIndex + 1) * 2 - 1));
                            break;
                        }

                        case LineAlignment.SpaceBetween:
                        {
                            double interItemSpace = countInLine > 1 ? totalSpace / (countInLine - 1) : 0;
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) - spaceAtLineStart);
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) + interItemSpace * (rangeIndex - lineStartIndex));
                            break;
                        }

                        case LineAlignment.SpaceEvenly:
                        {
                            double interItemSpace = countInLine >= 1 ? totalSpace / (countInLine + 1) : 0;
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) - spaceAtLineStart);
                            OM.SetMinorStart(ref bounds, OM.MinorStart(bounds) + interItemSpace * (rangeIndex - lineStartIndex + 1));
                            break;
                        }
                        }
                    }
                }

                bounds.X -= m_lastExtent.X;
                bounds.Y -= m_lastExtent.Y;

                if (!isWrapping)
                {
                    OM.SetMinorSize(ref bounds, Math.Max(OM.MinorSize(bounds), OM.Minor(finalSize)));
                }

                var element = m_elementManager.GetAt(rangeIndex);

                element.Arrange(bounds);
            }
        }