/// <summary>Renders a straight line from the previous point to this one.</summary> public override void RenderLine(CanvasContext context){ // Grab the raw drawing data: DynamicTexture data=context.ImageData; // Invert y: int endY=data.Height-(int)Y; int startY=data.Height-(int)Previous.Y; // Grab X: int endX=(int)X; int startX=(int)Previous.X; data.DrawLine(startX,startY,endX,endY,context.StrokeColour); }
/// <summary>Renders an arc from the previous point to this one.</summary> public override void RenderLine(CanvasContext context){ // Grab the raw drawing data: DynamicTexture data=context.ImageData; // Time to go polar! // We're going to rotate around the pole drawing one pixel at a time. // For the best accuracy, we first need to find out how much to rotate through per pixel. if(Length==0f){ // Nothing to draw anyway. return; } // How much must we rotate through overall? float angleToRotateThrough=EndAngle-StartAngle; // So arc length is how many pixels long the arc is. // Thus to step that many times, our delta angle is.. float deltaAngle=angleToRotateThrough/Length; // The current angle: float currentAngle=StartAngle; // The number of pixels: int pixelCount=(int)Mathf.Ceil(Length); if(pixelCount<0){ // Going anti-clockwise. Invert deltaAngle and the pixel count: deltaAngle=-deltaAngle; pixelCount=-pixelCount; } // Step pixel count times: for(int i=0;i<pixelCount;i++){ // Map from polar angle to coords: float x=Radius * (float) Math.Cos(currentAngle); float y=Radius * (float) Math.Sin(currentAngle); // Draw the pixel: data.DrawPixel((int)(CircleCenterX+x),data.Height-(int)(CircleCenterY+y),context.StrokeColour); // Rotate the angle: currentAngle+=deltaAngle; } }
/// <summary>Used internally. Renders the line between this point and the next one, if there is one.</summary> /// <param name="data">The image to draw to.</param> public virtual void RenderLine(CanvasContext context){}