public override void ExtrudeAndSample(VectorPath path, float extrudeBy, PointReceiverStepped sampler) { // Cache radius: float radius = Radius; // Extrude: Radius += extrudeBy; // Clamp: if (Radius < 0f) { Radius = 0f; } // Rebound: RecalculateBounds(path); if (sampler.IncludeFirstNode) { sampler.AddPoint(Previous.X, Previous.Y, 0f); } // Sample now: ComputeLinePoints(sampler); // Restore: Radius = radius; }
public override void ComputeLinePoints(PointReceiverStepped output) { int pixels = (int)(Length / output.SampleDistance); if (pixels <= 0) { pixels = 1; } // Run along the line as a 0-1 progression value. float deltaProgress = 1f / (float)pixels; float c = deltaProgress; // Step pixel count times: for (int i = 0; i < pixels; i++) { // From http://www.w3.org/TR/SVG/implnote.html#ArcParameterizationAlternatives float angle = StartAngle + (SweepAngle * c); float ellipseComponentX = RadiusX * (float)Math.Cos(angle); float ellipseComponentY = RadiusY * (float)Math.Sin(angle); float x = CosXAxis * ellipseComponentX - SinXAxis * ellipseComponentY + CenterX; float y = SinXAxis * ellipseComponentX + CosXAxis * ellipseComponentY + CenterY; output.AddPoint(x, y, c); c += deltaProgress; } }
public override void ExtrudeAndSample(VectorPath path, float extrudeBy, PointReceiverStepped sampler) { // First, cache all the points: float prevX = Previous.X; float prevY = Previous.Y; float c1x = Control1X; float c1y = Control1Y; float c2x = Control2X; float c2y = Control2Y; float x = X; float y = Y; // Get the normals and extrude along them. float normalX; float normalY; // First point: StartNormal(out normalX, out normalY); Previous.X += normalX * extrudeBy; Previous.Y += normalY * extrudeBy; // First control: NormalAt(0.3333f, out normalX, out normalY); Control1X += normalX * extrudeBy; Control1Y += normalY * extrudeBy; // Second control: NormalAt(0.6666f, out normalX, out normalY); Control2X += normalX * extrudeBy; Control2Y += normalY * extrudeBy; // Last point: EndNormal(out normalX, out normalY); X += normalX * extrudeBy; Y += normalY * extrudeBy; // Rebound: RecalculateBounds(path); if (sampler.IncludeFirstNode) { sampler.AddPoint(Previous.X, Previous.Y, 0f); } // Sample now: ComputeLinePoints(sampler); // Restore all the points: Previous.X = prevX; Previous.Y = prevY; Control1X = c1x; Control1Y = c1y; Control2X = c2x; Control2Y = c2y; X = x; Y = y; }
public override void ComputeLinePoints(PointReceiverStepped output) { // Divide length by the amount we advance per pixel to get the number of pixels on this line: int pixels = (int)(Length / output.SampleDistance); if (pixels <= 0) { pixels = 1; } // Run along the line as a 0-1 progression value. float deltaProgress = 1f / (float)pixels; // From but not including previous: float t = deltaProgress; float x = X; float y = Y; float previousX = Previous.X; float previousY = Previous.Y; float control1X3 = Control1X * 3f; float control2X3 = Control2X * 3f; float control1Y3 = Control1Y * 3f; float control2Y3 = Control2Y * 3f; float previousX3 = previousX * 3f; float previousY3 = previousY * 3f; // For each of the pixels: for (int i = 0; i < pixels; i++) { float tSquare = t * t; float tCube = tSquare * t; float pointX = previousX + (-previousX3 + t * (previousX3 - previousX * t)) * t + (control1X3 + t * (-2f * control1X3 + control1X3 * t)) * t + (control2X3 - control2X3 * t) * tSquare + x * tCube; float pointY = previousY + (-previousY3 + t * (previousY3 - previousY * t)) * t + (control1Y3 + t * (-2f * control1Y3 + control1Y3 * t)) * t + (control2Y3 - control2Y3 * t) * tSquare + y * tCube; // Add it: output.AddPoint(pointX, pointY, t); // Move progress: t += deltaProgress; } }
public override void ComputeLinePoints(PointReceiverStepped output) { float radius = Radius; // How much must we rotate through overall? float angleToRotateThrough = EndAngle - StartAngle; // The number of pixels: int pixelCount = (int)Math.Ceiling(Length / output.SampleDistance); if (pixelCount < 0) { // Going anti-clockwise. Invert deltaAngle and the pixel count: pixelCount = -pixelCount; } // So arc length is how many pixels long the arc is. // Thus to step that many times, our delta angle is.. float deltaAngle = angleToRotateThrough / (float)pixelCount; // The current angle: float currentAngle = StartAngle; // From but not including previous: float deltaC = 1f / (float)pixelCount; float c = deltaC; // 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); x += CircleCenterX; y += CircleCenterY; output.AddPoint(x, y, c); // Rotate the angle: currentAngle += deltaAngle; c += deltaC; } }
public override void ComputeLinePoints(PointReceiverStepped output) { // Get previous: float x = X; float y = Y; float previousX = Previous.X; float previousY = Previous.Y; float control1X2 = Control1X * 2f; float control1Y2 = Control1Y * 2f; // Divide length by the amount we advance per pixel to get the number of pixels on this line: int pixels = (int)(Length / output.SampleDistance); if (pixels <= 0) { pixels = 1; } // Run along the line as a 0-1 progression value. float deltaProgress = 1f / (float)pixels; // From but not including previous: float t = deltaProgress; float invert = (1f - t); // For each of the pixels: for (int i = 0; i < pixels; i++) { float tSquare = t * t; float controlFactor = t * invert; float invertSquare = invert * invert; // Figure out the point: float pointX = invertSquare * previousX + controlFactor * control1X2 + tSquare * x; float pointY = invertSquare * previousY + controlFactor * control1Y2 + tSquare * y; // Add it: output.AddPoint(pointX, pointY, t); // Move progress: t += deltaProgress; invert -= deltaProgress; } }
public override void ComputeLinePoints(PointReceiverStepped output) { // Get previous: float previousX = Previous.X; float previousY = Previous.Y; // Get deltas: float dx = X - previousX; float dy = Y - previousY; // Divide length by the amount we advance per pixel to get the number of pixels on this line: int pixels = (int)(Length / output.SampleDistance); if (pixels <= 0) { pixels = 1; } // Run along the line as a 0-1 progression value. float deltaProgress = 1f / (float)pixels; // From but not including previous: float progressX = deltaProgress * dx; float progressY = deltaProgress * dy; // Figure out the first point: float pointX = previousX + progressX; float pointY = previousY + progressY; float t = deltaProgress; // For each of the pixels: for (int i = 0; i < pixels; i++) { // Add it: output.AddPoint(pointX, pointY, t); // Move: pointX += progressX; pointY += progressY; t += deltaProgress; } }
public override void ExtrudeAndSample(VectorPath path, float extrudeBy, PointReceiverStepped sampler) { // First, cache all the points: float prevX = Previous.X; float prevY = Previous.Y; float x = X; float y = Y; // Get the normal and extrude along it. float normalX; float normalY; StartNormal(out normalX, out normalY); Previous.X += normalX * extrudeBy; Previous.Y += normalY * extrudeBy; X += normalX * extrudeBy; Y += normalY * extrudeBy; // Rebound: RecalculateBounds(path); if (sampler.IncludeFirstNode) { sampler.AddPoint(Previous.X, Previous.Y, 0f); } // Sample now: ComputeLinePoints(sampler); // Restore all the points: Previous.X = prevX; Previous.Y = prevY; X = x; Y = y; }