首次提交:本地项目同步到Gitea
This commit is contained in:
62
LibShapes/Utils/DistanceCalculation.cs
Normal file
62
LibShapes/Utils/DistanceCalculation.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// 距离计算的类,
|
||||
/// </summary>
|
||||
public class DistanceCalculation
|
||||
{
|
||||
/// <summary>
|
||||
/// 选择的容忍度
|
||||
/// </summary>
|
||||
public static float select_tolerance = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// 两点之间的距离
|
||||
/// </summary>
|
||||
/// <param name="p1"></param>
|
||||
/// <param name="p2"></param>
|
||||
/// <returns></returns>
|
||||
public static float distance(PointF p1, PointF p2)
|
||||
{
|
||||
return (float)Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点到线段的距离
|
||||
/// </summary>
|
||||
/// <param name="p0">点</param>
|
||||
/// <param name="p1">线段的点1</param>
|
||||
/// <param name="p2">线段的点2</param>
|
||||
/// <returns></returns>
|
||||
public static float pointToLine(PointF p0, PointF p1, PointF p2)
|
||||
{
|
||||
|
||||
float a = distance(p1, p2); // 求出这个线段的长度
|
||||
float b = distance(p0, p1); // 这个点跟线段的点1的长度
|
||||
float c = distance(p0, p2); // 这个点跟线段的点2的长度
|
||||
// 这里分几种情况
|
||||
if (c*c >= a*a + b*b)
|
||||
{
|
||||
// 如果这个特别的长,那么这个点就不考虑距离了
|
||||
return b;
|
||||
}else if(b*b >= a * a + c * c)
|
||||
{
|
||||
// 同理
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
float p = (a + b + c) / 2; // 半周长
|
||||
double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c)); // 海伦公式求面积
|
||||
return (float)(2 * s / a); // 返回点到线的距离
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
79
LibShapes/Utils/ExcelData.cs
Normal file
79
LibShapes/Utils/ExcelData.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using ExcelDataReader;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// 这个是一个工具类,可以读取excel数据的
|
||||
/// </summary>
|
||||
public class ExcelData
|
||||
{
|
||||
public static DataTable LoadExcel(string file_path)
|
||||
{
|
||||
using (var stream = File.Open(file_path, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
using (var reader = ExcelReaderFactory.CreateReader(stream))
|
||||
{
|
||||
|
||||
// Gets or sets a callback to obtain configuration options for a DataTable.
|
||||
var conf = new ExcelDataSetConfiguration()
|
||||
{
|
||||
// Gets or sets a value indicating whether to set the DataColumn.DataType
|
||||
// property in a second pass.
|
||||
UseColumnDataType = true,
|
||||
|
||||
// Gets or sets a callback to determine whether to include the current sheet
|
||||
// in the DataSet. Called once per sheet before ConfigureDataTable.
|
||||
FilterSheet = (tableReader, sheetIndex) => true,
|
||||
|
||||
// Gets or sets a callback to obtain configuration options for a DataTable.
|
||||
ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
|
||||
{
|
||||
// Gets or sets a value indicating the prefix of generated column names.
|
||||
EmptyColumnNamePrefix = "Column",
|
||||
|
||||
// Gets or sets a value indicating whether to use a row from the
|
||||
// data as column names. 是否使用数据作为列名
|
||||
UseHeaderRow = true,
|
||||
|
||||
//// Gets or sets a callback to determine which row is the header row.
|
||||
//// Only called when UseHeaderRow = true.
|
||||
//ReadHeaderRow = (rowReader) =>
|
||||
//{
|
||||
// // F.ex skip the first row and use the 2nd row as column headers:
|
||||
// rowReader.Read();
|
||||
//},
|
||||
|
||||
// Gets or sets a callback to determine whether to include the
|
||||
// current row in the DataTable.
|
||||
FilterRow = (rowReader) =>
|
||||
{
|
||||
return true;
|
||||
},
|
||||
|
||||
// Gets or sets a callback to determine whether to include the specific
|
||||
// column in the DataTable. Called once per column after reading the
|
||||
// headers.
|
||||
FilterColumn = (rowReader, columnIndex) =>
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var ds = reader.AsDataSet(conf);
|
||||
// 这里方便只是导入第一个
|
||||
return ds.Tables[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user