Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
seto committed Nov 29, 2024
1 parent dcb6760 commit b08c31c
Show file tree
Hide file tree
Showing 35 changed files with 885 additions and 687 deletions.
131 changes: 130 additions & 1 deletion Crystallography.Controls/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,133 @@
[*.cs]

# WFO1000: A property should determine its property content serialization with the DesignerSerializationVisibilityAttribute, DefaultValueAttribute or the ShouldSerializeProperty method
dotnet_diagnostic.WFO1000.severity = silent
dotnet_diagnostic.WFO1000.severity = silent
[*.cs]
#### 命名スタイル ####

# 名前付けルール

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

# 記号の仕様

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

# 命名スタイル

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
csharp_indent_labels = one_less_than_current
csharp_space_around_binary_operators = before_and_after
csharp_using_directive_placement = outside_namespace:silent
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = false:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_prefer_static_local_function = true:suggestion
csharp_prefer_static_anonymous_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent

[*.vb]
#### 命名スタイル ####

# 名前付けルール

dotnet_naming_rule.interface_should_be_i_で始まる.severity = suggestion
dotnet_naming_rule.interface_should_be_i_で始まる.symbols = interface
dotnet_naming_rule.interface_should_be_i_で始まる.style = i_で始まる

dotnet_naming_rule.型_should_be_パスカル_ケース.severity = suggestion
dotnet_naming_rule.型_should_be_パスカル_ケース.symbols =
dotnet_naming_rule.型_should_be_パスカル_ケース.style = パスカル_ケース

dotnet_naming_rule.フィールド以外のメンバー_should_be_パスカル_ケース.severity = suggestion
dotnet_naming_rule.フィールド以外のメンバー_should_be_パスカル_ケース.symbols = フィールド以外のメンバー
dotnet_naming_rule.フィールド以外のメンバー_should_be_パスカル_ケース.style = パスカル_ケース

# 記号の仕様

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.型.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.型.required_modifiers =

dotnet_naming_symbols.フィールド以外のメンバー.applicable_kinds = property, event, method
dotnet_naming_symbols.フィールド以外のメンバー.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.フィールド以外のメンバー.required_modifiers =

# 命名スタイル

dotnet_naming_style.i_で始まる.required_prefix = I
dotnet_naming_style.i_で始まる.required_suffix =
dotnet_naming_style.i_で始まる.word_separator =
dotnet_naming_style.i_で始まる.capitalization = pascal_case

dotnet_naming_style.パスカル_ケース.required_prefix =
dotnet_naming_style.パスカル_ケース.required_suffix =
dotnet_naming_style.パスカル_ケース.word_separator =
dotnet_naming_style.パスカル_ケース.capitalization = pascal_case

dotnet_naming_style.パスカル_ケース.required_prefix =
dotnet_naming_style.パスカル_ケース.required_suffix =
dotnet_naming_style.パスカル_ケース.word_separator =
dotnet_naming_style.パスカル_ケース.capitalization = pascal_case

[*.{cs,vb}]
tab_width = 4
indent_size = 4
dotnet_style_operator_placement_when_wrapping = beginning_of_line
end_of_line = crlf
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_code_quality_unused_parameters = all:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
3 changes: 2 additions & 1 deletion Crystallography.Controls/Crystal/PoleFigureControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand Down Expand Up @@ -286,7 +287,7 @@ public void DrawOutline(Graphics g)
private int justBeforeCrystallineNumber = -1;
private IEnumerable<(int Radial, int Sector)>[] Index;

public object lockObject = new object();
public Lock lockObject = new();

public double[][] generateDensityArrayNormal(double angleResolution)
{
Expand Down
25 changes: 13 additions & 12 deletions Crystallography.Controls/CrystalDatabase/CrystalDatabaseControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
using System.Windows.Forms;
#endregion

Expand Down Expand Up @@ -61,13 +62,13 @@ static byte[] serialize<T>(T c)
static Crystal2[] deserialize(Stream stream)
{
var buffer1 = new byte[4];
stream.Read(buffer1);
stream.ReadExactly(buffer1);
var length = BitConverter.ToInt32(buffer1);

var buffer2 = ArrayPool<byte>.Shared.Rent(length);
try
{
stream.Read(buffer2, 0, length);
stream.ReadExactly(buffer2, 0, length);
using var decompressor = new BrotliDecompressor();// Decompression(require using)
return MemoryPackSerializer.Deserialize<Crystal2[]>(decompressor.Decompress(buffer2.AsSpan()[0..length]));
}
Expand Down Expand Up @@ -100,21 +101,21 @@ public CrystalDatabaseControl()
#region データベース読み込み/書き込み関連

#region バイト書き込み/読み込み
private static int readInt(Stream s) => BitConverter.ToInt32(readBytes(s, 4), 0);
private static int readByte(Stream s) => s.ReadByte();
private static long readLong(Stream s) => BitConverter.ToInt64(readBytes(s, 8), 0);
private static int readInt(FileStream s) => BitConverter.ToInt32(readBytes(s, 4), 0);
private static int readByte(FileStream s) => s.ReadByte();
private static long readLong(FileStream s) => BitConverter.ToInt64(readBytes(s, 8), 0);

private static byte[] readBytes(Stream s, int length)
private static byte[] readBytes(FileStream s, int length)
{
var bytes = new byte[length];
s.Read(bytes, 0, bytes.Length);
s.ReadExactly(bytes);
return bytes;
}

private static void writeInt(Stream s, in int v) => s.Write(BitConverter.GetBytes(v), 0, 4);
private static void writeLong(Stream s, in long v) => s.Write(BitConverter.GetBytes(v), 0, 8);
private static void writeByte(Stream s, in byte v) => s.WriteByte(v);
private static void writeBytes(Stream s, in byte[] v) => s.Write(v, 0, v.Length);
private static void writeInt(FileStream s, in int v) => s.Write(BitConverter.GetBytes(v), 0, 4);
private static void writeLong(FileStream s, in long v) => s.Write(BitConverter.GetBytes(v), 0, 8);
private static void writeByte(FileStream s, in byte v) => s.WriteByte(v);
private static void writeBytes(FileStream s, in byte[] v) => s.Write(v, 0, v.Length);

#endregion

Expand All @@ -128,7 +129,7 @@ public void ReadDatabase(string filename)
ReadDatabaseWorker.RunWorkerAsync(filename);
}

readonly object lockObj = new();
readonly Lock lockObj = new();
private void ReadDatabaseWorker_DoWork(object sender, DoWorkEventArgs e)
{
var filename = (string)e.Argument;
Expand Down
5 changes: 3 additions & 2 deletions Crystallography.Controls/Crystallography.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<OutputType>Library</OutputType>
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyVersion>2024.11.13.0422</AssemblyVersion>
<FileVersion>2024.11.13.0422</FileVersion>
<AssemblyVersion>2024.11.25.0729</AssemblyVersion>
<FileVersion>2024.11.25.0729</FileVersion>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
<ApplicationUseCompatibleTextRendering>true</ApplicationUseCompatibleTextRendering>
<ApplicationVisualStyles>true</ApplicationVisualStyles>
Expand Down Expand Up @@ -42,6 +42,7 @@
<ItemGroup>
<PackageReference Include="IronPython" Version="3.4.1" />
<PackageReference Include="SimdLinq" Version="1.3.2" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.9" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Crystallography.Controls/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Threading;

namespace Crystallography.Controls;

Expand Down Expand Up @@ -258,7 +259,7 @@ public void Replace(object srcCrystal, Crystal2 targetcrystal)
}
}

readonly object lockObj = new();
readonly Lock lockObj = new();
public DataTableCrystalDatabaseRow CreateRow(Crystal2 c)
{
DataTableCrystalDatabaseRow dr;
Expand Down
4 changes: 2 additions & 2 deletions Crystallography.Controls/FormCrystalSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public Crystal[] CheckedCrystalList
{
get
{
List<Crystal> crystalList = new List<Crystal>();
List<Crystal> crystalList = [];
for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
crystalList.Add((Crystal)checkedListBox1.CheckedItems[i]);
return crystalList.ToArray();
return [.. crystalList];
}
}

Expand Down
4 changes: 2 additions & 2 deletions Crystallography.Controls/Numeric/NumericBox.resx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
Expand Down Expand Up @@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
Expand Down
13 changes: 8 additions & 5 deletions Crystallography/Atom/AtomStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Windows.Graphics.Printing;
using Edge = Crystallography.XrayLineEdge;

namespace Crystallography;
Expand Down Expand Up @@ -2596,6 +2598,7 @@ public double FactorImaginary(double kV, double s2, double m)
return p1.A * p2.A * (Math.Exp(-s2 * product / sum) / sum - Math.Exp(-s2 * (product - m * m) / sum2m) / sum2m);
})) * Math.PI * gamma * 2 / k0;
}


/// <summary>
/// 局所形式の非弾性散乱因子 FlatEwald近似 未完成
Expand Down Expand Up @@ -7205,7 +7208,7 @@ public static PointD[] MassAbsorptionCoefficient(int z)
return [.. pt];
}

private static readonly object lockObjForMassAbsorption = new();
private static readonly Lock lockObjForMassAbsorption = new();

