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
90a743c3
Commit
90a743c3
authored
Apr 21, 2020
by
Dennis Gläser
Browse files
[python][circle] implement type deduction from args
parent
7bb6aab7
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/frackit/geometry/__init__.py
View file @
90a743c3
from
._geometry
import
*
def
raiseGeometryConstructorException
(
type
,
issue
=
""
):
if
issue
==
"notImplemented"
:
raise
Exception
(
"Requested specialization of "
+
type
+
" class is not yet implemented"
)
if
issue
==
"numArgs"
:
raise
Exception
(
"Wrong number of arguments provided for construction of '"
+
type
+
"'"
)
else
:
raise
Exception
(
"Could not construct '"
+
type
+
"' from provided argument(s)"
)
############################################
# Argument-dependent n-d point construction
# Argument-dependent n-d point construction
"
def
Point
(
*
args
,
**
kwargs
):
numArgs
=
len
(
args
)
+
len
(
kwargs
)
...
...
@@ -32,7 +41,7 @@ def Vector(*args, **kwargs):
numArgs
=
len
(
args
)
+
len
(
kwargs
)
if
numArgs
==
0
:
raise
Exception
(
"Arguments needed for vector construction. For default-"
+
\
"constructible vector use the dimension-specific "
+
\
"constructible vector
s
use the dimension-specific "
+
\
"implementations Vector_1, Vector_2 or Vector_3"
);
def
makeVector
(
dim
):
...
...
@@ -46,7 +55,7 @@ def Vector(*args, **kwargs):
dim
=
len
(
args
[
0
])
else
:
try
:
dim
=
args
[
0
].
worldDimension
except
:
raise
Exception
(
"Invalid argument provided for Vector construction
"
)
except
:
raise
GeometryConstructorException
(
"vector
"
)
return
makeVector
(
dim
)
# (maybe) construct from two points
...
...
@@ -57,3 +66,15 @@ def Vector(*args, **kwargs):
# last option: construction from the raw coordinates
return
makeVector
(
numArgs
)
############################################
# Argument-dependent n-d circle construction
def
Circle
(
*
args
,
**
kwargs
):
numArgs
=
len
(
args
)
+
len
(
kwargs
)
if
numArgs
!=
3
:
raiseGeometryConstructorException
(
"circle"
,
"numArgs"
)
try
:
dim
=
args
[
0
].
worldDimension
except
:
raiseGeometryConstructorException
(
"circle"
)
if
dim
==
1
:
raiseGeometryConstructorException
(
"circle"
,
"notImplemented"
)
# todo
elif
dim
==
2
:
raiseGeometryConstructorException
(
"circle"
,
"notImplemented"
)
# todo
else
:
return
Circle_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