public bool Join(SlicePart other) { if (Closed) { return(false); } if (LastPoint.Near(other.FirstPoint)) { bool closing = FirstPoint.Near(other.LastPoint); int start = 1; int count = closing ? other.Points.Count - 1 : other.Points.Count; Normals[Normals.Count - 1] = other.Normals[0]; for (int i = start; i < count; i++) { Append(other.Points[i], other.Normals[i]); } Closed = closing; return(true); } if (LastPoint.Near(other.LastPoint)) { bool closing = FirstPoint.Near(other.FirstPoint); int end = closing ? 1 : 0; Normals[Normals.Count - 1] = other.Normals[other.Normals.Count - 1]; for (int i = other.Points.Count - 2; i >= end; i--) { Append(other.Points[i], other.Normals[i]); } Closed = closing; return(true); } if (FirstPoint.Near(other.LastPoint)) { bool closing = LastPoint.Near(other.FirstPoint); int end = closing ? 1 : 0; for (int i = other.Points.Count - 2; i >= end; i--) { Insert(0, other.Points[i], other.Normals[i]); } Closed = closing; return(true); } if (FirstPoint.Near(other.FirstPoint)) { bool closing = LastPoint.Near(other.LastPoint); int start = 1; int count = closing ? other.Points.Count - 1 : other.Points.Count; for (int i = start; i < count; i++) { Insert(0, other.Points[i], other.Normals[i]); } Closed = closing; return(true); } return(false); }
public SlicePart Clone() { SlicePart result = new SlicePart(); result.Points.AddRange(Points); result.Normals.AddRange(Normals); result.Closed = Closed; return(result); }
public SlicePart GetZPlane(float z) { SlicePart result = new SlicePart(); foreach (Vector3 point in Points) { result.Points.Add(new Vector3(point.X, point.Y, z)); } result.Normals.AddRange(Normals); result.Closed = Closed; return(result); }
public void AddSection(Vector3 first, Vector3 second, Vector3 normal = new Vector3()) { foreach (SlicePart part in Parts) { if (part.AddSection(first, second, normal)) { return; } } SlicePart newPart = new SlicePart(); newPart.AddSection(first, second, normal); Parts.Add(newPart); }
public SlicePart Transform(Matrix3 matrix) { SlicePart result = new SlicePart(); foreach (Vector3 point in Points) { result.Points.Add(Vector3.Transform(point, matrix)); } foreach (Vector3 normal in Normals) { result.Normals.Add(Vector3.Transform(normal, matrix).Normalized()); } result.Closed = Closed; return(result); }
public SlicePart Expand(SlicePart part, float distance) { SlicePart result = new SlicePart(); result.Closed = part.Closed; result.Normals.AddRange(part.Normals); for (int i = 0; i < part.Points.Count; i++) { int prevIndex = i == 0 ? part.Points.Count - 1 : i - 1; Vector2 prevNormal = part.Normals[prevIndex].Xy.Normalized(); Vector2 currentNormal = part.Normals[i].Xy.Normalized(); Vector3 expandBy = new Vector3((prevNormal + currentNormal) * distance); result.Points.Add(part.Points[i] + expandBy); } return(result); }
public void Join() { for (int i = Parts.Count - 1; i > 0; i--) { SlicePart partToJoin = Parts[i]; if (partToJoin.Closed) { continue; } for (int j = i - 1; j >= 0; j--) { SlicePart part = Parts[j]; if (part.Join(partToJoin)) { Parts.RemoveAt(i); break; } } } }