public static ValueTuple <DoubleDestructibleLineSegment, DoubleDestructibleLineSegment> Split(DoubleDestructibleLineSegment a, Vec2 point, float size) { var split1 = DestructibleLineSegment.Split(a.SideA, point, size); var split2 = DestructibleLineSegment.Split(a.SideB, point, size); DoubleDestructibleLineSegment lineLeft; DoubleDestructibleLineSegment lineRight; if (split1.Item1 == null || split2.Item2 == null) { lineLeft = null; } else { lineLeft = new DoubleDestructibleLineSegment(split1.Item1.Start, split1.Item1.End, split1.Item1.Color, split1.Item1.LineWidth); } if (split1.Item2 == null || split2.Item1 == null) { lineRight = null; } else { lineRight = new DoubleDestructibleLineSegment(split1.Item2.Start, split1.Item2.End, split1.Item2.Color, split1.Item2.LineWidth); } return(ValueTuple.Create(lineLeft, lineRight)); }
public DoubleDestructibleLineSegment(Vec2 start, Vec2 end, uint color = 0xffffffff, uint lineWidth = 1) { SideA = new DestructibleLineSegment(start, end, 0xffff0000, lineWidth); SideB = new DestructibleLineSegment(end, start, 0xff0000ff, lineWidth); AddChild(SideA); AddChild(SideB); StartCollider = new CircleCollider(0, start, true); EndCollider = new CircleCollider(0, end, true); AddChild(StartCollider); AddChild(EndCollider); }
public static ValueTuple <DestructibleLineSegment, DestructibleLineSegment> Split(DestructibleLineSegment a, Vec2 point, float size) { var line1Start = a.Start; var line1Vector = point - line1Start; var line1Length = line1Vector.magnitude - size; line1Vector = line1Vector.normalized * line1Length; var line1End = line1Start + line1Vector; DestructibleLineSegment line1 = null; if (line1Length >= Globals.World.DestructibleLineMinLength) { line1 = new DestructibleLineSegment(line1Start, line1End, a.Color, a.LineWidth); } var line2End = a.End; var line2Vector = point - line2End; var line2Length = line2Vector.magnitude - size; line2Vector = line2Vector.normalized * line2Length; var line2Start = line2End + line2Vector; DestructibleLineSegment line2 = null; if (line2Length >= Globals.World.DestructibleLineMinLength) { line2 = new DestructibleLineSegment(line2Start, line2End, a.Color, a.LineWidth); } if ((line1End - line1Start).sqrMagnitude <= Globals.World.DestructibleLineMinLength * Globals.World.DestructibleLineMinLength) { line1 = null; } if ((line2End - line2Start).sqrMagnitude <= Globals.World.DestructibleLineMinLength * Globals.World.DestructibleLineMinLength) { line2 = null; } return(ValueTuple.Create(line1, line2)); }