Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
f711d6cd
Commit
f711d6cd
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
add inversion possibility to Rectangle
add unit tests as well
parent
b12a6be8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!81
Refactorings no. 2 for the upcoming removing of "region of interest" (ROI)
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Device/Mask/Rectangle.cpp
+9
-2
9 additions, 2 deletions
Device/Mask/Rectangle.cpp
Device/Mask/Rectangle.h
+5
-2
5 additions, 2 deletions
Device/Mask/Rectangle.h
Tests/UnitTests/Core/Mask/Shape2DTest.cpp
+31
-0
31 additions, 0 deletions
Tests/UnitTests/Core/Mask/Shape2DTest.cpp
with
45 additions
and
4 deletions
Device/Mask/Rectangle.cpp
+
9
−
2
View file @
f711d6cd
...
...
@@ -19,7 +19,8 @@
//! @param ylow y-coordinate of lower left corner
//! @param xup x-coordinate of upper right corner
//! @param yup y-coordinate of upper right corner
Rectangle
::
Rectangle
(
double
xlow
,
double
ylow
,
double
xup
,
double
yup
)
:
IShape2D
(
"Rectangle"
)
Rectangle
::
Rectangle
(
double
xlow
,
double
ylow
,
double
xup
,
double
yup
,
bool
inverted
)
:
IShape2D
(
"Rectangle"
),
m_inverted
(
inverted
)
{
if
(
xup
<=
xlow
)
{
std
::
ostringstream
message
;
...
...
@@ -39,9 +40,15 @@ Rectangle::Rectangle(double xlow, double ylow, double xup, double yup) : IShape2
m_yup
=
yup
;
}
void
Rectangle
::
setInverted
(
bool
inverted
/*= true*/
)
{
m_inverted
=
inverted
;
}
bool
Rectangle
::
contains
(
double
x
,
double
y
)
const
{
return
x
<=
m_xup
&&
x
>=
m_xlow
&&
y
<=
m_yup
&&
y
>=
m_ylow
;
const
bool
inRect
=
x
<=
m_xup
&&
x
>=
m_xlow
&&
y
<=
m_yup
&&
y
>=
m_ylow
;
return
m_inverted
?
!
inRect
:
inRect
;
}
bool
Rectangle
::
contains
(
const
Bin1D
&
binx
,
const
Bin1D
&
biny
)
const
...
...
This diff is collapsed.
Click to expand it.
Device/Mask/Rectangle.h
+
5
−
2
View file @
f711d6cd
...
...
@@ -24,8 +24,10 @@
class
Rectangle
:
public
IShape2D
{
public:
Rectangle
(
double
xlow
,
double
ylow
,
double
xup
,
double
yup
);
Rectangle
*
clone
()
const
{
return
new
Rectangle
(
m_xlow
,
m_ylow
,
m_xup
,
m_yup
);
}
Rectangle
(
double
xlow
,
double
ylow
,
double
xup
,
double
yup
,
bool
inverted
=
false
);
Rectangle
*
clone
()
const
{
return
new
Rectangle
(
m_xlow
,
m_ylow
,
m_xup
,
m_yup
,
m_inverted
);
}
void
setInverted
(
bool
inverted
=
true
);
bool
contains
(
double
x
,
double
y
)
const
;
bool
contains
(
const
Bin1D
&
binx
,
const
Bin1D
&
biny
)
const
;
...
...
@@ -39,6 +41,7 @@ public:
private
:
double
m_xlow
,
m_ylow
,
m_xup
,
m_yup
;
bool
m_inverted
;
};
#endif // BORNAGAIN_DEVICE_MASK_RECTANGLE_H
This diff is collapsed.
Click to expand it.
Tests/UnitTests/Core/Mask/Shape2DTest.cpp
+
31
−
0
View file @
f711d6cd
...
...
@@ -41,6 +41,37 @@ TEST_F(Shape2DTest, Rectangle)
EXPECT_FALSE
(
clone
->
contains
(
binx2
,
biny2
));
}
TEST_F
(
Shape2DTest
,
Rectangle_inverted
)
{
Rectangle
rect
(
-
4.0
,
-
2.0
,
4.0
,
2.0
,
true
);
EXPECT_DOUBLE_EQ
(
32.0
,
rect
.
getArea
());
EXPECT_FALSE
(
rect
.
contains
(
0.0
,
0.0
));
EXPECT_FALSE
(
rect
.
contains
(
4.0
,
2.0
));
EXPECT_FALSE
(
rect
.
contains
(
-
4.0
,
-
2.0
));
EXPECT_FALSE
(
rect
.
contains
(
-
4.0
,
-
2.0
));
EXPECT_TRUE
(
rect
.
contains
(
0.0
,
2.01
));
EXPECT_TRUE
(
rect
.
contains
(
4.0
,
-
2.01
));
Bin1D
binx1
(
3.5
,
4.5
);
Bin1D
biny1
(
1.5
,
2.5
);
EXPECT_FALSE
(
rect
.
contains
(
binx1
,
biny1
));
Bin1D
binx2
(
3.5
,
4.6
);
Bin1D
biny2
(
1.5
,
2.6
);
EXPECT_TRUE
(
rect
.
contains
(
binx2
,
biny2
));
std
::
unique_ptr
<
Rectangle
>
clone
(
rect
.
clone
());
EXPECT_DOUBLE_EQ
(
32.0
,
clone
->
getArea
());
EXPECT_FALSE
(
clone
->
contains
(
0.0
,
0.0
));
EXPECT_FALSE
(
clone
->
contains
(
4.0
,
2.0
));
EXPECT_FALSE
(
clone
->
contains
(
-
4.0
,
-
2.0
));
EXPECT_FALSE
(
clone
->
contains
(
-
4.0
,
-
2.0
));
EXPECT_TRUE
(
clone
->
contains
(
0.0
,
2.01
));
EXPECT_TRUE
(
clone
->
contains
(
4.0
,
-
2.01
));
EXPECT_FALSE
(
clone
->
contains
(
binx1
,
biny1
));
EXPECT_TRUE
(
clone
->
contains
(
binx2
,
biny2
));
}
TEST_F
(
Shape2DTest
,
Ellipse
)
{
Ellipse
ellipse
(
10.0
,
1.0
,
8.0
,
4.0
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment