public JoinedPath(Path pathFirst, Path pathSecond) { measureFirst = new PathMeasure(pathFirst, false); measureSecond = new PathMeasure(pathSecond, false); lengthFirst = measureFirst.Length; lengthSecond = measureSecond.Length; }
public override Vector?GetValue(Keyframe <Vector?> keyframe, double keyframeProgress) { var pathKeyframe = (PathKeyframe)keyframe; var path = pathKeyframe.Path; if (path == null || path.Contours.Count == 0) { return(keyframe.StartValue); } if (ValueCallback != null) { return(ValueCallback.GetValueInternal(pathKeyframe.StartFrame.Value, pathKeyframe.EndFrame.Value, pathKeyframe.StartValue, pathKeyframe.EndValue, LinearCurrentKeyframeProgress, keyframeProgress, Progress)); } if (_pathMeasureKeyframe != pathKeyframe) { _pathMeasure?.Dispose(); _pathMeasure = new PathMeasure(path); _pathMeasureKeyframe = pathKeyframe; } return(_pathMeasure.GetPosTan(keyframeProgress * _pathMeasure.Length)); }
public JoinedPath(Path pathFirst, Path pathSecond) { _measureFirst = new PathMeasure(pathFirst, false); _measureSecond = new PathMeasure(pathSecond, false); _lengthFirst = _measureFirst.Length; _lengthSecond = _measureSecond.Length; }
public void SetPath(Path p) { Path = p; var measure = new PathMeasure(Path, false); _pathLength = measure.Length; }
private void Dispose(bool disposing) { if (_pathMeasure != null) { _pathMeasure.Dispose(disposing); _pathMeasure = null; } }
public SvgPath(Path path, Paint paint) { this.path = path; this.paint = paint; measure = new PathMeasure(path, false); this.length = measure.Length; region.SetPath(path, maxClip); bounds = region.Bounds; }
public override bool OnTouchEvent(MotionEvent e) { var touchX = e.GetX(); var touchY = e.GetY(); PathMeasure pm = new PathMeasure(DrawPath, false); //coordinates will be here float[] PrevCoords = { 0f, 0f }; //get coordinates of the middle point pm.GetPosTan(pm.Length, PrevCoords, null); switch (e.Action) { case MotionEventActions.Down: DrawPath.MoveTo(touchX, touchY); PointerDown = true; try { Invalidate(); } catch (ObjectDisposedException) { return(false); } PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs. PointerEventType.Down, new Point(PrevCoords[0], PrevCoords[1]), new Point(touchX, touchY), PointerDown)); break; case MotionEventActions.Move: DrawPath.LineTo(touchX, touchY); try { Invalidate(); } catch (ObjectDisposedException) { return(false); } PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs. PointerEventType.Move, new Point(PrevCoords[0], PrevCoords[1]), new Point(touchX, touchY), PointerDown)); break; case MotionEventActions.Up: DrawCanvas.DrawPath(DrawPath, DrawPaint); DrawPath.Reset(); PointerDown = false; try { Invalidate(); } catch (ObjectDisposedException) { return(false); } PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs. PointerEventType.Up, new Point(PrevCoords[0], PrevCoords[1]), new Point(touchX, touchY), PointerDown)); break; case MotionEventActions.Cancel: DrawCanvas.DrawPath(DrawPath, DrawPaint); DrawPath.Reset(); PointerDown = false; try { Invalidate(); } catch (ObjectDisposedException) { return(false); } PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs. PointerEventType.Cancel, new Point(PrevCoords[0], PrevCoords[1]), new Point(touchX, touchY), PointerDown)); break; default: return(false); } return(true); }
private float GetRestLength(Path path, float startD) { Path tempPath = new Path(); PathMeasure pathMeasure = new PathMeasure(path, false); pathMeasure.GetSegment(startD, pathMeasure.Length, tempPath, true); pathMeasure.SetPath(tempPath, false); return(pathMeasure.Length); }
/// <summary> /// Scale the Path by factor N, where N is the number of times each coordinate is /// multiplied. /// </summary> /// <param name="x">Multiplicity of X coordinates</param> /// <param name="y">Multiplicity of Y coordinates</param> public void ScalePathBy(float x, float y) { var m = new Matrix(); m.PostScale(x, y); Path.Transform(m); var measure = new PathMeasure(Path, false); _pathLength = measure.Length; }
public override Vector2?GetValue(Keyframe <Vector2?> keyframe, float keyframeProgress) { var pathKeyframe = (PathKeyframe)keyframe; var path = pathKeyframe.Path; if (path == null || path.Contours.Count == 0) { return(keyframe.StartValue); } if (_pathMeasureKeyframe != pathKeyframe) { _pathMeasure = new PathMeasure(path); _pathMeasureKeyframe = pathKeyframe; } return(_pathMeasure.GetPosTan(keyframeProgress * _pathMeasure.Length)); }
// Used to fetch points from given path. private PathPoints[] getPoints(Path p) { //Size of 1000 indicates that, 1000 points // would be extracted from the path var pointArray = new PathPoints[1000]; var pm = new PathMeasure(p, false); var length = pm.Length; var distance = 0f; var speed = length / 1000; var counter = 0; var aCoordinates = new float[2]; while ((distance < length) && (counter < 1000)) { pm.GetPosTan(distance, aCoordinates, null); pointArray[counter] = new PathPoints(aCoordinates[0], aCoordinates[1]); counter++; distance = distance + speed; } return(pointArray); }
private PathPoints[] getPoints(Path path) { PathPoints[] pointArray = new PathPoints[100]; PathMeasure pm = new PathMeasure(path, false); float length = pm.Length; float distance = 0f; float speed = length / 100; int counter = 0; float[] aCoordinates = new float[2]; while ((distance < length) && (counter < 100)) { // get point from the pathMoon pm.GetPosTan(distance, aCoordinates, null); pointArray[counter] = new PathPoints(aCoordinates[0], aCoordinates[1]); counter++; distance = distance + speed; } return(pointArray); }
internal static void ApplyTrimPathIfNeeded(Path path, float startValue, float endValue, float offsetValue) { LottieLog.BeginSection("applyTrimPathIfNeeded"); using (var pathMeasure = new PathMeasure(path)) { var length = pathMeasure.Length; if (startValue == 1f && endValue == 0f) { LottieLog.EndSection("applyTrimPathIfNeeded"); return; } if (length < 1f || Math.Abs(endValue - startValue - 1) < .01) { LottieLog.EndSection("applyTrimPathIfNeeded"); return; } var start = length * startValue; var end = length * endValue; var newStart = Math.Min(start, end); var newEnd = Math.Max(start, end); var offset = offsetValue * length; newStart += offset; newEnd += offset; // If the trim path has rotated around the path, we need to shift it back. if (newStart >= length && newEnd >= length) { newStart = MiscUtils.FloorMod(newStart, length); newEnd = MiscUtils.FloorMod(newEnd, length); } if (newStart < 0) { newStart = MiscUtils.FloorMod(newStart, length); } if (newEnd < 0) { newEnd = MiscUtils.FloorMod(newEnd, length); } // If the start and end are equals, return an empty path. if (newStart == newEnd) { path.Reset(); LottieLog.EndSection("applyTrimPathIfNeeded"); return; } if (newStart >= newEnd) { newStart -= length; } _tempPath.Reset(); pathMeasure.GetSegment(newStart, newEnd, ref _tempPath, true); if (newEnd > length) { _tempPath2.Reset(); pathMeasure.GetSegment(0, newEnd % length, ref _tempPath2, true); _tempPath.AddPath(_tempPath2); } else if (newStart < 0) { _tempPath2.Reset(); pathMeasure.GetSegment(length + newStart, length, ref _tempPath2, true); _tempPath.AddPath(_tempPath2); } } path.Set(_tempPath); LottieLog.EndSection("applyTrimPathIfNeeded"); }