Пример #1
0
 void AddSpacingPosition(float spacingPos, ReferenceRects referenceRects)
 {
     if (!m_SpacingPositions.ContainsKey(spacingPos))
     {
         m_SpacingPositions.Add(spacingPos, referenceRects);
     }
 }
Пример #2
0
        void ComputeSpacingPositions(ReferenceRects referenceRects, Rect sourceRect)
        {
            SnapReference startReference = referenceRects.Orientation == Orientation.Vertical ? SnapReference.TopEdge : SnapReference.LeftEdge;
            SnapReference endReference   = referenceRects.Orientation == Orientation.Vertical ? SnapReference.BottomEdge : SnapReference.RightEdge;

            for (int i = 0; i < referenceRects.Rects.Count; ++i)
            {
                Rect firstRect     = referenceRects.Rects[i];
                int  nextRectIndex = i + 1;                // After rect i is done, we don't consider it anymore for the next iterations

                for (int j = nextRectIndex; j < referenceRects.Rects.Count; ++j)
                {
                    Rect secondRect = referenceRects.Rects[j];

                    // For each rect i, we find the 3 spacing positions: (examples are for horizontal orientation)
                    //        - 1. position before rect i
                    //              +-----+    +-----+    +-----+
                    //              | pos |    |  i  |    |  j  |
                    //              +-----+    +-----+    +-----+
                    //        - 2. position between rect i and rect j
                    //              +-----+    +-----+    +-----+
                    //              |  i  |    | pos |    |  j  |
                    //              +-----+    +-----+    +-----+
                    //        - 3. position after rect j
                    //              +-----+    +-----+    +-----+
                    //              |  i  |    |  j  |    | pos |
                    //              +-----+    +-----+    +-----+

                    List <float> spacingPositions = GetSpacingPositions(sourceRect, firstRect, secondRect, startReference, endReference, referenceRects.Orientation);
                    AddSpacingPositions(spacingPositions, sourceRect, firstRect, secondRect, referenceRects.Orientation);
                }
            }
        }
Пример #3
0
        SnapToSpacingResult GetSnapToSpacingResult(Rect sourceRect, float middlePos, ReferenceRects referenceRects)
        {
            float sourceRectCenter = referenceRects.Orientation == Orientation.Vertical ? GetMaxPos(sourceRect, SnapReference.VerticalCenter).y : GetMaxPos(sourceRect, SnapReference.HorizontalCenter).x;
            float offset           = sourceRectCenter - middlePos;

            SnapToSpacingResult minResult = new SnapToSpacingResult {
                Offset         = offset,
                ReferenceRects = referenceRects
            };

            return(minResult.Distance <= SnapDistance * 1 / m_CurrentScale ? minResult : null);
        }