コード例 #1
0
    void SetInsertedHandlesPosition(BezierSegment insertedSegment, BezierSegment neighborSegment, BezierSegment segment)
    {
        int index = _currentHoverData.HoveredSegmentPointIndex;

        Vector2 tangent      = segment.Tangent(index - 1);
        float   segmentCount = segment.SegmentCount;
        float   quotient     = (index / segmentCount);

        Vector2 b = segment.SegmentPoints[index - 1];

        insertedSegment.Point = b;

        Vector2 q = CurveMath.GetPointOnLine(neighborSegment.SecondHandle, segment.FirstHandle, quotient);

        Vector2 q0 = neighborSegment.MoveHandleCloserToPoint(1 - quotient, true);

        segment.MoveHandleCloserToPoint(quotient, false);

        Vector2 r0 = CurveMath.GetIntersectionPointCoordinates(q0, q - q0, b, tangent);

        insertedSegment.SecondHandle = b + (b - r0) / index * (segmentCount - index);
        insertedSegment.FirstHandle  = r0;

        _currentPathObject.UpdatePointsHandlesRenderer();
    }
コード例 #2
0
    public override bool OverPathObject()
    {
        Vector2 mousePosition = Program.Instance.GetMouseCanvasPosition();

        // not over bounding box

        if (!MouseOverObject())
        {
            return(false);
        }

        int crossings = 0;

        for (int i = 0; i < _pointsSorted.Count - 1; i++)
        {
            float biggerY = _pointsSorted[i].y > _pointsSorted[i + 1].y ? _pointsSorted[i].y : _pointsSorted[i + 1].y;

            bool isFound;

            if (mousePosition.y <= biggerY)
            {
                if ((mousePosition.x >= _pointsSorted[i].x && mousePosition.x <= _pointsSorted[i + 1].x) || (mousePosition.x <= _pointsSorted[i].x && mousePosition.x >= _pointsSorted[i + 1].x))
                {
                    if (mousePosition.y <= CurveMath.GetIntersectionPointCoordinates(_pointsSorted[i], _pointsSorted[i + 1], mousePosition, mousePosition + Vector2.up, out isFound).y)
                    {
                        if (isFound)
                        {
                            crossings++;
                        }
                    }
                }
            }
        }
        return(crossings % 2 == 1);
    }
コード例 #3
0
    void IsAnyOtherPointBelow(out bool isAnysmaller, Vector2 left, Vector2 right)
    {
        float leftY            = left.y;
        float leftX            = left.x;
        float rightY           = right.y;
        float rightX           = right.x;
        float _currentSmallest = float.MaxValue;

        isAnysmaller = false;

        for (int i = 2; i < _points.Count - 2; i++)
        {
            Vector2 currentPoint = _points[i];

            if (currentPoint.x > leftX && currentPoint.x < rightX)
            {
                float currentY = currentPoint.y;
                if (currentY < leftY && currentY < rightY)
                {
                    Vector2 followingPoint = _points[i + 1];
                    Vector2 previousPoint  = _points[i - 1];
                    if ((previousPoint.y > leftY && previousPoint.x > leftX && previousPoint.x < rightX) ||
                        (followingPoint.y > leftY && followingPoint.x > leftX && followingPoint.x < rightX))
                    {
                        bool    found;
                        Vector2 intersection = CurveMath.GetIntersectionPointCoordinates(currentPoint, previousPoint, left, right, out found);
                        if (found && CurveMath.IsPointOnLine(left, right, intersection))
                        {
                            if (currentY < _currentSmallest)
                            {
                                _currentSmallest = currentY;
                                beneathIndex     = i;
                                isAnysmaller     = true;
                            }
                        }
                    }
                }
            }
        }
    }