Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
3f1da2c7
Commit
3f1da2c7
authored
Feb 25, 2017
by
mrbean-bremen
Browse files
Added bounds tests for some elements
parent
b6abd3cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgPathBasedElement.cs
View file @
3f1da2c7
...
...
@@ -12,7 +12,7 @@ namespace Svg
get
{
var
path
=
this
.
Path
(
null
);
if
(
Transforms
!=
null
)
if
(
Transforms
!=
null
&&
Transforms
.
Count
>
0
)
{
path
=
(
GraphicsPath
)
path
.
Clone
();
path
.
Transform
(
Transforms
.
GetMatrix
());
...
...
Tests/Svg.UnitTests/BoundsTests.cs
0 → 100644
View file @
3f1da2c7
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System.Drawing
;
namespace
Svg.UnitTests
{
/// <summary>
/// Test class to test bounds for elements without vs. with transformations
/// (see issue 281). Only some basic elements are tested - this should be sufficient
/// to verify the functionality for all path-based elements.
/// </summary>
[
TestClass
]
public
class
BoundsTests
:
SvgTestHelper
{
private
const
string
BoundsTestSvg
=
"Issue281_Bounds.BoundsTest.svg"
;
private
static
SvgDocument
testDocument
;
[
TestMethod
]
public
void
TestLineBounds
()
{
// x1="10" x2="30" y1="20" y2="40", default line thickness is 1
AssertEqualBounds
(
"line"
,
9.5f
,
19.5f
,
21
,
21
);
// additional translation(5, 5)
AssertEqualBounds
(
"line-xlate"
,
14.5f
,
24.5f
,
21
,
21
);
// additional rotation(180) and translation(-50, 0)
AssertEqualBounds
(
"line-xform"
,
19.5f
,
-
40.5f
,
21
,
21
);
}
[
TestMethod
]
public
void
TestRectangleBounds
()
{
// x="10" y="30" width="10" height="20"
AssertEqualBounds
(
"rect"
,
9.5f
,
29.5f
,
10.5f
,
20.5f
);
// additional translation(10, 10)
AssertEqualBounds
(
"rect-xlate"
,
19.5f
,
39.5f
,
10.5f
,
20.5f
);
// additional rotation(90)
AssertEqualBounds
(
"rect-rot"
,
-
50
,
9.5f
,
20.5f
,
10.5f
);
}
[
TestMethod
]
public
void
TestGroupBounds
()
{
// all lines from TestLineBounds()
AssertEqualBounds
(
"lines"
,
9.5f
,
29.5f
,
10.5f
,
20.5f
);
// all reactangles from TestRectangleBounds()
AssertEqualBounds
(
"rects"
,
19.5f
,
39.5f
,
10.5f
,
20.5f
);
}
private
void
AssertEqualBounds
(
string
elementId
,
float
x
,
float
y
,
float
width
,
float
height
)
{
const
float
Epsilon
=
0.01f
;
var
element
=
GetElement
(
elementId
);
var
elementBounds
=
element
.
Bounds
;
Assert
.
AreEqual
(
x
,
elementBounds
.
X
,
Epsilon
);
Assert
.
AreEqual
(
y
,
elementBounds
.
Y
,
Epsilon
);
Assert
.
AreEqual
(
width
,
elementBounds
.
Width
,
Epsilon
);
Assert
.
AreEqual
(
height
,
elementBounds
.
Height
,
Epsilon
);
}
private
SvgVisualElement
GetElement
(
string
elementId
)
{
if
(
testDocument
==
null
)
{
testDocument
=
OpenSvg
(
GetXMLDocFromResource
(
GetFullResourceString
(
BoundsTestSvg
)));
}
return
testDocument
.
GetElementById
<
SvgVisualElement
>(
elementId
);
}
}
}
Tests/Svg.UnitTests/Resources/Issue281_Bounds/BoundsTest.svg
0 → 100644
View file @
3f1da2c7
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns=
"http://www.w3.org/2000/svg"
version=
"1.1"
x=
"0px"
y=
"0px"
viewBox=
"0 0 100 100"
enable-background=
"new 0 0 34.06945 33.11168"
xml:space=
"preserve"
id=
"svg2"
>
<defs
id=
"defs30"
/>
<g
id=
"lines"
>
<line
id=
"line"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
/>
<line
id=
"line-xlate"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"translate(5, 5)"
/>
<line
id=
"line-xform"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"rotate(180), translate(-50, 0)"
/>
</g>
<g
id=
"rects"
>
<rect
id=
"rect"
x=
"10"
y=
"30"
width=
"10"
height=
"20"
/>
<rect
id=
"rect-xlate"
x=
"10"
y=
"30"
width=
"10"
height=
"20"
transform=
"translate(10, 10)"
/>
<rect
id=
"rect-rot"
x=
"10"
y=
"30"
width=
"10"
height=
"20"
transform=
"rotate(90)"
/>
</g>
</svg>
Tests/Svg.UnitTests/Svg.UnitTests.csproj
View file @
3f1da2c7
...
...
@@ -54,6 +54,7 @@
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"BoundsTests.cs"
/>
<Compile
Include=
"CssQueryTest.cs"
/>
<Compile
Include=
"LargeEmbeddedImageTest.cs"
/>
<Compile
Include=
"MarkerEndTest.cs"
/>
...
...
@@ -95,6 +96,9 @@
<ItemGroup>
<EmbeddedResource
Include=
"Resources\Issue_TextElement\Text.svg"
/>
</ItemGroup>
<ItemGroup>
<EmbeddedResource
Include=
"Resources\Issue281_Bounds\BoundsTest.svg"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildBinPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment