static void AssignPointEdgeInvolvement(EdgeLine edge) { if (!edge.IsOutside) { return; } switch (edge.SlopKind) { case LineSlopeKind.Horizontal: { //horiontal edge //must check if this is upper horizontal //or lower horizontal //we know after do bone analysis //------------ //both p and q of this edge is part of horizontal edge var p = edge.p.userData as GlyphPoint2D; if (p != null) { //TODO: review here p.isPartOfHorizontalEdge = true; p.isUpperSide = edge.IsUpper; p.horizontalEdge = edge; } var q = edge.q.userData as GlyphPoint2D; if (q != null) { //TODO: review here q.isPartOfHorizontalEdge = true; q.horizontalEdge = edge; q.isUpperSide = edge.IsUpper; } } break; case LineSlopeKind.Vertical: { //both p and q of this edge is part of vertical edge var p = edge.p.userData as GlyphPoint2D; if (p != null) { //TODO: review here p.AddVerticalEdge(edge); } var q = edge.q.userData as GlyphPoint2D; if (q != null) { //TODO: review here q.AddVerticalEdge(edge); } } break; } }
public GlyphTriangle(DelaunayTriangle tri) { this._tri = tri; TriangulationPoint p0 = _tri.P0; TriangulationPoint p1 = _tri.P1; TriangulationPoint p2 = _tri.P2; e0 = new EdgeLine(p0, p1); e1 = new EdgeLine(p1, p2); e2 = new EdgeLine(p2, p0); tri.Centroid2(out centroidX, out centroidY); e0.IsOutside = tri.EdgeIsConstrained(tri.FindEdgeIndex(tri.P0, tri.P1)); e1.IsOutside = tri.EdgeIsConstrained(tri.FindEdgeIndex(tri.P1, tri.P2)); e2.IsOutside = tri.EdgeIsConstrained(tri.FindEdgeIndex(tri.P2, tri.P0)); }
static bool FindMatchingOuterSide(EdgeLine compareEdge, GlyphTriangle another, out EdgeLine result, out int edgeIndex) { //compare by radian of edge line double compareSlope = Math.Abs(compareEdge.SlopAngle); double diff0 = double.MaxValue; double diff1 = double.MaxValue; double diff2 = double.MaxValue; diff0 = Math.Abs(Math.Abs(another.e0.SlopAngle) - compareSlope); diff1 = Math.Abs(Math.Abs(another.e1.SlopAngle) - compareSlope); diff2 = Math.Abs(Math.Abs(another.e2.SlopAngle) - compareSlope); //find min int minDiffSide = FindMinIndex(diff0, diff1, diff2); if (minDiffSide > -1) { edgeIndex = minDiffSide; switch (minDiffSide) { default: throw new NotSupportedException(); case 0: result = another.e0; break; case 1: result = another.e1; break; case 2: result = another.e2; break; } return(true); } else { edgeIndex = -1; result = null; return(false); } }
public void AddVerticalEdge(EdgeLine v_edge) { //associated if (!this.IsPartOfVerticalEdge) { this.IsPartOfVerticalEdge = true; } if (!this.IsLeftSide) { this.IsLeftSide = v_edge.IsLeftSide; } if (_edges == null) { _edges = new List <EdgeLine>(); } _edges.Add(v_edge); }
public void AddMatchingOutsideEdge(EdgeLine edgeLine) { #if DEBUG if (edgeLine == this) { throw new NotSupportedException(); } #endif if (matchingEdges == null) { matchingEdges = new Dictionary <EdgeLine, bool>(); } if (!matchingEdges.ContainsKey(edgeLine)) { matchingEdges.Add(edgeLine, true); } #if DEBUG if (matchingEdges.Count > 1) { } #endif }
static void MarkMatchingEdge(EdgeLine targetEdge, GlyphTriangle q) { EdgeLine matchingEdgeLine; int matchingEdgeSideNo; if (FindMatchingOuterSide(targetEdge, q, out matchingEdgeLine, out matchingEdgeSideNo)) { //assign matching edge line //mid point of each edge //p-triangle's edge midX,midY double pe_midX, pe_midY; CalculateMidPoint(targetEdge, out pe_midX, out pe_midY); //q-triangle's edge midX,midY double qe_midX, qe_midY; CalculateMidPoint(matchingEdgeLine, out qe_midX, out qe_midY); if (targetEdge.SlopKind == LineSlopeKind.Vertical) { //TODO: review same side edge (Fan shape) if (pe_midX < qe_midX) { targetEdge.IsLeftSide = true; if (matchingEdgeLine.IsOutside && matchingEdgeLine.SlopKind == LineSlopeKind.Vertical) { targetEdge.AddMatchingOutsideEdge(matchingEdgeLine); } } else { //matchingEdgeLine.IsLeftSide = true; if (matchingEdgeLine.IsOutside && matchingEdgeLine.SlopKind == LineSlopeKind.Vertical) { targetEdge.AddMatchingOutsideEdge(matchingEdgeLine); } } } else if (targetEdge.SlopKind == LineSlopeKind.Horizontal) { //TODO: review same side edge (Fan shape) if (pe_midY > qe_midY) { //p side is upper , q side is lower if (targetEdge.SlopKind == LineSlopeKind.Horizontal) { targetEdge.IsUpper = true; if (matchingEdgeLine.IsOutside && matchingEdgeLine.SlopKind == LineSlopeKind.Horizontal) { targetEdge.AddMatchingOutsideEdge(matchingEdgeLine); } } } else { if (matchingEdgeLine.SlopKind == LineSlopeKind.Horizontal) { // matchingEdgeLine.IsUpper = true; if (matchingEdgeLine.IsOutside && matchingEdgeLine.SlopKind == LineSlopeKind.Horizontal) { targetEdge.AddMatchingOutsideEdge(matchingEdgeLine); } } } } } }
static void CalculateMidPoint(EdgeLine e, out double midX, out double midY) { midX = (e.x0 + e.x1) / 2; midY = (e.y0 + e.y1) / 2; }
static void CreateFitShape(IGlyphTranslator tx, GlyphContour contour, float pixelScale, bool x_axis, bool y_axis, bool useHalfPixel) { List <GlyphPoint2D> mergePoints = contour.mergedPoints; int j = mergePoints.Count; //merge 0 = start double prev_px = 0; double prev_py = 0; double p_x = 0; double p_y = 0; double first_px = 0; double first_py = 0; { GlyphPoint2D p = mergePoints[0]; p_x = p.x * pixelScale; p_y = p.y * pixelScale; if (y_axis && p.isPartOfHorizontalEdge && p.isUpperSide && p_y > 3) { //vertical fitting //fit p_y to grid p_y = RoundToNearestVerticalSide((float)p_y, useHalfPixel); } if (x_axis && p.IsPartOfVerticalEdge && p.IsLeftSide) { float new_x = RoundToNearestHorizontalSide((float)p_x); //adjust right-side vertical edge EdgeLine rightside = p.GetMatchingVerticalEdge(); if (rightside != null) { } p_x = new_x; } tx.MoveTo((float)p_x, (float)p_y); //------------- first_px = prev_px = p_x; first_py = prev_py = p_y; } for (int i = 1; i < j; ++i) { //all merge point is polygon point GlyphPoint2D p = mergePoints[i]; p_x = p.x * pixelScale; p_y = p.y * pixelScale; if (y_axis && p.isPartOfHorizontalEdge && p.isUpperSide && p_y > 3) { //vertical fitting //fit p_y to grid p_y = RoundToNearestVerticalSide((float)p_y, useHalfPixel); } if (x_axis && p.IsPartOfVerticalEdge && p.IsLeftSide) { //horizontal fitting //fix p_x to grid float new_x = RoundToNearestHorizontalSide((float)p_x); ////adjust right-side vertical edge //PixelFarm.Agg.Typography.EdgeLine rightside = p.GetMatchingVerticalEdge(); //if (rightside != null && !rightside.IsLeftSide && rightside.IsOutside) //{ // var rightSideP = rightside.p.userData as GlyphPoint2D; // var rightSideQ = rightside.q.userData as GlyphPoint2D; // //find move diff // float movediff = (float)p_x - new_x; // //adjust right side edge // rightSideP.x = rightSideP.x + movediff; // rightSideQ.x = rightSideQ.x + movediff; //} p_x = new_x; } // tx.LineTo((float)p_x, (float)p_y); // prev_px = p_x; prev_py = p_y; } tx.LineTo((float)first_px, (float)first_py); }