Skip to content

Commit 2c846e2

Browse files
committed
update
1 parent dd37db1 commit 2c846e2

10 files changed

Lines changed: 119 additions & 22 deletions

File tree

Crystallography.Native/Crystallography.Native.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
<ConformanceMode>
329329
</ConformanceMode>
330330
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
331-
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
331+
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
332332
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
333333
<MultiProcessorCompilation>true</MultiProcessorCompilation>
334334
<EnableParallelCodeGeneration>false</EnableParallelCodeGeneration>

Crystallography.OpenGL/Crystallography.OpenGL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PackageReference Include="MathNet.Numerics" Version="6.0.0-beta2" />
3434
<PackageReference Include="OpenTK" Version="4.9.4" />
3535
<PackageReference Include="SimdLinq" Version="1.3.2" />
36-
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.10" />
36+
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.7.0" />
3737
<PackageReference Include="System.Management" Version="10.0.0" />
3838
<PackageReference Include="ZLinq" Version="1.5.4" />
3939
</ItemGroup>

Crystallography/Crystal/CrystalMinimum.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public enum DataType { None = 0, AMCSD = 1, COD = 2, }
5353
#endregion
5454

5555
#region プロパティ
56+
[MemoryPackIgnore]
57+
public static byte ID => 0;
58+
5659
/// <summary>
5760
/// a,b,c,alpha,beta,gammaの順番. 単位はAと度. エラーは 「9.726|5|」のような形式で表現
5861
/// </summary>

Crystallography/ExtensionMethods.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
using MathNet.Numerics.LinearAlgebra;
44
using MathNet.Numerics.LinearAlgebra.Double;
5+
using MemoryPack;
6+
using MemoryPack.Compression;
57
using System;
68
using System.Collections.Generic;
79
using System.Drawing;
@@ -363,6 +365,61 @@ public static class DoubleEx
363365
}
364366
#endregion
365367

368+
369+
public static class MemoryPackEx
370+
{
371+
372+
/// <summary>
373+
/// 静的メソッド MemoryPackでシリアライズしてbyte[]配列を返す
374+
/// </summary>
375+
/// <param name="val"></param>
376+
/// <returns></returns>
377+
public static byte[] Serialize<T>(T val, System.IO.Compression.CompressionLevel level= System.IO.Compression.CompressionLevel.Optimal, int window =22 )
378+
{
379+
using var compressor = new BrotliCompressor(level, window);
380+
MemoryPackSerializer.Serialize(compressor, val);
381+
return compressor.ToArray();
382+
}
383+
384+
/// <summary>
385+
/// 静的メソッド MemoryPackでシリアライズしてbyte[]配列を返す 先頭に1バイトのヘッダーを付加する
386+
/// </summary>
387+
/// <param name="val"></param>
388+
/// <returns></returns>
389+
public static byte[] Serialize<T>(byte header, T val, System.IO.Compression.CompressionLevel level = System.IO.Compression.CompressionLevel.Optimal, int window = 22)
390+
{
391+
using var compressor = new BrotliCompressor(level, window);
392+
MemoryPackSerializer.Serialize(compressor, val);
393+
//return compressor.ToArray();
394+
395+
//先頭の4バイトはheaderを格納
396+
var data = compressor.ToArray();
397+
var buffer = new byte[data.Length + 1];
398+
buffer[0] = header;
399+
Buffer.BlockCopy(data, 0, buffer, 1, data.Length);
400+
return buffer;
401+
}
402+
403+
/// <summary>
404+
/// MemoryPackでシリアライズされた byte[] 配列からTを返す. 不適切な入力値だった場合は default(T)) 返し。
405+
/// </summary>
406+
/// <param name="bytes"></param>
407+
/// <returns></returns>
408+
public static T Deserialize<T>(byte[] bytes)
409+
{
410+
try
411+
{
412+
using var decompressor = new BrotliDecompressor();// Decompression(require using)
413+
return MemoryPackSerializer.Deserialize<T>(decompressor.Decompress(bytes));
414+
}
415+
catch { return default; }
416+
}
417+
418+
}
419+
#region MemoryPackの拡張
420+
421+
#endregion
422+
366423
#region Graphicsクラス
367424
/// <summary>
368425
/// Graphics クラスの描画関数にdoubleを受けられるにようにした拡張メソッド

