Skip to content

Commit 1b5036a

Browse files
iscgarruevs
authored andcommitted
split: fix line splitting to avoid creating zero length line segments
When an endpoint of a line intersects another entity, line splitting creates two segments with one of them having zero length, unnecessarily discarding all constraints on it in the process as well. Change the behaviour to not split the line in that case, and instead just use the intersecting endpoint for the new coincident constraint.
1 parent 960f08b commit 1b5036a

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

src/modify.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@ hEntity GraphicsWindow::SplitLine(hEntity he, Vector pinter) {
448448
Vector p0 = SK.GetEntity(hep0)->PointGetNum(),
449449
p1 = SK.GetEntity(hep1)->PointGetNum();
450450

451+
if(p0.Equals(pinter)) {
452+
return hep0;
453+
}
454+
455+
if(p1.Equals(pinter)) {
456+
return hep1;
457+
}
458+
451459
// Add the two line segments this one gets split into.
452460
hRequest r0i = AddRequest(Request::Type::LINE_SEGMENT, /*rememberForUndo=*/false),
453461
ri1 = AddRequest(Request::Type::LINE_SEGMENT, /*rememberForUndo=*/false);
@@ -582,7 +590,6 @@ hEntity GraphicsWindow::SplitCubic(hEntity he, Vector pinter) {
582590

583591
hEntity GraphicsWindow::SplitEntity(hEntity he, Vector pinter) {
584592
Entity *e = SK.GetEntity(he);
585-
Entity::Type entityType = e->type;
586593

587594
hEntity ret;
588595
if(e->IsCircle()) {
@@ -597,22 +604,20 @@ hEntity GraphicsWindow::SplitEntity(hEntity he, Vector pinter) {
597604
}
598605

599606
// Finally, delete the request that generated the original entity.
600-
Request::Type reqType = EntReqTable::GetRequestForEntity(entityType);
601-
SK.request.ClearTags();
602-
for(auto &r : SK.request) {
603-
if(r.group != activeGroup)
604-
continue;
605-
if(r.type != reqType)
606-
continue;
607-
608-
// If the user wants to keep the old entities around, they can just
609-
// mark them construction first.
610-
if(he == r.h.entity(0) && !r.construction) {
611-
r.tag = 1;
612-
break;
607+
if(he.isFromRequest() && he == he.request().entity(0)) {
608+
hRequest hr = he.request();
609+
// Only delete the original request if we actually made a split
610+
// (i.e. the split point is not from the original request)
611+
if(hr != ret.request()) {
612+
Request *r = SK.GetRequest(hr);
613+
// If the user wants to keep the old entities around, they can just
614+
// mark them construction first.
615+
if(r->group == activeGroup && !r->construction) {
616+
r->tag = 1;
617+
DeleteTaggedRequests();
618+
}
613619
}
614620
}
615-
DeleteTaggedRequests();
616621

617622
return ret;
618623
}

0 commit comments

Comments
 (0)