-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Update samples and add to main solution #157
Conversation
Codecov Report
@@ Coverage Diff @@
## master #157 +/- ##
==========================================
+ Coverage 69.87% 69.92% +0.05%
==========================================
Files 88 88
Lines 5135 5144 +9
Branches 1048 1052 +4
==========================================
+ Hits 3588 3597 +9
Misses 1337 1337
Partials 210 210
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally fine but looks like you have issue with the draw along path sample... looks like you have incorrectly changed the semantics.
{ | ||
WrappingWidth = path.Length, | ||
WrappingWidth = path.Bounds.Width, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't the same thing.... (if i'm reading this right this is drawing along a path)
Imagine this path was a circle, the length of the circle in this case would be its circumference, whereas the width would just be its diameter meaning the text would only get partly around the outside before wrapping and not once it closes in itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length isn’t a property anymore so how would I calculate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An approximation is a sum of distances between subsequent path.Flatten().Single().Points
. (I assume Flatten returns a single ISimplePath
for this, but I may be wrong.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without the limitation on single path...
static float GetLength(IPath path)
{
float dist = 0;
foreach (var s in path.Flatten())
{
var points = s.Points.Span;
if (points.Length < 2)
{
// only a point
continue;
}
for (var i = 1; i < points.Length; i++)
{
dist += Vector2.Distance(points[i - 1], points[i]);
}
if (s.IsClosed)
{
dist += Vector2.Distance(points[0], points[points.Length - 1]);
}
}
return dist;
}
we should/could probably add this this as an extension on IPath
, or re add it back to the IPath
interface.
definitely makes the sample you threw into slack a little less broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we had the implementations calculating the length analytically, this should be an extension method. I would name it .CalculateApproximateLength()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I recall there were issues calculating it as a property in ComplexPolygon. I’d rather avoid re-adding it to the interface and use an extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with ComputeLength()
to match the DirectX method that does the same thing.
https://docs.microsoft.com/en-us/windows/win32/direct2d/id2d1geometry-computelength
Co-authored-by: Anton Firszov <antonfir@gmail.com>
public class ComputeLength | ||
{ | ||
[Fact] | ||
public void CanComputeUnrolledLength() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a test that verifies the length calculates as expected for more complex paths too... i.e. any IPath
where the Flatten()
call returns multiple ISimplePath
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked for and couldn’t find one in the codebase from before IPath.Length
was removed to reuse. With nothing to verify against I’m just been guessing the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to need a little help here.
I used LottieSharp to calculate a polygon length since it gave me access to the original DX method and attempted to replicate a polygon to match another test one.
var p = new LottieSharp.Path();
p.MoveTo(15, 0);
p.LineTo(25, 0);
p.MoveTo(15, 30);
p.LineTo(25, 0);
p.Close();
using (var factory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded))
{
p.GetGeometry(factory).ComputeLength().Dump(); // 73.24555
}
Our test code.
[Fact]
public void CanComputeUnrolledLength()
{
var pb = new PathBuilder();
pb.AddLine(new Vector2(15, 0), new Vector2(25, 0))
.AddLine(new Vector2(15, 30), new Vector2(25, 30))
.CloseFigure();
IPath p = pb.Build();
Assert.Equal(73.24555, p.ComputeLength()); // 83.24555206298828
}
We seem to be calculating a value exactly 10 more than the DX. I couldn't figure out a way to convert their types to ours to verify the output.
Tbh though, I don't understand how either is getting that number. The path should be a rectangle of sides 10x30 which would make the length 80 shouldn't it?
SkiaSharp seems to give me junk. Not sure what I'm doing wrong there.
using var p = new SKPath();
p.MoveTo(15, 0);
p.LineTo(25, 0);
p.MoveTo(15, 30);
p.LineTo(25, 0);
p.Close();
var measure = new SKPathMeasure(p, false, 1);
measure.Length.Dump(); // 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel your overthinking this too much..... all you want is:
[Fact]
public void CanComputeUnrolledLengthComplexPath()
{
var polygon = new ComplexPolygon(
new RectangularPolygon(PointF.Empty, new PointF(100, 200)),
new RectangularPolygon(new PointF(1000, 1000), new PointF(1100, 1200)));
Assert.Equal(1200, polygon.ComputeLength());
}
this just ensures that Flatten()
returns multilple ISimplePath
s and that we sum the distances across all the ISimplePath
s rather than just the first or any other logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw your use of path builder isn't the same in your 2 samples. we don't have a move line equivalent option, the 2nd add line call adds a line joining the end of the first and the start of the 2nd and then the CloseFigure joins the start and the end, which explains the confusion in the length differences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I'm definitely overthinking things! 😄
We should probably add MoveTo
and LineTo
methods then shouldn't we (or have I missed an equivalent)?
I'm still intrigued by the result. I must be visualizing something badly because it seemed like a rectangle to me.
Co-authored-by: Anton Firszov <antonfir@gmail.com>
Co-authored-by: Anton Firszov <antonfir@gmail.com>
Prerequisites
Description
Updates the samples project to use the latest API and includes it in the solution so we don't forget about it in the future.