Пример #1
0
        private static void SnapLineToNearestPoint(RulerLine line, IEnumerable <Quadrangle> hulls)
        {
            var step     = 1f;
            var mousePos = container.LocalMousePosition();

            if (!sceneView.Input.IsKeyPressed(Key.Shift))
            {
                step = (float)Math.Truncate(RulersWidget.CalculateEffectiveStep()) / RulersWidget.Tesselation;
            }
            var curValue = new Vector2(Utils.RoundTo(mousePos.X, step), Utils.RoundTo(mousePos.Y, step));

            if (SceneViewCommands.SnapRulerLinesToWidgets.Checked)
            {
                var mask = line.RulerOrientation.GetDirection();
                foreach (var hull in hulls)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (((hull[i] - mousePos) * mask).Length < ((mousePos - curValue) * mask).Length &&
                            !IsRulerContainLine(line.RulerOrientation.GetComponentFor(hull[i]), line.RulerOrientation)
                            )
                        {
                            line.MakePassingThroughPoint(hull[i]);
                            Window.Current.Invalidate();
                            return;
                        }
                    }
                }
            }

            if (!IsRulerContainLine(line.RulerOrientation.GetComponentFor(curValue), line.RulerOrientation))
            {
                line.MakePassingThroughPoint(curValue);
                Window.Current.Invalidate();
            }
        }