| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- using OTSCLRINTERFACE;
- using OTSDataType;
- using OTSCommon;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using OTSModelSharp.ServiceInterface;
- using OTSModelSharp.ServiceCenter;
- using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;
- namespace OTSMeasureApp
- {
- public class OTSSamplespaceGraphicsPanelFun
- {
-
-
-
- #region 鼠标移动位置
- public static CRectangleGDIObject GetMouseMoveLocation(CRectangleGDIObject item, MouseEventArgs e)
- {
- item.Region = new Rectangle(
- item.Region.Left + e.X - item.DraggingPoint.X,
- item.Region.Top + e.Y - item.DraggingPoint.Y,
- item.Region.Width,
- item.Region.Height);
- item.DraggingPoint = e.Location;
- return item;
- }
- #endregion
-
-
- #region 鼠标方法操作
- public static void MouseWheelFunction(List<CRectangleGDIObject> objList, CRectangleGDIObject m_RectangleGDIObjects, float globalZoomNum)
- {
- for (int i = 0; i < objList.Count; i++)
- {
- //多边形测量区域鼠标缩放
- if (objList[i].CreateType == CreateRectangleType.Polygon)
- {
- if (objList[i].DrawPolygonPointRegionF != null)
- {
- int polygonPointCount = objList[i].DrawPolygonPointRegionF.Count;
- if (polygonPointCount > 0)
- {
- for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
- {
- PointF wheelPoint = new PointF();
- wheelPoint = objList[i].DrawPolygonPointRegionF[pointIndex];
- float X = wheelPoint.X * globalZoomNum;
- float Y = wheelPoint.Y * globalZoomNum;
- objList[i].PolygonPointRegionF[pointIndex] = new PointF(wheelPoint.X * globalZoomNum, wheelPoint.Y * globalZoomNum);
- }
- }
- }
- }
- else
- {
- RectangleF rectF = new RectangleF();
- rectF = objList[i].RegionF;
- //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
- RectangleF returnRectF = OTSSamplespaceGraphicsPanelFun.MouseWheelFunctionF(m_RectangleGDIObjects, rectF, globalZoomNum);
- objList[i].Region = new Rectangle((int)returnRectF.X, (int)returnRectF.Y, (int)returnRectF.Width, (int)returnRectF.Height);
- objList[i].BSEImageWitdh = returnRectF.Width;
- objList[i].BSEImageHeight = returnRectF.Height;
- objList[i].BSEImageLocation = new PointF(returnRectF.X, returnRectF.Y);
- objList[i].SEMCenterPoint = returnRectF.Location;
- //重新绘制测量区域路径
- UpdateMeasureGraphicsPath(objList[i], objList[i].Region);
- }
- }
- }
- public static RectangleF MouseWheelFunctionF(CRectangleGDIObject RectangleGDIObject, RectangleF itemRect, float globalZoomNum)
- {
- //缩放比例
- float X = itemRect.X * globalZoomNum;
- float Y = itemRect.Y * globalZoomNum;
- float Width = itemRect.Width * globalZoomNum;
- float Height = itemRect.Height * globalZoomNum;
- return new RectangleF(X, Y, Width, Height);
- }
- public enum EnumMousePointPosition
- {
- MouseSizeNone = 0, //'无
- MouseSizeRight = 1, //'拉伸右边框
- MouseSizeLeft = 2, //'拉伸左边框
- MouseSizeBottom = 3, //'拉伸下边框
- MouseSizeTop = 4, //'拉伸上边框
- MouseSizeTopLeft = 5, //'拉伸左上角
- MouseSizeTopRight = 6, //'拉伸右上角
- MouseSizeBottomLeft = 7, //'拉伸左下角
- MouseSizeBottomRight = 8, //'拉伸右下角
- MouseDrag = 9 // '鼠标拖动
- }
- const int Band = 5;
-
- public static EnumMousePointPosition MousePointPosition(Point point, Point e)
- {
- //MouseDrag 中心
- if ((e.X == point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseDrag;
- }
- //MouseSizeTopLeft 上左
- if ((e.X < point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTopLeft;
- }
- //MouseSizeTopRight 下右
- if ((e.X > point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTopRight;
- }
- //MouseSizeLeft 左侧
- if ((e.X < point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseSizeLeft;
- }
- //MouseSizeRight 右侧
- if ((e.X > point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseSizeRight;
- }
- //MouseSizeTop 上侧
- if ((e.X == point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTop;
- }
- //MouseSizeBottom 下侧
- if ((e.X == point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottom;
- }
- //MouseSizeBottomRight 下左
- if ((e.X < point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottomLeft;
- }
- //MouseSizeBottomRight 下右
- if ((e.X > point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottomRight;
- }
- return EnumMousePointPosition.MouseSizeNone;
- }
- #endregion
-
- #region 根据选择的测量区域 切换至最上层
- public static List<CRectangleGDIObject> SelectMeasureIndexIsTop(List<CRectangleGDIObject> objList, string SampleName)
- {
- List<CRectangleGDIObject> objListTemp = objList;
- CRectangleGDIObject itemTemp = null;
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.SampleName == SampleName)
- {
- //临时记录所选测量区域
- itemTemp = item;
- //删除原信息
- objListTemp.Remove(item);
- //添加新信息
- objListTemp.Insert(objListTemp.Count, itemTemp);
- break;
- }
- }
- return objListTemp;
- }
- #endregion
- #region 根据选择的样品 切换至最上层
- public static List<CRectangleGDIObject> SelectSampleIndexIsTop(List<CRectangleGDIObject> objList, string SampleName)
- {
- List<CRectangleGDIObject> objListTemp = objList;
- CRectangleGDIObject itemTemp = null;
- foreach (CRectangleGDIObject item in objList)
- {
- if (item.SampleName == SampleName)
- {
- //临时记录所选样品
- itemTemp = item;
- //删除原信息
- objListTemp.Remove(item);
- //添加新信息
- objListTemp.Insert(objListTemp.Count, itemTemp);
- break;
- }
- }
- return objListTemp;
- }
- #endregion
- #region 获取拍摄BSE图 将byte数组转换为图片
- public static Image GetBSEImage(byte[] ImageByte, int width, int height)
- {
- //图片
- Bitmap bitmap = null;
- //将byte数据转换为图片
- bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
- return bitmap;
- }
- #endregion
-
-
-
-
-
- #region 删除样品弹出提示
- public static bool ShowDeleteDialog(string sampleName)
- {
- //国际化
- OTSCommon.Language lan = new OTSCommon.Language();
- Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
- string str1 = table["message5"].ToString();
- string str2 = table["message6"].ToString();
- string sDeleteSampleName = str1;
- sDeleteSampleName += sampleName;
- sDeleteSampleName += " 信息 ?";
- if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- #endregion
- //#region 将点转换至工作区域
- //public void PointToClient(Point rect)
- //{
- // this.PointToClient(rect);
- //}
- //#endregion
- #region 删除样品 同时删除帧图
- public static bool DeleteSampleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleSelectName)
- {
- try
- {
- //提交主窗体响应
- bool deleteResult = false;
- if (OTSSamplespaceGraphicsPanelFun.ShowDeleteDialog(sampleSelectName))
- {
- //设置当前状态
- m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
- deleteResult = m_MeasureAppForm.DeleteSample(sampleSelectName);
- if (deleteResult)
- {
- //样品对象列表中无样品信息 则清除帧图对象列表信息
- bool result = m_MeasureAppForm.m_SamplepaceWindow.SampleIsEmptyClearSingleInfo();
- if(result)
- {
- m_MeasureAppForm.m_MeasureRetWindow.SetInit();
- }
- }
- }
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- #endregion
-
-
- #region 根据颜色枚举 获取颜色值
- public static string GetColorValue(ColorType ColorEnum)
- {
- string ColorStr = string.Empty;
- switch (ColorEnum)
- {
- case ColorType.SingleColor:
- ColorStr = "#fd8f8f";//帧图fd8f8f
- break;
- case ColorType.RoundRectangleColor:
- ColorStr = "#c8c8c8";//c8c8c8圆角矩形
- break;
- case ColorType.FontColor:
- ColorStr = "#90ee90";//90ee90文字颜色
- break;
- case ColorType.SampleColor:
- ColorStr = "#f4f4f4";//f4f4f4 样品未选择
- break;
- case ColorType.SampleSelColor:
- ColorStr = "#505050";//505050 样品选择后
- break;
- }
- return ColorStr;
- }
- #endregion
-
-
- #region 根据list中的帧图信息 获取中心位置
- public static PointF GetSingleCenterLocation(List<CRectangleGDIObject> m_SingleGDIObjects)
- {
- float MinX = 0f;
- float MinY = 0f;
- float MaxX = 0f;
- float MaxY = 0f;
- float width = 0f;
- float height = 0f;
- //获取最小XY 与最大XY
- MinX = m_SingleGDIObjects[0].RegionF.X;
- MinY = m_SingleGDIObjects[0].RegionF.Y;
- MaxX = m_SingleGDIObjects[0].RegionF.X;
- MaxY = m_SingleGDIObjects[0].RegionF.Y;
- width = m_SingleGDIObjects[0].RegionF.Width;
- height = m_SingleGDIObjects[0].RegionF.Height;
- for (int i = 0; i < m_SingleGDIObjects.Count; i++)
- {
- MinX = Math.Min(m_SingleGDIObjects[i].RegionF.X, MinX);
- MinY = Math.Min(m_SingleGDIObjects[i].RegionF.Y, MinY);
- MaxX = Math.Max(m_SingleGDIObjects[i].RegionF.X, MaxX);
- MaxY = Math.Max(m_SingleGDIObjects[i].RegionF.Y, MaxY);
- }
- //获取帧图的外框矩形
- RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX- MinX+ width, MaxY- MinY+ height);
- //计算外框矩形的中心点
- float PointFX = SingleRect.X + SingleRect.Width / 2;
- float PointFY = SingleRect.Y + SingleRect.Height / 2;
- PointF SingleCenterPoint = new PointF(PointFX, PointFY);
- return SingleCenterPoint;
- }
- public static PointF GetSingleDrawCenterLocation(List<CRectangleGDIObject> m_SingleGDIObjects)
- {
- float MinX = 0f;
- float MinY = 0f;
- float MaxX = 0f;
- float MaxY = 0f;
- float width = 0f;
- float height = 0f;
- //获取最小XY 与最大XY
- MinX = m_SingleGDIObjects[0].DrawRegionF.X;
- MinY = m_SingleGDIObjects[0].DrawRegionF.Y;
- MaxX = m_SingleGDIObjects[0].DrawRegionF.X;
- MaxY = m_SingleGDIObjects[0].DrawRegionF.Y;
- width = m_SingleGDIObjects[0].DrawRegionF.Width;
- height = m_SingleGDIObjects[0].DrawRegionF.Height;
- for (int i = 0; i < m_SingleGDIObjects.Count; i++)
- {
- MinX = Math.Min(m_SingleGDIObjects[i].DrawRegionF.X, MinX);
- MinY = Math.Min(m_SingleGDIObjects[i].DrawRegionF.Y, MinY);
- MaxX = Math.Max(m_SingleGDIObjects[i].DrawRegionF.X, MaxX);
- MaxY = Math.Max(m_SingleGDIObjects[i].DrawRegionF.Y, MaxY);
- }
- //获取帧图的外框矩形
- RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX - MinX + width, MaxY - MinY + height);
- //计算外框矩形的中心点
- float PointFX = SingleRect.X + SingleRect.Width / 2;
- float PointFY = SingleRect.Y + SingleRect.Height / 2;
- PointF SingleCenterPoint = new PointF(PointFX, PointFY);
- return SingleCenterPoint;
- }
- #endregion
- #region 将所有帧图移植测量区域位置
- public static void SetSingleLocationToMeasureLocation(List<CRectangleGDIObject> m_ObjectListGDIObjects, CRectangleGDIObject m_ObjectGDIObjects)
- {
- //获取帧图中心与测量区域中心
- PointF singleCenterPoinF= GetSingleCenterLocation(m_ObjectListGDIObjects);
- PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects);
- //测量区域 已改变为倍数的尺寸 中心点
- PointF measureCenterPoin = m_ObjectGDIObjects. GetCenterPoint();
- //测量区域 正常尺寸 中心点
- PointF measureCenterPoinF = m_ObjectGDIObjects. GetCenterPoint();
- //计算相差的XY距离
- float moveX = measureCenterPoin.X - singleCenterPoinF.X;
- float moveY = measureCenterPoin.Y - singleCenterPoinF.Y;
- float moveFX = measureCenterPoinF.X - singleDrawCenterPoinF.X;
- float moveFY = measureCenterPoinF.Y - singleDrawCenterPoinF.Y;
- //需要移动的位置
- PointF movePoint = new PointF(moveX, moveY);
- PointF movePointF = new PointF(moveFX, moveFY);
- foreach (var ObjectItem in m_ObjectListGDIObjects)
- {
- //计算移动后的位置
- float X = ObjectItem.RegionF.X + movePoint.X;
- float Y = ObjectItem.RegionF.Y + movePoint.Y;
- float Width = ObjectItem.RegionF.Width;
- float Height = ObjectItem.RegionF.Height;
- ObjectItem.Region = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
- ObjectItem.RegionF = new RectangleF(X, Y, Width, Height);
- ObjectItem.DrawRegionF = new RectangleF(ObjectItem.DrawRegionF.X + movePointF.X, ObjectItem.DrawRegionF.Y + movePointF.Y, ObjectItem.DrawRegionF.Width, ObjectItem.DrawRegionF.Height);
- }
- }
- #endregion
-
-
-
- #region 通过样品孔名称 获取在列表中的索引
- /// <summary>
- /// 通过样品孔名称 获取在列表中的索引
- /// </summary>
- /// <param name="oTSSampleStageData">样品台文件</param>
- /// <param name="sampleHoleName">样品孔名称</param>
- /// <returns></returns>
- public static int GetSampleHoleIndex(StageDrawingData oTSSampleStageData,string sampleHoleName, ref OTSSampleHoleInfo sampleHoleInfo)
- {
- try
- {
- int sampleHoleIndex = -1;
- if (oTSSampleStageData.sSHoleInfoList.Count > 0)
- {
- for (int i = 0; i < oTSSampleStageData.sSHoleInfoList.Count; i++)
- {
- if (oTSSampleStageData.sSHoleInfoList[i].sSHoleName == sampleHoleName)
- {
- sampleHoleInfo = oTSSampleStageData.sSHoleInfoList[i];
- sampleHoleIndex = i;
- break;
- }
- }
- }
- return sampleHoleIndex;
- }
- catch (Exception)
- {
- return -1;
- }
- }
- #endregion
-
- #region 添加帧图信息
- /// <summary>
- /// 添加帧图信息
- /// </summary>
- /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
- /// <param name="m_SingleGDIObjects">帧图对象列表</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns></returns>
- public static bool AddALLSingleInfo(List<CRectangleGDIObject> m_ALLSingleGDIObjects, List<CRectangleGDIObject> m_SingleGDIObjects, string sampleName)
- {
- bool result = false;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- bool IsExist = true;
- if (m_ALLSingleGDIObjects.Count > 0)
- {
-
- //判断是否包含样品名称
- foreach (var item in m_ALLSingleGDIObjects)
- {
- if (item.SampleName.Equals(sampleName))
- {
- IsExist = false;
- break;
- }
- }
- }
- if (IsExist)
- {
- result = true;
- foreach (var item in m_SingleGDIObjects)
- {
- m_ALLSingleGDIObjects.Add(item);
- }
- }
- return result;
- }
- return result;
- }
- #endregion
- #region 删除帧图信息
- /// <summary>
- /// 删除帧图信息
- /// </summary>
- /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns></returns>
- public static bool DeleteALLSingleInfo(List<CRectangleGDIObject> m_ALLSingleGDIObjects, string sampleName)
- {
- bool result = false;
- int resultCount = 0;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- if (m_ALLSingleGDIObjects.Count > 0)
- {
- for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ALLSingleGDIObjects[i].SampleName.Equals(sampleName))
- {
- m_ALLSingleGDIObjects.RemoveAt(i);
- resultCount++;
- }
- }
- }
- else
- {
- result = true;
- }
- if (resultCount > 0)
- {
- result = true;
- }
- }
- return result;
- }
- #endregion
- #region 切换样品 填充帧图信息
- public static void ChangeSampleFillSingleInfo(List<CRectangleGDIObject> m_ALLSingleGDIObjects, List<CRectangleGDIObject> m_SingleGDIObjects, string sampleName)
- {
- //判断帧图对象中是否存在当前工作样品帧图信息
- bool IsExist = true;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- if (m_ALLSingleGDIObjects.Count > 0)
- {
- foreach (var item in m_SingleGDIObjects)
- {
- if (item.SampleName.Equals(sampleName))
- {
- IsExist = false;
- }
- }
- if (IsExist)
- {
- //判断是否包含样品名称
- foreach (var item in m_ALLSingleGDIObjects)
- {
- if (item.SampleName.Equals(sampleName))
- {
- m_SingleGDIObjects.Add(item);
- }
- }
- }
- }
- }
- }
- #endregion
- #region 修改已存在的帧图中样品名称
- public static void EditWorkSampleName(List<CRectangleGDIObject> m_ALLSingleGDIObjects, string oldSampleName, string newSampleName)
- {
- int resultCount = 0;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- if (m_ALLSingleGDIObjects.Count > 0)
- {
- for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ALLSingleGDIObjects[i].SampleName.Equals(oldSampleName))
- {
- m_ALLSingleGDIObjects[i].SampleName = newSampleName;
- resultCount++;
- }
- }
- }
- }
- }
- #endregion
- #region 修改测量区域中GraphicsPath属性
- public static void UpdateMeasureGraphicsPath(CRectangleGDIObject measureItem, Rectangle rectPara)
- {
- //重新绘制测量区域路径
- GraphicsPath GPath = new GraphicsPath();
- if (measureItem.CreateType == CreateRectangleType.Polygon)
- {
- GraphicsPath PolygonMeasurePath = new GraphicsPath();
- PolygonMeasurePath.AddPolygon(measureItem.PolygonPointRegionF.ToArray());
- GPath = PolygonMeasurePath;
- }
- else if(measureItem.CreateType == CreateRectangleType.CircleByThreePoints)
- {
- GPath.AddEllipse(rectPara);
- }
- else
- {
- if (measureItem.Shape == (int)CreateRectangleType.Circle)
- {
- GPath.AddEllipse(rectPara);
- }
- else
- {
- GPath.AddRectangle(rectPara);
- }
- }
- measureItem.GPath = GPath;
- }
- #endregion
- #region OnMouseWheel
- public static void RestoreInitialPosition(List<CRectangleGDIObject> l_GDIObjects,float m_GlobalZoomNum)
- {
- for (int i = 0; i < l_GDIObjects.Count; i++)
- {
- RectangleF rectF = new RectangleF();
- rectF = l_GDIObjects[i].DrawRegionF;
- //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
- l_GDIObjects[i].Region = new Rectangle((int)(rectF.X * m_GlobalZoomNum), (int)(rectF.Y * m_GlobalZoomNum), (int)(rectF.Width * m_GlobalZoomNum), (int)(rectF.Height * m_GlobalZoomNum));
- PointF pointF = new PointF(rectF.X * m_GlobalZoomNum, rectF.Y * m_GlobalZoomNum);
- SizeF sizeF = new SizeF((rectF.Width * m_GlobalZoomNum), (rectF.Height * m_GlobalZoomNum));
- l_GDIObjects[i].RegionF = new RectangleF(pointF, sizeF);
- }
- }
- #endregion
- #region 判断当前位置是否在不规则形状里面
- /// <summary>
- /// 判断当前位置是否在不规则形状里面
- /// </summary>
- /// <param name="PointList">不规则形状坐标集合</param>
- /// <param name="currentMouseLocation">当前鼠标坐标</param>
- /// <returns></returns>
- public static bool PositionPnpoly(List<Point> polygonPointList, Point currentMouseLocation)
- {
- double testx = currentMouseLocation.X;
- double testy = currentMouseLocation.Y;
- int nvert = polygonPointList.Count;
- List<double> vertx = new List<double>();
- List<double> verty = new List<double>();
- for (int pointIndex = 0; pointIndex < polygonPointList.Count; pointIndex++)
- {
- vertx.Add(polygonPointList[pointIndex].X);
- verty.Add(polygonPointList[pointIndex].Y);
- }
- int i, j, c = 0;
- for (i = 0, j = nvert - 1; i < nvert; j = i++)
- {
- if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
- {
- c = 1 + c; ;
- }
- }
- if (c % 2 == 0)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- #endregion
- #region 获取多边形最小外接矩形
- /// <summary>
- /// 获取多边形最小外接矩形
- /// </summary>
- /// <param name="polygonPointList">不规则形状坐标集合</param>
- /// <returns></returns>
- public static Rectangle GetPolygonToMinRectangle(List<PointF> polygonPointList)
- {
- if (polygonPointList != null)
- {
- if (polygonPointList.Count > 0)
- {
- int pCount = polygonPointList.Count;
- float minX = polygonPointList[0].X;
- float minY = polygonPointList[0].Y;
- float maxX = polygonPointList[0].X;
- float maxY = polygonPointList[0].Y;
- //获取最小X,Y 最大X,Y
- for (int i = 0; i < pCount; i++)
- {
- minX = Math.Min(minX, polygonPointList[i].X);
- minY = Math.Min(minY, polygonPointList[i].Y);
- maxX = Math.Max(maxX, polygonPointList[i].X);
- maxY = Math.Max(maxY, polygonPointList[i].Y);
- }
- //创建外接矩形
- Rectangle rect = new Rectangle();
- rect.Location = new Point((int)minX, (int)minY);
- rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
- return rect;
- }
- }
- return new Rectangle();
- }
- #endregion
-
- #region 获取 Rectangle 外框点集合
- public static Point[] GetRectangleToPoint(RectangleF rectangleF)
- {
- int Left = (int)rectangleF.Left;
- int Top = (int)rectangleF.Top;
- int Right = (int)rectangleF.Right;
- int Bottom = (int)rectangleF.Bottom;
- List<Point> addPoint = new List<Point>();
- for (int i = Left; i <= Right; i++)
- {
- addPoint.Add(new Point(Left + 1, Top));
- }
- for (int i = Top; i <= Bottom; i++)
- {
- addPoint.Add(new Point(Right,Top + 1));
- }
- for (int i = Right; i >= Left; i--)
- {
- addPoint.Add(new Point(Right - 1, Bottom));
- }
- for (int i = Bottom; i >= Top; i--)
- {
- addPoint.Add(new Point(Left,Bottom - 1));
- }
- return addPoint.ToArray();
- }
- #endregion
-
-
-
- }
- }
|