1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /*-------------------------------------------------------------------------
- * 功能描述:Polygon
- * 作者:xulisong
- * 创建时间: 2019/4/29 17:37:09
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using SAGA.RevitUtils.Extends;
- namespace SAGA.RevitUtils.Utils
- {
- public class Polygon : IEnumerable<XYZ>
- {
- private List<XYZ> m_Points;
- public Polygon(List<XYZ> points)
- {
- if (points.Count < 3)
- {
- throw new ArgumentException($"{nameof(points)}数量不能小于3");
- }
- m_Points = (points ?? new List<XYZ>()).Select(xyz=>xyz.NewZ()).ToList();
- Points = new ReadOnlyCollection<XYZ>(m_Points);
- }
- /// <summary>
- /// 关联逆时针点(最后一个点和第一个点封闭)
- /// </summary>
- public ReadOnlyCollection<XYZ> Points { get; private set; }
- #region 实现遍历方法
- public IEnumerator<XYZ> GetEnumerator()
- {
- return ((IEnumerable<XYZ>)m_Points).GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable<XYZ>)m_Points).GetEnumerator();
- }
- #endregion
- #region 子凸多边形
- private ReadOnlyCollection<Polygon> m_ChildrenConvexPolygons;
- /// <summary>
- /// 分解的子凸多边形
- /// </summary>
- public ReadOnlyCollection<Polygon> ChildrenConvexPolygons
- {
- get
- {
- if (m_ChildrenConvexPolygons == null)
- {
- var polygons = PolygonUtil.SplitToConvexPolygons(this);
- m_ChildrenConvexPolygons = new ReadOnlyCollection<Polygon>(polygons);
- }
- return m_ChildrenConvexPolygons;
- }
- }
- #endregion
- private Outline m_Box;
- /// <summary>
- /// 多边形包围盒
- /// </summary>
- public Outline Box
- {
- get
- {
- if (m_Box == null)
- {
- m_Box = OutlineUtil.CreateBox(this.m_Points);
- }
- return m_Box;
- }
- }
-
- }
- }
|