Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup cloning as per review #202

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/Consolonia.Core/Drawing/StreamGeometryImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ internal class StreamGeometryImpl : IStreamGeometryImpl
{
private readonly List<Rectangle> _fills;
private readonly List<Line> _strokes;
private Rect _bounds;

public StreamGeometryImpl()
{
Expand All @@ -25,23 +24,25 @@ public StreamGeometryImpl()
public IReadOnlyList<Rectangle> Fills => _fills;
// private SKPath _path;

public Rect Bounds => _bounds;
public Rect Bounds { get; private set; }

public double ContourLength => _strokes.Sum(l => l.ContourLength);


public IStreamGeometryImpl Clone()
{
var clone = new StreamGeometryImpl();
foreach (Line line in _strokes) clone._strokes.Add(line);
foreach (Rectangle rect in _fills) clone._fills.Add(rect);
clone._bounds = _bounds;
return clone;
var cloneGeometry = new StreamGeometryImpl();
foreach (Line cloneLine in _strokes.Select(l => new Line(l.PStart, l.PEnd, this, l.Transform)))
cloneGeometry._strokes.Add(cloneLine);
foreach (Rectangle cloneRect in _fills.Select(r => new Rectangle(r.Rect, r, r.Transform)))
cloneGeometry._fills.Add(cloneRect);
cloneGeometry.Bounds = Bounds;
return cloneGeometry;
}

public bool FillContains(Point point)
{
return _bounds.Contains(point);
return _fills.Any(rect => rect.FillContains(point));
}

public Rect GetRenderBounds(IPen pen)
Expand Down Expand Up @@ -177,11 +178,8 @@ public void LineTo(Point point)
public void EndFigure(bool isClosed)
{
Rect bound = _geometryImpl._strokes.Aggregate(new Rect(), (rect, line) => rect.Union(line.Bounds));
_geometryImpl._bounds = bound;
if (_isFilled)
{
// _geometryImpl._fills.Add(new Rectangle(bound));
}
_geometryImpl.Bounds = bound;
if (_isFilled) _geometryImpl._fills.Add(new Rectangle(bound));
}

/// <inheritdoc />
Expand Down
Loading