WPF Answer
In WPF you can just use Geometry.Combine to combine the stroke geometries, then call GetArea on the combined geometry to get the total area covered.
Silverlight Answer
In Silverlight you don't have Geomerty.Combine or Geometry.GetArea, and you also don't have RenderTargetBitmap. So in Silverlight I think you have to do the calculations yourself.
Here are the setup steps:
- Convert the geometries to cubic bezier curves (approximate arcs, all else are exact)
- Split all curves at their x minima and x maxima
- Rearrange coordinates so each curve goes from low x to high x
- Sort by x then y of first coordinate
- Start at minimum x coordinate with no active curve segments
Here is the main loop:
- Add any bezier curves that start at the current x coordinate to the active list
- Remove any bezier curves that end at the current x coordinate from the active list
- Compute intersections of active bezier curves. Find next x coordinate of such intersection.
- Let "end x" be earliest of next line intersection and next start or stop coordinate of a bezier curve
- Compute area from current x to "end x" then set current to end
- Repeat until "end x" reaches macimum x coordinate of any curve
Here is the inner loop that computes the area:
- Go through active curves in increasing y.
- Every time a curve is passed flip the "inside" bit for the original geometry for that curve.
- Every time y changes any "inside" bit is set, compute the area between the previous bezier curve and the current one and add it to the grand total area
That's it.
More details on Silverlight answer
Formulas to convert segments of a PathGeometry into a cubic bezier approximation:
- BezierSegment: Cubic control points are P0, P1, P2, P3 (no change)
- LineSegment: Cubic control points are P0, P0, P1, P1
- QuadraticBezierSegment: Cubic control points are P0, (P0+2P1)/3, (2P1+P2)/3, P2
- ArcSegment: Divide into octants and for each, compute unit tangent vectors T0, T1 at start & end pointing toward arc, generate control points (approximation) of P0, P0 + T0 * 4/3*(Sqrt(2)-1)*R, P1 + T1 * 4/3(Sqrt(2)-1)*R, P1, then modify with size and RotationAngle
- Poly...Segment: Break into individual segments, then use above formulas on each
Computing intersections of active Bezier curves:
- Since the curves have already been split at their minima / maxima, each is a smooth, continuous function of x, you can use these techniques to compute their intersection
- It can save some computation if you check y minima/maxima to see if there is any possible overlap before actually computing the intersection