Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tools
frackit
Commits
0eecec25
Commit
0eecec25
authored
Apr 20, 2020
by
Dennis Gläser
Browse files
[python][point] implement type deduction from args
parent
e6b692c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/frackit/geometry/__init__.py
View file @
0eecec25
from
._geometry
import
*
# Construct an n-dimensional point
def
Point
(
*
args
,
**
kwargs
):
numArgs
=
len
(
args
)
+
len
(
kwargs
)
if
numArgs
==
0
:
raise
Exception
(
"Arguments needed for point construction. For default-"
+
\
"constructible points use the dimension-specific "
+
\
"implementations Point_1, Point_2 or Point_3"
);
# single argument construction
if
numArgs
==
1
:
# construction from a list
if
isinstance
(
args
[
0
],
list
):
if
len
(
args
[
0
])
==
1
:
return
Point_1
(
*
args
,
**
kwargs
)
elif
len
(
args
[
0
])
==
2
:
return
Point_2
(
*
args
,
**
kwargs
)
else
:
return
Point_3
(
*
args
,
**
kwargs
)
# construction from a single (hopefully) scalar
else
:
return
Point_1
(
*
args
,
**
kwargs
)
# select point type from the number of arguments
if
numArgs
==
2
:
return
Point_2
(
*
args
,
**
kwargs
)
else
:
return
Point_3
(
*
args
,
**
kwargs
)
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