Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyCommandCenter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Dawid Lukasz Abucewicz
PyCommandCenter
Commits
2b4077c3
Commit
2b4077c3
authored
6 years ago
by
David Bergström
Browse files
Options
Downloads
Patches
Plain Diff
Add 2 classes for points
parent
e9d51100
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
python-api-src/lib_point.cpp
+42
-0
42 additions, 0 deletions
python-api-src/lib_point.cpp
python-api-src/library.cpp
+1
-0
1 addition, 0 deletions
python-api-src/library.cpp
python-api-src/library.h
+2
-1
2 additions, 1 deletion
python-api-src/library.h
with
45 additions
and
1 deletion
python-api-src/lib_point.cpp
0 → 100644
+
42
−
0
View file @
2b4077c3
#include
"library.h"
namespace
py
=
pybind11
;
void
define_point
(
py
::
module
&
m
)
{
// Note that Point2D has dynamic attributes, allowing students to add additional methods to it
py
::
class_
<
sc2
::
Point2D
>
(
m
,
"Point2D"
,
py
::
dynamic_attr
())
.
def
(
py
::
init
<
float
,
float
>
())
.
def
(
py
::
init
())
.
def_readwrite
(
"x"
,
&
sc2
::
Point2D
::
x
)
.
def_readwrite
(
"y"
,
&
sc2
::
Point2D
::
y
)
.
def
(
py
::
self
+=
py
::
self
)
.
def
(
py
::
self
-=
py
::
self
)
.
def
(
py
::
self
*=
float
())
.
def
(
py
::
self
/=
float
())
// TODO: These does not compile
//.def(py::self == py::self)
//.def(py::self != py::self)
.
def
(
py
::
self
+
py
::
self
)
.
def
(
py
::
self
-
py
::
self
)
.
def
(
py
::
self
*
float
())
.
def
(
float
()
*
py
::
self
)
.
def
(
py
::
self
/
float
())
.
def
(
float
()
/
py
::
self
)
.
def
(
"__repr__"
,
[](
const
sc2
::
Point2D
&
p
)
{
return
"<Point2D: ("
+
std
::
to_string
(
p
.
x
)
+
", "
+
std
::
to_string
(
p
.
y
)
+
")>"
;
})
.
def
(
"__str__"
,
[](
const
sc2
::
Point2D
&
p
)
{
return
"("
+
std
::
to_string
(
p
.
x
)
+
", "
+
std
::
to_string
(
p
.
y
)
+
")"
;
});
py
::
class_
<
sc2
::
Point2DI
>
(
m
,
"Point2DI"
)
.
def
(
py
::
init
<
int
,
int
>
())
.
def_readwrite
(
"x"
,
&
sc2
::
Point2DI
::
x
)
.
def_readwrite
(
"y"
,
&
sc2
::
Point2DI
::
y
)
.
def
(
py
::
self
==
py
::
self
)
.
def
(
py
::
self
!=
py
::
self
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
python-api-src/library.cpp
+
1
−
0
View file @
2b4077c3
...
...
@@ -10,6 +10,7 @@ PYBIND11_MODULE(library, m)
define_unit
(
m
);
define_unittype
(
m
);
define_util
(
m
);
define_point
(
m
);
py
::
class_
<
Coordinator
>
(
m
,
"Coordinator"
)
.
def
(
py
::
init
())
...
...
This diff is collapsed.
Click to expand it.
python-api-src/library.h
+
2
−
1
View file @
2b4077c3
...
...
@@ -53,4 +53,5 @@ public:
void
define_typeenums
(
pybind11
::
module
&
m
);
void
define_unit
(
pybind11
::
module
&
m
);
void
define_unittype
(
pybind11
::
module
&
m
);
void
define_util
(
pybind11
::
module
&
m
);
\ No newline at end of file
void
define_util
(
pybind11
::
module
&
m
);
void
define_point
(
pybind11
::
module
&
m
);
\ No newline at end of file
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