internal override bool HitTest(StrokeNodeData beginNode, StrokeNodeData endNode, Quad quad, IEnumerable <ContourSegment> hitContour) { double num = 0.0; StrokeNodeData strokeNodeData; Vector vector; if (beginNode.IsEmpty || (quad.IsEmpty && endNode.PressureFactor > beginNode.PressureFactor)) { strokeNodeData = endNode; StrokeNodeData empty = StrokeNodeData.Empty; vector = default(Vector); } else { strokeNodeData = beginNode; StrokeNodeData empty = endNode; num = _radius * (double)empty.PressureFactor; num *= num; vector = empty.Position - strokeNodeData.Position; if (!_nodeShapeToCircle.IsIdentity) { vector = _nodeShapeToCircle.Transform(vector); } } double num2 = _radius * (double)strokeNodeData.PressureFactor; num2 *= num2; bool flag = false; bool flag2 = true; foreach (ContourSegment item in hitContour) { if (!item.IsArc) { Vector vector2 = item.Begin - strokeNodeData.Position; Vector vector3 = vector2 + item.Vector; if (!_nodeShapeToCircle.IsIdentity) { vector2 = _nodeShapeToCircle.Transform(vector2); vector3 = _nodeShapeToCircle.Transform(vector3); } if (StrokeNodeOperations.GetNearest(vector2, vector3).LengthSquared <= num2) { flag = true; break; } if (!quad.IsEmpty && (StrokeNodeOperations.GetNearest(vector2 - vector, vector3 - vector).LengthSquared <= num || StrokeNodeOperations.HitTestQuadSegment(quad, item.Begin, item.End))) { flag = true; break; } if (flag2 && StrokeNodeOperations.WhereIsVectorAboutVector(endNode.Position - item.Begin, item.Vector) != HitResult.Right) { flag2 = false; } } } return(flag | flag2); }
internal StrokeNode(StrokeNodeOperations operations, int index, StrokeNodeData nodeData, StrokeNodeData lastNodeData, bool isLastNode) { _operations = operations; _index = index; _thisNode = nodeData; _lastNode = lastNodeData; _isQuadCached = lastNodeData.IsEmpty; _connectingQuad = Quad.Empty; _isLastNode = isLastNode; }
internal StrokeNodeIterator(StylusPointCollection stylusPoints, StrokeNodeOperations operations, bool usePressure) { _stylusPoints = stylusPoints; if (operations == null) { throw new ArgumentNullException("operations"); } _operations = operations; _usePressure = usePressure; }
private static HitResult WhereIsNodeAboutSegment(Vector spine, Vector segBegin, Vector segEnd) { HitResult result = HitResult.Right; Vector vector = segEnd - segBegin; if (StrokeNodeOperations.WhereIsVectorAboutVector(-segBegin, vector) == HitResult.Left && !DoubleUtil.IsZero(Vector.Determinant(spine, vector))) { result = HitResult.Left; } return(result); }
internal override StrokeFIndices CutTest(StrokeNodeData beginNode, StrokeNodeData endNode, Quad quad, Point hitBeginPoint, Point hitEndPoint) { Vector vector = beginNode.IsEmpty ? new Vector(0.0, 0.0) : (beginNode.Position - endNode.Position); Vector vector2 = hitBeginPoint - endNode.Position; Vector vector3 = hitEndPoint - endNode.Position; if (!_nodeShapeToCircle.IsIdentity) { vector = _nodeShapeToCircle.Transform(vector); vector2 = _nodeShapeToCircle.Transform(vector2); vector3 = _nodeShapeToCircle.Transform(vector3); } StrokeFIndices empty = StrokeFIndices.Empty; double num = 0.0; double num2 = _radius * (double)endNode.PressureFactor; if (StrokeNodeOperations.GetNearest(vector2, vector3).LengthSquared <= num2 * num2) { empty.EndFIndex = StrokeFIndices.AfterLast; empty.BeginFIndex = (beginNode.IsEmpty ? StrokeFIndices.BeforeFirst : 1.0); } if (!beginNode.IsEmpty) { num = _radius * (double)beginNode.PressureFactor; if (StrokeNodeOperations.GetNearest(vector2 - vector, vector3 - vector).LengthSquared <= num * num) { empty.BeginFIndex = StrokeFIndices.BeforeFirst; if (!DoubleUtil.AreClose(empty.EndFIndex, StrokeFIndices.AfterLast)) { empty.EndFIndex = 0.0; } } } if (empty.IsFull || quad.IsEmpty || (empty.IsEmpty && !StrokeNodeOperations.HitTestQuadSegment(quad, hitBeginPoint, hitEndPoint))) { return(empty); } if (!DoubleUtil.AreClose(empty.BeginFIndex, StrokeFIndices.BeforeFirst)) { empty.BeginFIndex = ClipTest(-vector, num, num2, vector2 - vector, vector3 - vector); } if (!DoubleUtil.AreClose(empty.EndFIndex, StrokeFIndices.AfterLast)) { empty.EndFIndex = 1.0 - ClipTest(vector, num2, num, vector2, vector3); } if (IsInvalidCutTestResult(empty)) { return(StrokeFIndices.Empty); } return(empty); }
internal static StrokeNodeIterator GetIterator(StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes) { if (stylusPoints == null) { throw new ArgumentNullException("stylusPoints"); } if (drawingAttributes == null) { throw new ArgumentNullException("drawingAttributes"); } StrokeNodeOperations operations = StrokeNodeOperations.CreateInstance(GetStylusShape(drawingAttributes)); bool usePressure = !drawingAttributes.IgnorePressure; return(new StrokeNodeIterator(stylusPoints, operations, usePressure)); }
private static double ClipTest(Vector spineVector, double beginRadius, double endRadius, Vector hitBegin, Vector hitEnd) { if (DoubleUtil.IsZero(spineVector.X) && DoubleUtil.IsZero(spineVector.Y)) { Vector nearest = StrokeNodeOperations.GetNearest(hitBegin, hitEnd); double num = (nearest.X == 0.0) ? Math.Abs(nearest.Y) : ((nearest.Y != 0.0) ? nearest.Length : Math.Abs(nearest.X)); return(StrokeNodeOperations.AdjustFIndex((num - beginRadius) / (endRadius - beginRadius))); } if (DoubleUtil.AreClose(hitBegin, hitEnd)) { return(ClipTest(spineVector, beginRadius, endRadius, hitBegin)); } Vector vector = hitEnd - hitBegin; double num2; if (DoubleUtil.IsZero(Vector.Determinant(spineVector, vector))) { num2 = ClipTest(spineVector, beginRadius, endRadius, StrokeNodeOperations.GetNearest(hitBegin, hitEnd)); } else { double projectionFIndex = StrokeNodeOperations.GetProjectionFIndex(hitBegin, hitEnd); Vector vector2 = hitBegin + vector * projectionFIndex; if (vector2.LengthSquared < beginRadius * beginRadius) { num2 = ClipTest(spineVector, beginRadius, endRadius, (0.0 > projectionFIndex) ? hitBegin : hitEnd); } else { Vector vector3 = spineVector + StrokeNodeOperations.GetProjection(-spineVector, vector2 - spineVector); if (DoubleUtil.IsZero(vector3.LengthSquared) || DoubleUtil.IsZero(endRadius - beginRadius + vector3.Length)) { return(1.0); } num2 = (vector2.Length - beginRadius) / (endRadius - beginRadius + vector3.Length); Vector vector4 = spineVector * num2; double projectionFIndex2 = StrokeNodeOperations.GetProjectionFIndex(hitBegin - vector4, hitEnd - vector4); if (!DoubleUtil.IsBetweenZeroAndOne(projectionFIndex2)) { num2 = ClipTest(spineVector, beginRadius, endRadius, (0.0 > projectionFIndex2) ? hitBegin : hitEnd); } } } return(StrokeNodeOperations.AdjustFIndex(num2)); }
internal override bool HitTest(StrokeNodeData beginNode, StrokeNodeData endNode, Quad quad, Point hitBeginPoint, Point hitEndPoint) { StrokeNodeData strokeNodeData; StrokeNodeData strokeNodeData2; if (beginNode.IsEmpty || (quad.IsEmpty && endNode.PressureFactor > beginNode.PressureFactor)) { strokeNodeData = endNode; strokeNodeData2 = StrokeNodeData.Empty; } else { strokeNodeData = beginNode; strokeNodeData2 = endNode; } Vector vector = hitBeginPoint - strokeNodeData.Position; Vector vector2 = hitEndPoint - strokeNodeData.Position; if (!_nodeShapeToCircle.IsIdentity) { vector = _nodeShapeToCircle.Transform(vector); vector2 = _nodeShapeToCircle.Transform(vector2); } bool result = false; double num = _radius * (double)strokeNodeData.PressureFactor; if (StrokeNodeOperations.GetNearest(vector, vector2).LengthSquared <= num * num) { result = true; } else if (!quad.IsEmpty) { Vector vector3 = strokeNodeData2.Position - strokeNodeData.Position; if (!_nodeShapeToCircle.IsIdentity) { vector3 = _nodeShapeToCircle.Transform(vector3); } double num2 = _radius * (double)strokeNodeData2.PressureFactor; if (StrokeNodeOperations.GetNearest(vector - vector3, vector2 - vector3).LengthSquared <= num2 * num2 || StrokeNodeOperations.HitTestQuadSegment(quad, hitBeginPoint, hitEndPoint)) { result = true; } } return(result); }
private static double ClipTest(Vector spine, double beginRadius, double endRadius, Vector hit) { double num = endRadius - beginRadius; double num2 = spine.X * spine.X + spine.Y * spine.Y - num * num; double num3 = -2.0 * (hit.X * spine.X + hit.Y * spine.Y + beginRadius * num); double num4 = hit.X * hit.X + hit.Y * hit.Y - beginRadius * beginRadius; if (DoubleUtil.IsZero(num2) || !DoubleUtil.GreaterThanOrClose(num3 * num3, 4.0 * num2 * num4)) { return(1.0); } double num5 = Math.Sqrt(num3 * num3 - 4.0 * num2 * num4); double num6 = (0.0 - num3 + num5) / (2.0 * num2); double num7 = (0.0 - num3 - num5) / (2.0 * num2); double findex = (DoubleUtil.IsBetweenZeroAndOne(num6) && DoubleUtil.IsBetweenZeroAndOne(num6)) ? Math.Min(num6, num7) : (DoubleUtil.IsBetweenZeroAndOne(num6) ? num6 : (DoubleUtil.IsBetweenZeroAndOne(num7) ? num7 : ((num6 > 1.0 && num7 > 1.0) ? 1.0 : ((!(num6 < 0.0) || !(num7 < 0.0)) ? ((Math.Abs(Math.Min(num6, num7) - 0.0) < Math.Abs(Math.Max(num6, num7) - 1.0)) ? 0.0 : 1.0) : 0.0)))); return(StrokeNodeOperations.AdjustFIndex(findex)); }
internal override StrokeFIndices CutTest(StrokeNodeData beginNode, StrokeNodeData endNode, Quad quad, IEnumerable <ContourSegment> hitContour) { Vector vector = beginNode.IsEmpty ? new Vector(0.0, 0.0) : (beginNode.Position - endNode.Position); if (!_nodeShapeToCircle.IsIdentity) { vector = _nodeShapeToCircle.Transform(vector); } double num = 0.0; double num2 = 0.0; double num3 = _radius * (double)endNode.PressureFactor; double num4 = num3 * num3; if (!beginNode.IsEmpty) { num = _radius * (double)beginNode.PressureFactor; num2 = num * num; } bool flag = true; StrokeFIndices result = StrokeFIndices.Empty; foreach (ContourSegment item in hitContour) { if (!item.IsArc) { Vector vector2 = item.Begin - endNode.Position; Vector vector3 = vector2 + item.Vector; if (!_nodeShapeToCircle.IsIdentity) { vector2 = _nodeShapeToCircle.Transform(vector2); vector3 = _nodeShapeToCircle.Transform(vector3); } bool flag2 = false; if (StrokeNodeOperations.GetNearest(vector2, vector3).LengthSquared < num4) { flag2 = true; if (!DoubleUtil.AreClose(result.EndFIndex, StrokeFIndices.AfterLast)) { result.EndFIndex = StrokeFIndices.AfterLast; if (beginNode.IsEmpty) { result.BeginFIndex = StrokeFIndices.BeforeFirst; break; } if (DoubleUtil.AreClose(result.BeginFIndex, StrokeFIndices.BeforeFirst)) { break; } } } if (!beginNode.IsEmpty && (!flag2 || !DoubleUtil.AreClose(result.BeginFIndex, StrokeFIndices.BeforeFirst)) && StrokeNodeOperations.GetNearest(vector2 - vector, vector3 - vector).LengthSquared < num2) { flag2 = true; if (!DoubleUtil.AreClose(result.BeginFIndex, StrokeFIndices.BeforeFirst)) { result.BeginFIndex = StrokeFIndices.BeforeFirst; if (DoubleUtil.AreClose(result.EndFIndex, StrokeFIndices.AfterLast)) { break; } } } if (beginNode.IsEmpty || (!flag2 && (quad.IsEmpty || !StrokeNodeOperations.HitTestQuadSegment(quad, item.Begin, item.End)))) { if (flag && StrokeNodeOperations.WhereIsVectorAboutVector(endNode.Position - item.Begin, item.Vector) != HitResult.Right) { flag = false; } } else { flag = false; CalculateCutLocations(vector, vector2, vector3, num3, num, ref result); if (result.IsFull) { break; } } } } if (!result.IsFull) { if (flag) { result = StrokeFIndices.Full; } else if (DoubleUtil.AreClose(result.EndFIndex, StrokeFIndices.BeforeFirst) && !DoubleUtil.AreClose(result.BeginFIndex, StrokeFIndices.AfterLast)) { result.EndFIndex = StrokeFIndices.AfterLast; } else if (DoubleUtil.AreClose(result.BeginFIndex, StrokeFIndices.AfterLast) && !DoubleUtil.AreClose(result.EndFIndex, StrokeFIndices.BeforeFirst)) { result.BeginFIndex = StrokeFIndices.BeforeFirst; } } if (IsInvalidCutTestResult(result)) { return(StrokeFIndices.Empty); } return(result); }
internal StrokeNodeIterator(DrawingAttributes drawingAttributes) : this(null, StrokeNodeOperations.CreateInstance((drawingAttributes == null) ? null : GetStylusShape(drawingAttributes)), !(drawingAttributes == null) && !drawingAttributes.IgnorePressure) { }
internal StrokeNodeIterator(StylusShape nodeShape) : this(null, StrokeNodeOperations.CreateInstance(nodeShape), false) { }