Crystallography/PointD.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using MemoryPack;
12
using System;
23
using System.ComponentModel;
34
using System.Drawing;
@@ -137,15 +138,28 @@ public SizeD(Size size) : this()
137138
[StructLayout(LayoutKind.Sequential)]
138139
[Serializable()]
139140
[TypeConverter(typeof(PointDConverter))]
140-
public struct PointD : IComparable, IEquatable<PointD>
141+
[MemoryPackable]
142+
public partial struct PointD : IComparable, IEquatable<PointD>
141143
{
142144
public double X { get; set; }
143145
public double Y { get; set; }
146+
147+
[MemoryPackIgnore]
144148
public object Tag { get; set; }
149+
150+
[MemoryPackIgnore]
145151
public readonly bool IsNaN => double.IsNaN(X) || double.IsNaN(Y);
152+
153+
[MemoryPackIgnore]
146154
public readonly double Length2 => X * X + Y * Y;
155+
156+
[MemoryPackIgnore]
147157
public readonly double Length => Math.Sqrt(X * X + Y * Y);
148158

159+
[MemoryPackConstructor]
160+
public PointD()
161+
{ X = 0;Y = 0;Tag = null; }
162+
149163
public PointD(in double x, in double y)
150164
{
151165
X = x;

Crystallography/Profile.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MathNet.Numerics.LinearAlgebra.Double;
2+
using MemoryPack;
23
using System;
34
using System.Collections.Generic;
45
using System.Drawing;
@@ -9,27 +10,35 @@
910
namespace Crystallography;
1011

1112
[Serializable]
12-
public class Profile : ICloneable
13+
[MemoryPackable]
14+
public partial class Profile : ICloneable
1315
{
1416
#region プロパティ、フィールド
1517
public string text;
1618

17-
public List<PointD> Pt;
18-
public List<PointD> Err;
19+
public List<PointD> Pt=[];
20+
public List<PointD> Err=[];
1921

22+
[MemoryPackIgnore]
2023
public Color Color = Color.Blue;
2124

2225
public float LineWidth = 1f;
2326

27+
[MemoryPackIgnore]
2428
public RectangleD Range => new(new PointD(Pt.Min(p => p.X), Pt.Min(p => p.Y)), new PointD(Pt.Max(p => p.X), Pt.Max(p => p.Y)));
29+
[MemoryPackIgnore]
2530
public double MaxX => Pt.Max(p => p.X);
31+
[MemoryPackIgnore]
2632
public double MinX => Pt.Min(p => p.X);
33+
[MemoryPackIgnore]
2734
public double MaxY => Pt.Max(p => p.Y);
35+
[MemoryPackIgnore]
2836
public double MinY => Pt.Min(p => p.Y);
2937

3038
#endregion
3139

3240
#region コンストラクタ
41+
[MemoryPackConstructor]
3342
public Profile()
3443
{
3544
Pt = [];
@@ -423,29 +432,37 @@ public enum BackgroundMode { BSplineCurve, ReferrenceProfile }
423432

424433
#endregion
425434

426-
[Serializable]
427-
public class DiffractionProfile2 : ICloneable
435+
//[Serializable]
436+
[MemoryPackable]
437+
public partial class DiffractionProfile2 : ICloneable
428438
{
439+
public static byte ID => 2;
440+
429441
#region マスク関連ここから
430442
[Serializable]
431-
public class MaskingRange
443+
[MemoryPackable]
444+
public partial class MaskingRange
432445
{
433446
public double[] X = new double[2];
434447

448+
[MemoryPackConstructor]
435449
public MaskingRange() => X[0] = X[1] = 0;
436450

437451
public MaskingRange(double x1, double x2)
438452
{
439453
X[0] = x1;
440454
X[1] = x2;
441455
}
442-
456+
457+
[MemoryPackIgnore]
443458
public double Maximum => Math.Max(X[0], X[1]);
444-
459+
460+
[MemoryPackIgnore]
445461
public double Minimum => Math.Min(X[0], X[1]);
446-
462+
447463
public override string ToString()
448464
=> X[0] < X[1] ? $"{X[0]:g8} - {X[1]:g8}" : $"{X[1]:g8} - {X[0]:g8}";
465+
449466
}
450467

451468
public List<MaskingRange> maskingRanges = [];
@@ -534,12 +551,13 @@ public object Clone()
534551
#region プロパティ
535552

536553
#region プロファイル
554+
537555
/// <summary>
538556
/// ソースプロファイル ()
539557
/// </summary>
540558
public Profile SourceProfile;
541559

542-
public PointD[] BgPoints;
560+
public PointD[] BgPoints = [];
543561

544562
/// <summary>
545563
/// 軸変換後のプロファイル. SetConvertedProfile()を呼び出すことで生成される.
@@ -1257,7 +1275,8 @@ public PointD[] ConvertDestToSrc(PointD[] pt)
12571275
#region HorizontalAxisProperty プロファイルの性質を表す構造体
12581276

12591277
[Serializable]
1260-
public record struct HorizontalAxisProperty
1278+
[MemoryPackable]
1279+
public partial record struct HorizontalAxisProperty
12611280
{
12621281
#region プロパティ
12631282
/// <summary>
@@ -2222,7 +2241,7 @@ public DiffractionProfile()
22222241

22232242
ElectronAccVolatage = 200;
22242243

2225-
ColorARGB = null;
2244+
ColorARGB = Color.Blue.ToArgb();
22262245
}
22272246

22282247

ReciPro/FormMain.Designer.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReciPro/FormMain.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ protected override void WndProc(ref System.Windows.Forms.Message msg)
7575
if (Clipboard.GetDataObject().GetDataPresent(typeof(byte[])))
7676
{
7777
var bytes = (byte[])Clipboard.GetDataObject().GetData(typeof(byte[]));
78-
var c2 = Crystal2.Deserialize(bytes);
79-
crystalControl.Crystal = Crystal2.GetCrystal(c2);
78+
if (bytes[0] == Crystal2.ID)
79+
{
80+
var c2 = Crystal2.Deserialize(bytes[1..]);
81+
crystalControl.Crystal = Crystal2.GetCrystal(c2);
82+
}
8083
}
8184

8285
if ((int)NextHandle != 0)

ReciPro/ReciPro.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<PackageReference Include="MathNet.Numerics.MKL.Win-x64" Version="3.0.0" />
9696
<PackageReference Include="OpenTK" Version="4.9.4" />
9797
<PackageReference Include="SimdLinq" Version="1.3.2" />
98-
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.10" />
98+
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.7.0" />
9999
<PackageReference Include="ZLinq" Version="1.5.4" />
100100
</ItemGroup>
101101

ReciPro/Version.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ internal static class Version
77

88
public const string History =
99
"History" +
10+
"\r\n ver4.910(2025/11/26) Updated: .Net Desktop Runtime 9 to 10. Fixed minor bugs." +
1011
"\r\n ver4.909(2025/10/29) Fixed a minor bug." +
1112
"\r\n ver4.907(2025/10/28) Fixed a minor bug." +
1213
"\r\n ver4.906(2025/09/26) Fixed a minor bug. Renewed the Eigen library." +

0 commit comments

Comments
 (0)