Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TULIP
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NUI
TULIP
Commits
cf0482c2
Commit
cf0482c2
authored
Sep 09, 2020
by
Nico Mack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added parseAngle method to AngleUtils class
parent
cd241985
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
TULIP/src/lu/list/itis/dkd/tui/utility/AngleUnit.java
TULIP/src/lu/list/itis/dkd/tui/utility/AngleUnit.java
+37
-0
TULIP/src/lu/list/itis/dkd/tui/utility/AngleUtils.java
TULIP/src/lu/list/itis/dkd/tui/utility/AngleUtils.java
+33
-0
No files found.
TULIP/src/lu/list/itis/dkd/tui/utility/AngleUnit.java
0 → 100644
View file @
cf0482c2
package
lu.list.itis.dkd.tui.utility
;
// ***************************************************************************
// * Enum Definition and Members *
// ***************************************************************************
public
enum
AngleUnit
{
DEG
(
1
),
RAD
((
2
*
Math
.
PI
)
/
360
);
public
final
double
factor
;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
private
AngleUnit
(
double
factor
)
{
this
.
factor
=
factor
;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
public
double
convertTo
(
double
value
,
AngleUnit
target
)
{
double
normalized
=
value
/
this
.
factor
;
return
value
*
target
.
factor
;
}
}
\ No newline at end of file
TULIP/src/lu/list/itis/dkd/tui/utility/AngleUtils.java
View file @
cf0482c2
...
...
@@ -16,6 +16,11 @@
*/
package
lu.list.itis.dkd.tui.utility
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @author mack
* @since [major].[minor]
...
...
@@ -37,6 +42,15 @@ public class AngleUtils {
public
static
final
double
ONE_EIGHTY
=
180
d
;
public
static
final
double
NINETY
=
90
d
;
private
static
final
Pattern
ANGLE_PATTERN
=
Pattern
.
compile
(
"([+-]?\\d+\\.?\\d*)\\s*(rad|deg)?"
,
Pattern
.
CASE_INSENSITIVE
);
//$NON-NLS-1$
private
static
Map
<
String
,
AngleUnit
>
LOOKUP_TABLE
=
new
HashMap
<>();
static
{
LOOKUP_TABLE
.
put
(
"rad"
,
AngleUnit
.
RAD
);
LOOKUP_TABLE
.
put
(
"deg"
,
AngleUnit
.
DEG
);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
...
...
@@ -143,4 +157,23 @@ public class AngleUtils {
return
quadrant
;
}
// ---------------------------------------------------------------------------
/**
* @param angleWithUnit
* @param targetUnit
* @return
*/
// ---------------------------------------------------------------------------
public
static
double
parseAngle
(
String
angleWithUnit
,
AngleUnit
targetUnit
)
{
double
value
=
Double
.
NaN
;
Matcher
areaMatcher
=
ANGLE_PATTERN
.
matcher
(
angleWithUnit
);
if
(
areaMatcher
.
matches
())
{
value
=
Double
.
parseDouble
(
areaMatcher
.
group
(
1
));
AngleUnit
angleUnit
=
LOOKUP_TABLE
.
get
(
areaMatcher
.
group
(
2
));
value
=
angleUnit
.
convertTo
(
value
,
targetUnit
);
}
return
value
;
}
}
Write
Preview
Markdown
is supported
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