//---------------------------------------------fix_degenerate_bisectrix_end public static void fix_degenerate_bisectrix_end(LineParameters lp, ref int x, ref int y) { int d = Basics.Round(((double)(x - lp.x2) * (double)(lp.y2 - lp.y1) - (double)(y - lp.y2) * (double)(lp.x2 - lp.x1)) / lp.len); if (d < line_subpixel_scale / 2) { x = lp.x2 + (lp.y2 - lp.y1); y = lp.y2 - (lp.x2 - lp.x1); } }
//--------------------------------------------------------------------- public void Divide(LineParameters lp1, LineParameters lp2) { int xmid = (x1 + x2) >> 1; int ymid = (y1 + y2) >> 1; int len2 = len >> 1; lp1 = this; // it is a struct so this is a copy lp2 = this; // it is a struct so this is a copy lp1.x2 = xmid; lp1.y2 = ymid; lp1.len = len2; lp1.dx = Math.Abs(lp1.x2 - lp1.x1); lp1.dy = Math.Abs(lp1.y2 - lp1.y1); lp2.x1 = xmid; lp2.y1 = ymid; lp2.len = len2; lp2.dx = Math.Abs(lp2.x2 - lp2.x1); lp2.dy = Math.Abs(lp2.y2 - lp2.y1); }
//--------------------------------------------------------------------- public bool SameOrthogonalQuadrant(LineParameters lp) { return(s_orthogonal_quadrant[octant] == s_orthogonal_quadrant[lp.octant]); }
//-------------------------------------------fix_degenerate_bisectrix_start public static void fix_degenerate_bisectrix_start(LineParameters lp, ref int x, ref int y) { int d = Basics.Round(((double)(x - lp.x2) * (double)(lp.y2 - lp.y1) - (double)(y - lp.y2) * (double)(lp.x2 - lp.x1)) / lp.len); if (d < line_subpixel_scale / 2) { x = lp.x1 + (lp.y2 - lp.y1); y = lp.y1 - (lp.x2 - lp.x1); } }
public const int line_subpixel_shift = 8; //----line_subpixel_shift #endregion Fields #region Methods //------------------------------------------------------------------------- public static void bisectrix(LineParameters l1, LineParameters l2, out int x, out int y) { double k = (double)(l2.len) / (double)(l1.len); double tx = l2.x2 - (l2.x1 - l1.x1) * k; double ty = l2.y2 - (l2.y1 - l1.y1) * k; //All bisectrices must be on the right of the Line //If the next point is on the left (l1 => l2.2) //then the bisectix should be rotated by 180 degrees. if ((double)(l2.x2 - l2.x1) * (double)(l2.y1 - l1.y1) < (double)(l2.y2 - l2.y1) * (double)(l2.x1 - l1.x1) + 100.0) { tx -= (tx - l2.x1) * 2.0; ty -= (ty - l2.y1) * 2.0; } // Check if the bisectrix is too short double dx = tx - l2.x1; double dy = ty - l2.y1; if ((int)Math.Sqrt(dx * dx + dy * dy) < line_subpixel_scale) { x = (l2.x1 + l2.x1 + (l2.y1 - l1.y1) + (l2.y2 - l2.y1)) >> 1; y = (l2.y1 + l2.y1 - (l2.x1 - l1.x1) - (l2.x2 - l2.x1)) >> 1; return; } x = Basics.Round(tx); y = Basics.Round(ty); }
//--------------------------------------------------------------------- public bool SameOrthogonalQuadrant(LineParameters lp) { return s_orthogonal_quadrant[octant] == s_orthogonal_quadrant[lp.octant]; }
//--------------------------------------------------------------------- public bool SameDiagonalQuadrant(LineParameters lp) { return s_diagonal_quadrant[octant] == s_diagonal_quadrant[lp.octant]; }