The complexity of my last post bothered me a bit, so I thought about it a little more :
The LineSegment2d derives from LineEntity2d which has a Direction property which is a Vector2d.
and ,
The Vector2d Method v1.IsEqualTo(v2) defaults to using Tolerance.Global.EqualVector so I didn't need to include the Tolerance parameter in the call.
Not needing to create 2 new Vector2d's and a new Tolerance cleaned up the functionality considerably.
. . . in effect , to a simple one-line statement.
This means the code actually doing the work can be reduced to :
bool result = pline.GetLineSegment2dAt(firstIndex).Direction.IsEqualTo(
pline.GetLineSegment2dAt(lastIndex).Direction.Negate());
and the full transaction can now be :
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Polyline pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
var firstIndex = 0;
var lastIndex = 2;
bool result = pline.GetLineSegment2dAt(firstIndex).Direction.IsEqualTo(
pline.GetLineSegment2dAt(lastIndex).Direction.Negate());
ed.WriteMessage(
$"{(result ? "Legs same direction" : "Legs Different direction")}\n");
tr.Commit();
}
This, of course, assumes the orientation of the legs is intended to be 'parallel' ie extending in the same direction, equidistant at all points, and never converging or diverging, not just on the same side of the center segment.
Regards,
// Called Kerry or kdub in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub
NZST UTC+12 : class keyThumper<T> : Lazy<T>; another Swamper