public static Vector2 CalcIntersection(PartEntityLine line1, PartEntityLine line2) { Vector2 a = line1.End - line1.Start; Vector2 b = line2.Start - line2.End; Vector2 intersection = CalcIntersection(a, line1.Start, b, line2.End); return(intersection); }
public PartEntityLine AddLineEntity(Vector2 start, Vector2 end, EntityType type = EntityType.Normal) { PartEntityLine entity = new PartEntityLine() { Start = start, End = end, EntityType = type }; Entities.Add(entity); return(entity); }
public PartEntityLine AddLineEntity(LineDirection direction, Vector2 start, float length, EntityType type = EntityType.Normal) { PartEntityLine entity = new PartEntityLine() { Start = start, End = Utils.CalcEnd(start, length, direction), EntityType = type }; Entities.Add(entity); return(entity); }
public PartEntityLine AddLineEntity(Vector2 start, float length, float angle, EntityType type = EntityType.Normal) { PartEntityLine entity = new PartEntityLine() { Start = start, End = Utils.CalcEnd(start, length, angle), EntityType = type }; Entities.Add(entity); return(entity); }
public PartEntityLine AddLineEntity(float length, float angle, EntityType type = EntityType.Normal) { PartEntityLine entity = new PartEntityLine() { Start = Entities.Last().End, End = Utils.CalcEnd(Entities.Last().End, length, angle), EntityType = type }; Entities.Add(entity); return(entity); }
public override PartEntityOffset CalcOffset(float distance, PerpendicularRotation rotation, EntityType constructionType, EntityType lineType) { List <PerpConstructionLines> points = CalcOffsetPoints(distance, rotation, constructionType); List <PartEntityLine> result = new List <PartEntityLine>(); for (int i = 0; i < points.Count; i++) { PerpConstructionLines point = points[i]; //perpendicular construction lines from origional line PartEntityLine lineStart = new PartEntityLine() { Start = point.StartOfLine, End = point.StartOfLine + point.PerpEndPointStartLine, EntityType = constructionType }; PartEntityLine lineEnd = new PartEntityLine() { Start = point.EndOfLine, End = point.EndOfLine + point.PerpEndPointEndLine, EntityType = constructionType }; result.Add(lineStart); result.Add(lineEnd); //line between construction start line and end line result.Add(new PartEntityLine() { Start = point.StartOfLine + point.PerpEndPointStartLine, End = point.EndOfLine + point.PerpEndPointEndLine, EntityType = lineType }); } //project to intersecions or trim to intersection List <PartEntityLine> saLines = result.Where(x => x.EntityType == lineType).ToList(); for (int i = 0; i < saLines.Count; i++) { PartEntityLine line = saLines[i]; if (i + 1 < saLines.Count) { PartEntityLine lineNext = saLines[i + 1]; Vector2 intersection = Utils.CalcIntersection(line, lineNext); //TODO: check this logic if (intersection != Vector2.Zero) { if (!float.IsNaN(intersection.X) && !float.IsNaN(intersection.Y)) { line.End = intersection; lineNext.Start = intersection; } } } //System.Diagnostics.Debug.WriteLine("[" + i + "] " + line.ToString()); } return(new PartEntityOffset(result)); }
private void BuildGrainLine() { int arrowLength = 10; PartEntityLine line1 = new PartEntityLine() { EntityType = EntityType.GrainLine, }; if (((PartEntityText)Entities[0]).Rotation == -90) { line1.Start = Start + Utils.Right(5); line1.End = End + Utils.Right(5); } else { line1.Start = Start + Utils.Left(5); line1.End = End + Utils.Left(5); } Entities.Add(line1); PartEntityLine line2 = new PartEntityLine() { Start = line1.End, End = line1.End + Utils.Left(arrowLength) + Utils.Down(arrowLength), EntityType = EntityType.GrainLine, }; Entities.Add(line2); PartEntityLine line3 = new PartEntityLine() { Start = line1.End, End = line1.End + Utils.Right(arrowLength) + Utils.Down(arrowLength), EntityType = EntityType.GrainLine, }; Entities.Add(line3); PartEntityLine line4 = new PartEntityLine() { Start = line2.End, End = line3.End, EntityType = EntityType.GrainLine, }; Entities.Add(line4); }
private static void Intersect(PartEntityOffset offsetLine1, PartEntityOffset offsetLine2, EntityType type) { List <PartEntityLine> firstLinesSA = offsetLine1.Lines.Where(x => x.EntityType != type).ToList(); List <PartEntityLine> secondLinesSA = offsetLine2.Lines.Where(x => x.EntityType != type).ToList(); PartEntityLine firstLineSA = firstLinesSA.Last(); PartEntityLine secondLineSA = secondLinesSA.First(); Vector2 intersection = Utils.CalcIntersection(firstLineSA, secondLineSA); if (intersection != Vector2.Zero) { if (!float.IsNaN(intersection.X) && !float.IsNaN(intersection.Y)) { firstLineSA.End = intersection; secondLineSA.Start = intersection; } } }
private List <PerpConstructionLines> CalcOffsetPoints(float distance, PerpendicularRotation rotation, EntityType type) { List <PerpConstructionLines> result = new List <PerpConstructionLines>(); for (int i = 0; i < Lines.Count; i++) { PartEntityLine line = Lines[i]; PerpConstructionLines perpConstructionLines = new PerpConstructionLines( line.End, line.Start, line.End, line.Start, distance, rotation, type ); result.Add(perpConstructionLines); } return(result); }
public override PartEntityOffset CalcOffset(float distance, PerpendicularRotation rotation, EntityType constructionType, EntityType lineType) { List <PartEntityLine> result = new List <PartEntityLine>(); PerpConstructionLines point = CalcOffsetPoints(distance, rotation, constructionType); //perpendicular construction lines from origional line PartEntityLine lineStart = new PartEntityLine() { Start = point.StartOfLine, End = point.StartOfLine + point.PerpEndPointStartLine, EntityType = constructionType }; PartEntityLine lineEnd = new PartEntityLine() { Start = point.EndOfLine, End = point.EndOfLine + point.PerpEndPointEndLine, EntityType = constructionType }; result.Add(lineStart); result.Add(lineEnd); //line between construction start line and end line result.Add(new PartEntityLine() { Start = point.StartOfLine + point.PerpEndPointStartLine, End = point.EndOfLine + point.PerpEndPointEndLine, EntityType = lineType }); return(new PartEntityOffset(result)); }
public PartEntityMeasurements(Vector2 startFirst, List <MeasurmentText> measurements) { Entities = new List <PartEntity>(); EntityType = EntityType.Text; Vector2 start = startFirst; PartExtents boundsFirst = new PartExtents(); float paddingBetweenLines = 3f; foreach (MeasurmentText line in measurements) { PartExtents bounds = Utils.CalcFontSizeBounds(line.TextSize, line.Text, "Arial"); if (boundsFirst.IsEmpty()) { boundsFirst.Copy(bounds); } start += Utils.Down(bounds.Height + paddingBetweenLines); PartEntityText entityText = new PartEntityText() { Start = start, End = start + Utils.Right(bounds.Width), Text = line.Text, IsItalic = line.IsItalic, IsBold = line.IsBold, TextSize = line.TextSize, EntityType = EntityType.Text, ShowBoundingFrame = false, }; Entities.Add(entityText); } PartExtents extents = PartExtents.CalcPartExtents(Entities); Start = new Vector2(extents.MinX, extents.MinY); End = new Vector2(extents.MaxX, extents.MaxY); float padding = 10f; PartEntityLine line1 = new PartEntityLine() { Start = Start + Utils.Up(boundsFirst.Height + paddingBetweenLines) + Utils.Left(padding / 2) + Utils.Up(padding / 2), End = Start + Utils.Up(boundsFirst.Height + paddingBetweenLines) + Utils.Right(extents.Width) + Utils.Right(padding / 2) + Utils.Up(padding / 2), EntityType = EntityType.MeasurementLine, }; Entities.Add(line1); PartEntityLine line2 = new PartEntityLine() { Start = line1.End, End = line1.End + Utils.Down(extents.Height + boundsFirst.Height + paddingBetweenLines) + Utils.Down(padding), EntityType = EntityType.MeasurementLine, }; Entities.Add(line2); PartEntityLine line3 = new PartEntityLine() { Start = line2.End, End = line2.End + Utils.Left(extents.Width) + Utils.Left(padding), EntityType = EntityType.MeasurementLine, }; Entities.Add(line3); PartEntityLine line4 = new PartEntityLine() { Start = line3.End, End = line1.Start, EntityType = EntityType.MeasurementLine, }; Entities.Add(line4); extents = PartExtents.CalcPartExtents(Entities); Start = new Vector2(extents.MinX, extents.MinY); End = new Vector2(extents.MaxX, extents.MaxY); }