public OSLine(Vector2I I_start, Vector2I I_end, char I_color) : base(I_start, I_end) { ForeColor = I_color; Vector2I deltaV2I = I_end - I_start; List <OSDot> L_Result = new List <OSDot>(); if (deltaV2I.X == 0) // | { //L_TotalDots.AddRange(L_BackGroundDots.Range(0, deltaV2I.Y)); for (int yStep = I_start.Y, yMax = I_end.Y, xSwift = I_start.X; yStep < yMax; yStep++) { //L_TotalDots[yStep - yStart] = new OSDot(new Vector2I(xSwift, yStep), I_color); L_TotalDots.Add(new OSDot(new Vector2I(xSwift, yStep), ForeColor)); } } if (deltaV2I.Y == 0) // - { //L_TotalDots.AddRange(L_BackGroundDots.Range(0, deltaV2I.X)); for (int xStep = I_start.X, xMax = I_end.X, ySwift = I_start.Y; xStep < xMax; xStep++) { //L_TotalDots[xStep - xStart] = new OSDot(new Vector2I(xStep, ySwift), I_color); L_TotalDots.Add(new OSDot(new Vector2I(xStep, ySwift), ForeColor)); } } else { // \ float slope = (float)deltaV2I.Y / (float)deltaV2I.X; if (slope < 1) { //斜率小的按X遍历 //L_TotalDots.AddRange(L_BackGroundDots.Range(0, deltaV2I.X)); for (int xStep = 0, xMax = deltaV2I.X, xSwift = I_start.X, ySwift = I_start.Y; xStep < xMax; xStep++) { //L_TotalDots[xStep] = new OSDot(new Vector2I((int)(xStep * slope + xSwift), ySwift), I_color); L_TotalDots.Add(new OSDot(new Vector2I(xStep + xSwift, (int)((float)xStep * slope + ySwift)), ForeColor)); } } else { //斜率大的就按Y遍历吧 //L_TotalDots.AddRange(L_BackGroundDots.Range(0, deltaV2I.Y)); for (int yStep = 0, yMax = deltaV2I.Y, xSwift = I_start.X, ySwift = I_start.Y; yStep < yMax; yStep++) { //L_TotalDots[yStep] = new OSDot(new Vector2I(xSwift, (int)(yStep / slope + ySwift)), I_color); L_TotalDots.Add(new OSDot(new Vector2I((int)((float)yStep / slope + xSwift), yStep + ySwift), ForeColor)); } } } }
public OSRec(Vector2I I_start, Vector2I I_end, char I_color) : base(I_start, I_end) { //Fills int XLength = I_end.X - I_start.X; int YLength = I_end.Y - I_start.Y; //L_FillDots.AddRange(L_BackGroundDots.Range(0, XLength * YLength)); for (int X = I_start.X, xMax = I_end.X; X < xMax; X++) { for (int Y = I_start.Y, yMax = I_end.Y; Y < yMax; Y++) { L_TotalDots.Add(new OSDot(new Vector2I(X, Y), ForeColor)); } } }