public PerpConstructionLines(PartEntity part, Vector2 line1End, Vector2 line1Start, Vector2 GivenLine1End, Vector2 GivenLine2End, float length, PerpendicularRotation rotation, EntityType type) { this.PartEntity = part; this.EndOfLine = line1End; this.StartOfLine = line1Start; this.GivenLine1End = GivenLine1End; this.GivenLine2End = GivenLine2End; this.LinesLength = length; this.Rotation = rotation; this.EntityType = type; this.UseBezierControlPointsAsRefForLine1 = true; this.UseBezierControlPointsAsRefForLine2 = true; Vector2 given1; Vector2 given2; if (PartEntity != null && PartEntity is PartEntityBezier) { if (UseBezierControlPointsAsRefForLine1) { GivenLine1End = StartOfLine + ((PartEntityBezier)PartEntity).Control1; } if (UseBezierControlPointsAsRefForLine2) { GivenLine2End = EndOfLine + ((PartEntityBezier)PartEntity).Control2; } } given1 = GivenLine1End - StartOfLine; given2 = EndOfLine - GivenLine2End; if (Rotation == PerpendicularRotation.Clockwise) { PerpEndPointStartLine = new Vector2(given1.Y, -given1.X);//clockwise } else { PerpEndPointStartLine = new Vector2(-given1.Y, given1.X);//anticlockwise } if (Rotation == PerpendicularRotation.Clockwise) { PerpEndPointEndLine = new Vector2(given2.Y, -given2.X);//clockwise } else { PerpEndPointEndLine = new Vector2(-given2.Y, given2.X);//anticlockwise } PerpEndPointStartLine = Vector2.Normalize(PerpEndPointStartLine) * LinesLength; PerpEndPointEndLine = Vector2.Normalize(PerpEndPointEndLine) * LinesLength; }
private PerpConstructionLines CalcOffsetPoints(float distance, PerpendicularRotation rotation, EntityType type) { PerpConstructionLines perpConstructionLines = new PerpConstructionLines( End, Start, End, Start, distance, rotation, type ); return(perpConstructionLines); }
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 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 FRectangle AsRotated(PerpendicularRotation rot) { switch (rot) { case PerpendicularRotation.DEGREE_CW_000: case PerpendicularRotation.DEGREE_CW_180: return(this); case PerpendicularRotation.DEGREE_CW_090: case PerpendicularRotation.DEGREE_CW_270: return(new FRectangle( X + Width / 2 - Height / 2, Y - Width / 2 + Height / 2, Height, Width)); default: throw new ArgumentOutOfRangeException(nameof(rot), rot, null); } }
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 List <PerpConstructionLines> AddDefaultSAConstructionLines(float length, PerpendicularRotation rotation, EntityType type) { List <PerpConstructionLines> listOfPerpPoints = new List <PerpConstructionLines>(); List <PartEntity> filtered = GetNormalEntitys(); for (int i = 0; i < filtered.Count; i++) { PartEntity first = filtered[i]; PartEntity second; if (i + 1 < filtered.Count) { second = filtered[i + 1]; } else { second = filtered[0]; } PerpConstructionLines pcl = new PerpConstructionLines(second, second.End, first.End, second.End, first.End, length, rotation, type); listOfPerpPoints.Add(pcl); } return(listOfPerpPoints); }
public override PartEntityOffset CalcOffset(float distance, PerpendicularRotation rotation, EntityType constructionType, EntityType lineType) { throw new NotImplementedException(); }
public abstract PartEntityOffset CalcOffset(float distance, PerpendicularRotation rotation, EntityType constructionType, EntityType lineType);
public PerpConstructionLines(Vector2 line1End, Vector2 line1Start, Vector2 GivenLine1End, Vector2 GivenLine2End, float length, PerpendicularRotation rotation, EntityType type) : this(null, line1End, line1Start, GivenLine1End, GivenLine2End, length, rotation, type) { }