static public bool IsCrop(this Stroq stroke) { if (stroke.Cusps().Length == 3 && stroke.Cusps().Straightness(0, 1) < 0.15 & stroke.Cusps().Straightness(1, 2) < 0.15 && Math.Abs(stroke.Cusps().inSeg(1).Direction.UnsignedAngle(stroke.Cusps().outSeg(1).Direction) - Math.PI / 2) < Math.PI / 4) { return(true); } return(false); }
static public bool BalancedCrops(this Stroq crop1, Stroq crop2) { if (crop2 != null && (Math.Sign(crop1.Cusps()[1].curvature) == Math.Sign(crop2.Cusps()[1].curvature) || ((crop1.Cusps().outSeg(1).Direction.Normal().Dot(crop2.Cusps().inSeg(1).Direction.Normal()) < -0.5) && (crop1.Cusps().inSeg(1).Direction.Normal().Dot(crop2.Cusps().outSeg(1).Direction.Normal()) < -0.5)))) { return(false); } return(true); }
static bool insertionCaret(Stroq caret) { double dist = (caret.Cusps()[1].dist / caret.Cusps().Distance - 0.5); bool isCaret = caret.Cusps().Length == 3 && Math.Abs(caret.Cusps()[1].dist / caret.Cusps().Distance - 0.5) < .1 && caret.Cusps().Straightness(0, 1) < 0.15 && caret.Cusps().Straightness(1, 2) < 0.15 && caret.Cusps().inSeg(1).Direction.UnsignedAngle(new Vec(0, -1)) < Math.PI / 4 && caret.Cusps().inSeg(1).Direction.UnsignedAngle(-caret.Cusps().outSeg(1).Direction) < Math.PI / 4; return(isCaret); }
static public bool IsFlick(this Stroq stroke) { if (!stroke.Property.Exists(IS_FLICK)) { bool flick = stroke.Cusps().Length == 2 && stroke.Cusps().Straightness(0, 1) < 0.15 && stroke.Cusps().Distance > 20 && stroke.Count * 16 < 353 && (stroke.Cusps()[1].pt - stroke.Cusps()[0].pt).Normal().Dot(new Vec(1, -1).Normal()) > 0.65; stroke.Property[IS_FLICK] = flick; } return((bool)stroke.Property[IS_FLICK]); }
static int leftRightHook(Stroq caret) { Pt endpt = Pt.Avg(caret[0], caret[-1]); int dir = (caret.Cusps().Length == 3 && Math.Abs(caret.Cusps()[1].dist / caret.Cusps().Distance - 0.5) < .1 && caret.Cusps().Straightness(0, 1) < 0.15 && caret.Cusps().Straightness(1, 2) < 0.15 && caret.Cusps().inSeg(1).Direction.UnsignedAngle(-caret.Cusps().outSeg(1).Direction) < Math.PI / 8) ? (caret.Cusps()[1].pt - endpt).UnsignedAngle(new Vec(1, 0)) < Math.PI / 6 ? 1 : ((caret.Cusps()[1].pt - endpt).UnsignedAngle(new Vec(-1, 0)) < Math.PI / 6 ? -1 : 0) : 0; return(dir); }
static public bool IsCircle(this Stroq stroke) { if (!stroke.Property.Exists(IS_CIRCLE)) { bool circle = (stroke[0] - stroke[-1]).Length / stroke.GetBounds().MaxDim < .2; for (int i = 1; i < stroke.Cusps().Length - 1 && circle; i++) { if (Math.Abs(stroke.Cusps()[i].curvature) > 0.6) { circle = false; } if (Math.Sign(stroke.Cusps()[i].curvature) != Math.Sign(stroke.Cusps()[i - 1].curvature)) { circle = false; } } stroke.Property[IS_CIRCLE] = circle; } return((bool)stroke.Property[IS_CIRCLE]); }
static Dir doubleHitch(Stroq s) { if (s.Cusps().Length == 4 && s.Cusps().Straightness() < zStraightnessTolerance) { Vec dir = (s[-1] - s[0]).Normal(); double dx = dir.SignedAngle(Vec.Xaxis); double ndx = dir.SignedAngle(-Vec.Xaxis); if (dir.X > 0.3) { if (dx > .3) { return(Dir.NE); } else if (dx < -.3) { return(Dir.SE); } else { return(Dir.E); } } else if (dir.X < 0.3) { if (ndx < -.3) { return(Dir.NW); } else if (ndx > .3) { return(Dir.SW); } else { return(Dir.W); } } } return(Dir.None); }
static public object Lassoed(this Stroq stroke, LassoTest test) { object sel = null; DictLookup dict = null; if (!stroke.Property.Exists(LASSO)) { dict = new DictLookup(); stroke.Property[LASSO] = dict; } else { dict = (DictLookup)stroke.Property[LASSO]; } if (dict.ContainsKey(test)) { sel = dict[test]; } else { double threshold = stroke.GetBounds().MaxDim * .2; Stroq lasso = stroke; // truncate the lasso where it retraces closest to its starting point. for (int i = stroke.Count - 1; i > Math.Max(stroke.Count / 2, stroke.Cusps()[-2].index); i--) { if ((stroke[i] - stroke[0]).Length < threshold) { List <Pt> lassoPts = new List <Pt>(); for (int j = 0; j < i; j++) { lassoPts.Add(stroke[j]); } lasso = new Stroq(lassoPts.ToArray()); } } sel = test(lasso); dict.Add(test, sel); } return(sel); }
static bool isCircular(Pt[] clippepts) { Stroq tempStroke = new Stroq(clippepts); Cusps set = tempStroke.Cusps(); if (set.SelfIntersects.Count > 4) { return(false); } if (set.Distance > 1.25 * (tempStroke.GetBounds().Width *2 + tempStroke.GetBounds().Height *2)) { return(false); } for (int i = 1; i < set.Length; i++) { if (Math.Abs(set[i].curvature) > .75) { return(false); } } double d = (tempStroke[-1] - tempStroke[0]).Length / tempStroke.GetBounds().MaxDim; return(d < 0.75); }
static public bool IsLasso(this Stroq stroke) { double threshold = stroke.GetBounds().MaxDim * .2; bool canBeLasso = false; for (int i = stroke.Count - 1; !canBeLasso && i > Math.Max(stroke.Count / 2, stroke.Cusps()[-2].index); i--) { if ((stroke[i] - stroke[0]).Length < threshold) { canBeLasso = true; // the lasso has returned close enough to the starting point to make it a lasso } } return(canBeLasso); }