Exemple #1
0
 /// <summary>
 /// Creates an instance of <see cref="IntersectionPoint"/> with values for its public fields based on <paramref name="point"/>: <see cref="ExtrudedPointUV.Parameter"/>, <see cref="ExtrudedPointUV.Point"/> and <see cref="ExtrudedPointUV.UV"/> values.
 /// <see cref="FirstPointSegmentIndex"/> and <see cref="FirstPointSegmentIndex2"/> are based on <paramref name="pointIndices"/>.
 /// <see cref="SecondPointSegmentIndex"/> and <see cref="SecondPointSegmentIndex2"/> are based on <paramref name="otherPointIndices"/>.
 /// </summary>
 /// <param name="point">The <see cref="ExtrudedPointUV"/> supplying <see cref="Parameter"/>, <see cref="Point"/> and <see cref="UV"/> values.</param>
 /// <param name="pointIndices">The <see cref="ExtrudedPointUV"/> supplying <see cref="FirstPointSegmentIndex"/> and <see cref="FirstPointSegmentIndex2"/> values.</param>
 /// <param name="otherPointIndices">The <see cref="ExtrudedPointUV"/> supplying <see cref="SecondPointSegmentIndex"/> and <see cref="SecondPointSegmentIndex2"/> values.</param>
 public IntersectionPoint(ExtrudedPointUV point, ExtrudedPointUV pointIndices, ExtrudedPointUV otherPointIndices)
 {
     Parameter = point.Parameter;
     Point     = point.Point;
     UV        = point.UV;
     FirstPointSegmentIndex   = pointIndices.LinePointSegmentIndex;
     FirstPointSegmentIndex2  = pointIndices.LinePointSegmentIndex2;
     SecondPointSegmentIndex  = otherPointIndices.LinePointSegmentIndex;
     SecondPointSegmentIndex2 = otherPointIndices.LinePointSegmentIndex2;
 }
Exemple #2
0
        /// <summary>
        /// Determines if an extruded point is closer to a line (on a segment-by-segment basis) than the extrusion amount.
        /// </summary>
        /// <param name="extrudedPoint">Extruded test point</param>
        /// <param name="linePointList">List of points defining the line</param>
        /// <param name="extrusionAmount">The extrusion amount</param>
        internal static bool IsCloserThanExtrusionDistance_Segmentwise(ExtrudedPointUV extrudedPoint, SegmentwiseLinePointListUV linePointList, float extrusionAmount)
        {
            var linePoints             = linePointList.Points;
            var linePointsMaximumDelta = linePointList.MaxSegmentDistance;

            var numSegments = linePoints.Count - 1;

            Vector2 point                  = extrudedPoint.Point;
            var     segmentIndex           = Math.Max(0, Math.Min(numSegments - 1, extrudedPoint.LinePointSegmentIndex));
            var     segmentIndex2          = Math.Max(0, Math.Min(numSegments - 1, extrudedPoint.LinePointSegmentIndex2));
            bool    isCloser               = false;
            var     extrusionAmountAbs     = Mathf.Abs(extrusionAmount);
            var     extrusionAmountSquared = extrusionAmount * extrusionAmount;

            //We'll look every *numSteps* points to see what's closest. We will increase it if the line point is much further away than the extrusion distance.
            int numSteps = 1;

            for (int i = 0; i < numSegments; i += numSteps)
            {
                if (i != segmentIndex && i != segmentIndex2)
                {
                    isCloser = LineSegmentUtil.IsPointWithinDistanceOfSegment(linePoints[i].Point, linePoints[i + 1].Point, point, extrusionAmountSquared);
                }
                if (isCloser)
                {
                    break;
                }
                else
                {
                    var distanceDiff = (linePoints[i].Point - point).magnitude - extrusionAmountAbs;
                    numSteps = Mathf.FloorToInt(Mathf.Max(1f, distanceDiff / linePointsMaximumDelta));
                }
            }

            return(isCloser);
        }
Exemple #3
0
 /// <summary>
 /// Creates an instance of <see cref="LinePointUV"/> with values for its public field taken from an extruded point <see cref="SegmentwiseExtrudedPointListUV"/>.
 /// </summary>
 /// <param name="extrudedPoint">The extruded point fromm which to take <see cref="Parameter"/>, <see cref="Point"/> and <see cref="UV"/> values.</param>
 public LinePointUV(ExtrudedPointUV extrudedPoint) : this(extrudedPoint.Parameter, extrudedPoint.Point, extrudedPoint.UV)
 {
 }
Exemple #4
0
 /// <summary> Gets the position of a <see cref="ExtrudedPointUV"/>.</summary>
 /// <param name="vector2WithUV">The <see cref="ExtrudedPointUV"/>.</param>
 private static Vector2 GetVector(ExtrudedPointUV vector2WithUV)
 {
     return(vector2WithUV.Point);
 }
Exemple #5
0
        /// <summary> Gets the average of two <see cref="ExtrudedPointUV"/>, not really caring about the line point segment indexes for the purposes of ClosestPointAlongSegmentwiseLine.</summary>
        /// <param name="firstVector">The first vector</param>
        /// <param name="secondVector">The second vector</param>
        /// <param name="fractionOfSecond"> The weight of the second vector in the average</param>
        private static ExtrudedPointUV GetAverage(ExtrudedPointUV firstVector, ExtrudedPointUV secondVector, float fractionOfSecond)
        {
            var averagedLinePoint = new LinePointUV(firstVector).AverageWith(new LinePointUV(secondVector), fractionOfSecond);

            return(new ExtrudedPointUV(averagedLinePoint, firstVector.LinePointSegmentIndex, firstVector.LinePointSegmentIndex2));
        }
Exemple #6
0
 /// <summary>
 /// Creates a new instance of <see cref="Vector2WithUV"/> with <see cref="Point"/> and <see cref="UV"/> values from a <paramref name="extrudedPointUV"/>.
 /// </summary>
 /// <param name="extrudedPointUV">The <see cref="ExtrudedPointUV"/> from which to take <see cref="Point"/> and <see cref="UV"/> values.</param>
 internal Vector2WithUV(ExtrudedPointUV extrudedPointUV) : this(extrudedPointUV.Point, extrudedPointUV.UV)
 {
 }