Commit f0c36ab5 authored by 潘栩锋's avatar 潘栩锋 🚴

1,修改了Range

parent d8728c2c
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\Project.FLY.Thick.Normal\packages\PropertyChanged2.Fody.2.5.13\build\PropertyChanged2.Fody.props" Condition="Exists('..\..\..\Project.FLY.Thick.Normal\packages\PropertyChanged2.Fody.2.5.13\build\PropertyChanged2.Fody.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
......@@ -33,6 +34,8 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -59,6 +62,12 @@
</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\Project.FLY.Thick.Normal\packages\Newtonsoft.Json.12.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PropertyChanged2, Version=2.5.13.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\..\..\Project.FLY.Thick.Normal\packages\PropertyChanged2.Fody.2.5.13\lib\net40\PropertyChanged2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
......@@ -110,8 +119,22 @@
</ItemGroup>
<ItemGroup>
<None Include="..\版本说明.txt" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\Project.FLY.Thick.Normal\packages\Fody.3.2.13\build\Fody.targets" Condition="Exists('..\..\..\Project.FLY.Thick.Normal\packages\Fody.3.2.13\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\Project.FLY.Thick.Normal\packages\Fody.3.2.13\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\Project.FLY.Thick.Normal\packages\Fody.3.2.13\build\Fody.targets'))" />
<Error Condition="!Exists('..\..\..\Project.FLY.Thick.Normal\packages\PropertyChanged2.Fody.2.5.13\build\PropertyChanged2.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\Project.FLY.Thick.Normal\packages\PropertyChanged2.Fody.2.5.13\build\PropertyChanged2.Fody.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......
......@@ -3,33 +3,32 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Newtonsoft.Json;
namespace Misc
{
/// <summary>
/// int范围类,
/// </summary>
public class Range : INotifyPropertyChanged, Misc.ISaveToXml
{
static Range()
{
Misc.SaveToXmlHepler.Regist(typeof(Range));
}
public Range()
{
Reset();
}
public bool Contain(Range r)
{
if ((Begin <= r.Begin) && (r.End <= End))
return true;
else
return false;
}
public bool Contain(int p)
{
if ((Begin <= p) && (p <= End))
return true;
else
return false;
}
#region property
/// <summary>
/// 开始
/// </summary>
public int Begin { get; set; }
/// <summary>
/// 结束
/// </summary>
public int End { get; set; }
#endregion
#region just get property
/// <summary>
/// 本范围 中心位置
/// </summary>
[JsonIgnore]
public int Mid
{
get
......@@ -40,6 +39,11 @@ namespace Misc
return Misc.MyBase.NULL_VALUE;
}
}
/// <summary>
/// 本范围宽度
/// </summary>
[JsonIgnore]
public int Width
{
get
......@@ -50,54 +54,91 @@ namespace Misc
return Misc.MyBase.NULL_VALUE;
}
}
public void Move(int offset)
{
Begin += offset;
End += offset;
}
public int Begin
/// <summary>
/// 是否有效
/// </summary>
[JsonIgnore]
public bool IsValid
{
get
{
return begin;
}
set
{
begin = value;
if (this.PropertyChanged != null)
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Begin"));
if (Misc.MyBase.ISVALIDATA(Begin))
return true;
else
return false;
}
}
private int begin;
public int End
#endregion
static Range()
{
get
{
return end;
}
set
{
end = value;
if (this.PropertyChanged != null)
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("End"));
}
Misc.SaveToXmlHepler.Regist(typeof(Range));
}
/// <summary>
/// 使用无效值初始化
/// </summary>
public Range()
{
Reset();
}
#region methods
/// <summary>
/// 范围 r 在 本范围内
/// </summary>
/// <param name="r"></param>
/// <returns></returns>
public bool Contain(Range r)
{
if ((Begin <= r.Begin) && (r.End <= End))
return true;
else
return false;
}
/// <summary>
/// 点 p 在 本范围内
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public bool Contain(int p)
{
if ((Begin <= p) && (p <= End))
return true;
else
return false;
}
/// <summary>
/// 平移
/// </summary>
/// <param name="offset"></param>
public void Move(int offset)
{
Begin += offset;
End += offset;
}
private int end;
/// <summary>
/// 复位为无效
/// </summary>
public void Reset()
{
Begin = Misc.MyBase.NULL_VALUE;
End = Misc.MyBase.NULL_VALUE;
}
public bool IsValid
{
get
{
if (Misc.MyBase.ISVALIDATA(Begin))
return true;
else
return false;
}
}
/// <summary>
/// 转换为8个字节
/// </summary>
......@@ -125,6 +166,12 @@ namespace Misc
return true;
}
/// <summary>
/// 范围并集
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static Range operator |(Range a, Range b)
{
return new Range()
......@@ -134,6 +181,12 @@ namespace Misc
};
}
/// <summary>
/// 范围交集
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static Range operator &(Range a, Range b)
{
Range r = new Range()
......@@ -150,6 +203,13 @@ namespace Misc
return r;
}
}
/// <summary>
/// 范围 a小于b
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool operator <(Range a, Range b)
{
if (a.End < b.Begin)//[a.b,a.e] [b.b,b.e]
......@@ -161,6 +221,13 @@ namespace Misc
return false;
}
}
/// <summary>
/// 范围 a大于b
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool operator >(Range a, Range b)
{
if (b.End < (a.Begin))// [b.b,b.e][a.b,a.e]
......@@ -172,6 +239,8 @@ namespace Misc
return false;
}
}
public static bool operator <(int p, Range r)
{
if (p < r.Begin)
......@@ -216,6 +285,7 @@ namespace Misc
return false;
}
}
/// <summary>
/// 是否有交集
/// </summary>
......@@ -253,17 +323,31 @@ namespace Misc
return true;
return false;
}
/// <summary>
/// 复制 r 的值到 本范围内
/// </summary>
/// <param name="r"></param>
public void Copy(Range r)
{
Begin = r.Begin;
End = r.End;
}
/// <summary>
/// 克隆
/// </summary>
/// <returns></returns>
public Range Clone()
{
Range r = new Range();
r.Copy(this);
return r;
}
#endregion
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "[" + Begin.ToString() + "," + End.ToString() + "]=" + Width.ToString();
......@@ -332,4 +416,6 @@ namespace Misc
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment