-
Notifications
You must be signed in to change notification settings - Fork 483
#482 - Masks are now rendered #825
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
7cab3a1
70fc451
15e5f6e
785983d
746695d
e924082
b45403c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Svg.ExtensionMethods | ||
{ | ||
internal static class PointFExtensions | ||
{ | ||
internal static RectangleF GetBounds(this IEnumerable<PointF> points) | ||
{ | ||
var minX = points.Min(point => point.X); | ||
var maxX = points.Max(point => point.X); | ||
var minY = points.Min(point => point.Y); | ||
var maxY = points.Max(point => point.Y); | ||
|
||
return new RectangleF(minX, minY, maxX - minX, maxY - minY); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Drawing.Drawing2D; | ||
using System.Text; | ||
|
||
namespace Svg.ExtensionMethods | ||
{ | ||
internal static class RectangleFExtensions | ||
{ | ||
internal static Rectangle Round(this RectangleF rectangle) | ||
{ | ||
return new Rectangle((int)Math.Round(rectangle.X), (int)Math.Round(rectangle.Y), (int)Math.Round(rectangle.Width), (int)Math.Round(rectangle.Height)); | ||
} | ||
|
||
internal static RectangleF GetIntersection(this RectangleF rectangle, RectangleF anotherRectangle) | ||
{ | ||
var x1 = Math.Max(rectangle.X, anotherRectangle.X); | ||
var x2 = Math.Min(rectangle.X + rectangle.Width, anotherRectangle.X + anotherRectangle.Width); | ||
|
||
var y1 = Math.Max(rectangle.Y, anotherRectangle.Y); | ||
var y2 = Math.Min(rectangle.Y + rectangle.Height, anotherRectangle.Y + anotherRectangle.Height); | ||
|
||
var width = x2 - x1; | ||
var height = y2 - y1; | ||
|
||
if (width < 0) | ||
{ | ||
width = 0; | ||
} | ||
|
||
if (height < 0) | ||
{ | ||
height = 0; | ||
} | ||
|
||
return new RectangleF(x1, y1, width, height); | ||
} | ||
|
||
internal static RectangleF GetIntersection(this RectangleF rectangle, SizeF size) | ||
{ | ||
return GetIntersection(rectangle, new RectangleF(new PointF(0, 0), size)); | ||
} | ||
|
||
internal static PointF[] GetPoints(this RectangleF rectangle) | ||
{ | ||
return new[] | ||
{ | ||
rectangle.Location, | ||
rectangle.Location + rectangle.Size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here should consider five points like this, If there are only two points, there will have issue with the bounds when the transform contains rotation return new[]
{
rectangle.Location,
rectangle.Location + rectangle.Size,
new PointF(rectangle.X,rectangle.Y+rectangle.Height),
new PointF(rectangle.X+rectangle.Width,rectangle.Y)
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can verify this by this transform : "matrix(0.51 0.51 -0.51 0.51 776.90 96.03)" |
||
}; | ||
} | ||
|
||
internal static RectangleF Transform(this RectangleF rectangle, Matrix matrix) | ||
{ | ||
var points = GetPoints(rectangle); | ||
matrix.TransformPoints(points); | ||
return points.GetBounds(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,62 @@ Many performance improvements by using SourceGenerators instad of reflection. | |
<PropertyGroup Condition="'$(TargetFramework)' != 'net452'"> | ||
<DefineConstants>$(DefineConstants);USE_SOURCE_GENERATORS</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
|
||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net5.0|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp2.1|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp2.1|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net452|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.1|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net461|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp3.1|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net5.0|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net461|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net452|AnyCPU'"> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' != 'net452'"> | ||
<ProjectReference Include="..\Generators\Svg.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ public void RenderTestFileFromIssue482() | |
|
||
ImagesAreEqual(renderedDocument, expectedImage, 1, out equalPercentage, out difference); | ||
|
||
Assert.Greater(equalPercentage, 98); | ||
Assert.Greater(equalPercentage, 99); | ||
} | ||
|
||
[Test] | ||
|
@@ -40,7 +40,7 @@ public void RenderVariousElementsDefaultSize() | |
|
||
ImagesAreEqual(renderedDocument, expectedImage, 1, out equalPercentage, out difference); | ||
|
||
Assert.Greater(equalPercentage, 98); | ||
Assert.Greater(equalPercentage, 99); | ||
} | ||
|
||
[Test] | ||
|
@@ -54,9 +54,26 @@ public void RenderVariousElementsUpscaled() | |
float equalPercentage; | ||
Bitmap difference; | ||
|
||
ImagesAreEqual(renderedDocument, expectedImage, 1, out equalPercentage, out difference); | ||
var areImagesEqual = ImagesAreEqual(renderedDocument, expectedImage, 1, out equalPercentage, out difference); | ||
|
||
Assert.Greater(equalPercentage, 99); | ||
} | ||
|
||
[Test] | ||
public void RenderPcb() | ||
{ | ||
var document = OpenSvg(GetXMLDocFromResource(GetFullResourceString("Issue482_MasksNotRendered.PCB.svg"))); | ||
|
||
var renderedDocument = document.Draw(1440, 2560); | ||
|
||
var expectedImage = GetBitmapFromResource("Issue482_MasksNotRendered.PCB.png"); | ||
|
||
float equalPercentage; | ||
Bitmap difference; | ||
|
||
var areImagesEqual = ImagesAreEqual(renderedDocument, expectedImage, 1, out equalPercentage, out difference); | ||
|
||
Assert.Greater(equalPercentage, 98); | ||
Assert.Greater(equalPercentage, 99); | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add CRLF. |
Uh oh!
There was an error while loading. Please reload this page.