private void ComputeAll() { System.Drawing.RectangleF boxA = Compute.BoundingBox(m_StrokeA.Points); System.Drawing.RectangleF boxB = Compute.BoundingBox(m_StrokeB.Points); bool aLeft, aRight, aTop, aBottom; aLeft = aRight = aTop = aBottom = false; if (boxA.X <= boxB.X) { aLeft = true; } if (boxA.X + boxA.Width >= boxB.X + boxB.Width) { aRight = true; } if (boxA.Y <= boxB.Y) { aTop = true; } if (boxA.Y + boxA.Height >= boxB.Y + boxB.Height) { aBottom = true; } if (aLeft && aRight) // 'b' enclosed in 'a' (horizontal) { m_xOverlap = (double)boxB.Width; } else if (!aLeft && !aRight) // 'a' enclosed in 'b' (horizontal) { m_xOverlap = (double)boxA.Width; } else if (aLeft) // 'a' left of 'b' { m_xOverlap = (double)(boxA.X + boxA.Width - boxB.X); } else // 'b' left of 'a' { m_xOverlap = (double)(boxB.X + boxB.Width - boxA.X); } if (aTop && aBottom) { m_yOverlap = (double)boxB.Height; } else if (!aTop && !aBottom) { m_yOverlap = (double)boxA.Height; } else if (aTop) { m_yOverlap = (double)(boxA.Y + boxA.Height - boxB.Y); } else { m_yOverlap = (double)(boxB.Y + boxB.Height - boxA.Y); } }
/// <summary> /// Non-uniform scaling of the list of points to a square. /// </summary> /// <param name="points">List of points to be scaled</param> /// <param name="size">Size of one edge of the square</param> /// <returns>List of new points that have been scaled</returns> private List <Point> scaleToSquare(List <Point> points, double size) { List <Point> newPoints = new List <Point>(points.Count); System.Drawing.RectangleF bBox = Compute.BoundingBox(points.ToArray()); for (int i = 0; i < points.Count; i++) { float x = points[i].X * (float)(size) / bBox.Width; float y = points[i].Y * (float)(size) / bBox.Height; newPoints.Add(new Point(x, y)); } return(newPoints); }
/// <summary> /// Constructor /// </summary> /// <param name="sketch"></param> /// <param name="extensionLengthsExtreme"></param> public IntersectionSketch(Sketch.Sketch sketch, Dictionary <Substroke, double> extensionLengthsExtreme) { m_Sketch = sketch; double avgArcLength = GetAvgArcLength(sketch); m_Strokes = new List <Substroke>(); m_Boxes = new Dictionary <Substroke, System.Drawing.RectangleF>(); m_Lines = new Dictionary <Substroke, List <Line> >(); foreach (Substroke s in m_Sketch.Substrokes) { if (!m_Strokes.Contains(s)) { m_Strokes.Add(s); } if (!m_Boxes.ContainsKey(s)) { m_Boxes.Add(s, Compute.BoundingBox(s.Points)); } if (!m_Lines.ContainsKey(s)) { double d = Math.Min(avgArcLength, (s.SpatialLength + avgArcLength) / 2); d *= Compute.THRESHOLD; List <Line> lines = Compute.getLines(s.PointsL); Line[] endLines = getEndLines(lines, d); lines.Add(endLines[1]); lines.Insert(0, endLines[0]); m_Lines.Add(s, lines); } } m_ExtensionLengthsExtreme = extensionLengthsExtreme; m_Stroke2Intersections = new Dictionary <Substroke, Dictionary <Substroke, Future <IntersectionPair> > >(); for (int i = 0; i < m_Sketch.Substrokes.Length; i++) { FindIntersections(m_Sketch.SubstrokesL, i); } }
/// <summary> /// Adds the given stroke to the intersection sketch /// </summary> /// <param name="stroke"></param> public void AddStroke(Substroke stroke) { if (m_Strokes.Contains(stroke)) { return; } if (m_Stroke2Intersections.ContainsKey(stroke)) { return; } if (m_Boxes.ContainsKey(stroke)) { return; } if (m_Lines.ContainsKey(stroke)) { return; } List <Line> lines = Compute.getLines(stroke.PointsL); Line[] endLines = null; endLines = getEndLines(lines, m_ExtensionLengthsExtreme[stroke]); lines.Insert(0, endLines[0]); lines.Add(endLines[1]); m_Lines.Add(stroke, lines); m_Boxes.Add(stroke, Compute.BoundingBox(lines)); m_Stroke2Intersections.Add(stroke, new Dictionary <Substroke, Future <IntersectionPair> >()); foreach (Substroke s in m_Strokes) { Future <IntersectionPair> pair = getPair(stroke, s); m_Stroke2Intersections[s].Add(stroke, pair); m_Stroke2Intersections[stroke].Add(s, pair); } m_Strokes.Add(stroke); }
/// <summary> /// Finds the features of a Substroke /// </summary> /// <param name="substroke">Substroke to find features for</param> public FeatureStroke(Sketch.Substroke substroke) { Point[] points = substroke.Points; _substroke = substroke; spatial = new Spatial(points); arcLength = new ArcLength(points); slope = new Slope(points); speed = new Speed(points); curvature = new Curvature(points, ArcLength.Profile, Slope.TanProfile); fit = new Fit(substroke); boundingBox = Compute.BoundingBox(substroke.Points); this.id = (System.Guid)substroke.Id; features = new Dictionary <string, Feature>(); featuresToUse = new Dictionary <string, bool>(); addAllFeatures(); if (UseThetas) { thetas = Compute.FindThetas(substroke.Points); //thetas = Compute.Normalize(thetas, Math.PI * 2.0); } else { thetas = new double[0]; } if (UseArcLength) { features.Add("Arc Length", new InkLength(arcLength.TotalLength)); } if (UseClosedPath) { features.Add("Part of a Closed Path", new PartOfClosedPath(false)); features.Add("Inside a Closed Path", new InsideClosedPath(false)); } }
private System.Drawing.RectangleF computeBoundingBox(Substroke substroke) { return(Compute.BoundingBox(m_Lines[substroke])); }