/// <summary>
/// 質量吸収係数を覚えておく
Expand Down Expand Up @@ -7390,7 +7393,7 @@ public static void ReadChantlerData(string[] fileNames)
int z = Convert.ToInt32(str[1].Split([','])[0].Replace("<b>Z=", ""));//2行目から原子番号を読み取る
//edgeの値を読み取る
while (!str[i].Contains("edge")) i++;
var edgeNo = Convert.ToInt32(str[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0]);
var edgeNo = Convert.ToInt32(str[i].Split([' '], StringSplitOptions.RemoveEmptyEntries)[0]);
i += 2;

var edge = new List<PointD>();
Expand All @@ -7414,7 +7417,7 @@ public static void ReadChantlerData(string[] fileNames)
str[i] = str[i].Replace(" VII", "7"); str[i] = str[i].Replace(" VI", "6"); str[i] = str[i].Replace(" IV", "4");
str[i] = str[i].Replace(" V", "5"); str[i] = str[i].Replace(" III", "3"); str[i] = str[i].Replace(" II", "2");
str[i] = str[i].Replace(" I", "1");
string[] temp = str[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string[] temp = str[i].Split([' '], StringSplitOptions.RemoveEmptyEntries);
if (temp.Length % 2 == 0)
for (int j = 0; j < temp.Length; j += 2)
{
Expand All @@ -7433,10 +7436,10 @@ public static void ReadChantlerData(string[] fileNames)

while (!str[i].Contains("Photoelectric")) i++;
i += 2;
var absorp = new List<PointD>(edge.ToArray());
var absorp = new List<PointD>([.. edge]);
sbAbsorption.AppendLine("new PointD[][]{");
for (; i < str.Count - 1; i++)
absorp.Add(new PointD(Convert.ToDouble(str[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0]), Convert.ToDouble(str[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1])));
absorp.Add(new PointD(Convert.ToDouble(str[i].Split([' '], StringSplitOptions.RemoveEmptyEntries)[0]), Convert.ToDouble(str[i].Split([' '], StringSplitOptions.RemoveEmptyEntries)[1])));
//sbAbsorption.AppendLine("new PointD(" + str[i].Replace(" ", ",") + ")" + (i == str.Count - 2 ? "" : ","));
absorp.Sort();
var pf = new List<Profile> { new() };
Expand Down
8 changes: 4 additions & 4 deletions Crystallography/BetheMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public enum Solver { Eigen_MKL, Eigen_Eigen, MtxExp_MKL, MtxExp_Eigen, Auto }
public event ProgressChangedEventHandler StemProgressChanged;
public event RunWorkerCompletedEventHandler StemCompleted;

private readonly object lockObj1 = new();
private readonly object lockObj2 = new();
private readonly Lock lockObj1 = new();
private readonly Lock lockObj2 = new();

/// <summary>
/// Result_STEM_Ela[thickness][defocus]
Expand Down Expand Up @@ -167,7 +167,7 @@ public BetheMethod(Crystal crystal)
};
bwSTEM.RunWorkerCompleted += Stem_RunWorkerCompleted;
bwSTEM.ProgressChanged += Stem_ProgressChanged;
bwSTEM.DoWork += stem_DoWork;
bwSTEM.DoWork += StemDoWork;
}
#endregion

Expand Down Expand Up @@ -885,7 +885,7 @@ public void RunSTEM(int maxNumOfBloch, double voltage, double cs, double delta,
if (!bwSTEM.IsBusy)
bwSTEM.RunWorkerAsync((solver, thread, cs, delta, sliceThickness, convergenceAngle, detAngleInner, detAngleOuter, thicknesses, defocusses, imageSize, resolution, sourceSize));
}
public unsafe void stem_DoWork(object sender, DoWorkEventArgs e)
public unsafe void StemDoWork(object sender, DoWorkEventArgs e)
{
//MathNetの行列の内部は、1列目の要素、2列目の要素、という順番で格納されている

Expand Down
3 changes: 2 additions & 1 deletion Crystallography/ChemicalStandard.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace Crystallography
{
Expand Down Expand Up @@ -679,7 +680,7 @@ public static double ChontinuousFluorescenceFactor(Element[] elements, int index
return c * elements[index].MolarWeight * zAve * EcA * mu_rhoAAe / mu_rhoUnkAe * gammaMinusOnePerGamma * Math.Log(1 + g * U0A) / g / U0A;
}

private static object lockObJforBetaArray = new object();
private static Lock lockObJforBetaArray = new Lock();

/// <summary>
/// betaの値を保管する一時変数.
Expand Down
Loading

0 comments on commit b08c31c

Please sign in to comment.