#if ACAD24 using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Colors; using AcAp = Autodesk.AutoCAD.ApplicationServices; #elif BCAD using Bricscad.EditorInput; using Teigha.Geometry; using Teigha.DatabaseServices; using Teigha.Colors; using AcAp = Bricscad.ApplicationServices; #endif using System; using System.Collections.Generic; namespace Boprs { /// /// Simple closed polygon. /// public class Contour : ICloneable { public object Clone() { return new Contour() { Vertices = new List(Vertices) }; } /// /// Vertices of the contour. /// public List Vertices { get; private set; } /// /// Are the vertices of the contour arranged in clockwise manner? /// /// true if the contour is clockwise, false if counter-clockwise. public bool IsClockwise() { double areaSum = 0; // Go through all the vertices. for (int i = 0; i < Vertices.Count; i++) { // Get current vertex Point2d p0 = Vertices[i]; // Get the next vertex Point2d p1 = Vertices[(i + 1) % Vertices.Count]; // Compute the area under the trapezoid made by the current segment. // Note that this is actually double the proper value, but we only care about its relation to 0. areaSum += (p1.X - p0.X) * (p1.Y + p0.Y); } return areaSum > 0; } /// /// Reverse the orientation of the contour. /// public void Reverse() { Vertices.Reverse(); } /// /// Constructor. /// public Contour() { Vertices = new List(); } #if DEBUG internal void Draw(Color color = null) { AcAp.Document acDoc = AcAp.Application.DocumentManager.MdiActiveDocument; Database acDb = acDoc.Database; using (Transaction acTrans = acDb.TransactionManager.StartTransaction()) { // Open the BlockTableRecord BlockTable acBlkTbl = (BlockTable)acTrans.GetObject(acDb.BlockTableId, OpenMode.ForRead); BlockTableRecord acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite); for(int i = 0; i < Vertices.Count; i++) { Line asLine = new Line(Vertices[i].To3d(), Vertices[(i + 1) % Vertices.Count].To3d()); acBlkTblRec.AppendEntity(asLine); acTrans.AddNewlyCreatedDBObject(asLine, true); } acTrans.Commit(); } } #endif } }