Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
f9a1629c
Commit
f9a1629c
authored
Mar 26, 2020
by
540597360@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加MyMath中Map的double版本
parent
0667c868
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
+104
-0
MyMath.cs
Project.FLY.Misc/MISC/MyMath.cs
+104
-0
No files found.
Project.FLY.Misc/MISC/MyMath.cs
View file @
f9a1629c
...
@@ -500,5 +500,109 @@ namespace Misc
...
@@ -500,5 +500,109 @@ namespace Misc
}
}
return
data_new
;
return
data_new
;
}
}
/// <summary>
/// 对环形数据 分区移位
/// </summary>
/// <param name="data">原始数据</param>
/// <param name="map">key=old_idx, value=new_idx</param>
/// <returns></returns>
public
static
double
[]
Map
(
IEnumerable
<
double
>
data
,
Dictionary
<
int
,
int
>
map
)
{
if
(
map
==
null
||
map
.
Count
()
==
0
)
return
data
.
ToArray
();
double
[]
data_new
=
new
double
[
data
.
Count
()];
if
(
map
.
Count
()
==
1
)
{
//只是平移而已
int
old_idx0
=
map
.
Keys
.
ElementAt
(
0
);
int
new_idx0
=
map
[
old_idx0
];
for
(
int
i
=
0
;
i
<
data
.
Count
();
i
++)
{
int
new_idx
=
i
;
int
old_idx
=
(
old_idx0
-
new_idx0
)
+
new_idx
;
if
(
old_idx
>=
data
.
Count
())
old_idx
-=
data
.
Count
();
else
if
(
old_idx
<
0
)
old_idx
+=
data
.
Count
();
data_new
[
new_idx
]
=
data
.
ElementAt
(
old_idx
);
}
return
data_new
;
}
for
(
int
i
=
0
;
i
<
map
.
Count
();
i
++)
{
int
old_idx0
=
map
.
Keys
.
ElementAt
(
i
);
int
new_idx0
=
map
[
old_idx0
];
int
i_next
=
i
+
1
;
if
(
i_next
>=
map
.
Count
())
i_next
=
0
;
int
old_idx1
=
map
.
Keys
.
ElementAt
(
i_next
);
int
new_idx1
=
map
[
old_idx1
];
int
cnt
=
new_idx1
-
new_idx0
;
if
(
cnt
<
0
)
cnt
+=
data
.
Count
();
int
cnt_old
=
old_idx1
-
old_idx0
;
if
(
cnt_old
<
0
)
cnt_old
+=
data
.
Count
();
double
w
=
1.0
*
cnt_old
/
cnt
;
for
(
int
j
=
0
;
j
<
cnt
;
j
++)
{
int
new_idx
=
j
+
new_idx0
;
if
(
new_idx
>=
data
.
Count
())
new_idx
-=
data
.
Count
();
double
old_idx
=
j
*
w
+
old_idx0
;
int
o1
=
(
int
)
Math
.
Ceiling
(
old_idx
);
int
o0
=
(
int
)
old_idx
;
if
(
o0
==
o1
)
{
int
old_idx_0
=
o0
;
if
(
old_idx_0
>=
data
.
Count
())
old_idx_0
-=
data
.
Count
();
data_new
[
new_idx
]
=
data
.
ElementAt
(
old_idx_0
);
}
else
{
int
old_idx_0
=
o0
;
if
(
old_idx_0
>=
data
.
Count
())
old_idx_0
-=
data
.
Count
();
int
old_idx_1
=
o1
;
if
(
old_idx_1
>=
data
.
Count
())
old_idx_1
-=
data
.
Count
();
if
(
double
.
IsNaN
(
data
.
ElementAt
(
old_idx_1
))
&&
double
.
IsNaN
(
data
.
ElementAt
(
old_idx_0
)))
{
data_new
[
new_idx
]
=
(
data
.
ElementAt
(
old_idx_1
)
*
(
old_idx
-
o0
)
+
data
.
ElementAt
(
old_idx_0
)
*
(
o1
-
old_idx
));
}
else
if
(
double
.
IsNaN
(
data
.
ElementAt
(
old_idx_0
)))
{
data_new
[
new_idx
]
=
data
.
ElementAt
(
old_idx_0
);
}
else
if
(
double
.
IsNaN
(
data
.
ElementAt
(
old_idx_1
)))
{
data_new
[
new_idx
]
=
data
.
ElementAt
(
old_idx_1
);
}
else
{
data_new
[
new_idx
]
=
double
.
NaN
;
}
}
}
}
return
data_new
;
}
}
}
}
}
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