Skip to content

Commit

Permalink
Fix deletion, update tophat
Browse files Browse the repository at this point in the history
  • Loading branch information
vtereshkov committed Feb 23, 2024
1 parent b09ea0a commit 382326f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions editor.um
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ fn (ed: ^Editor) deleteSelectedPoint() {
// Detect polygon containing the point, decrement other point indices
polyToDelete := -1
for polyIndex, poly in ed.polys {
for vertIndex, vert in poly.vert {
if vert == ed.selectedPt {
for _, ptIndex^ in poly.vert {
if ptIndex^ == ed.selectedPt {
polyToDelete = polyIndex
break
} else if vert > ed.selectedPt {
poly.vert[vertIndex]--
} else if ptIndex^ > ed.selectedPt {
ptIndex^--
}
}
}
Expand All @@ -184,22 +184,28 @@ fn (ed: ^Editor) deleteSelectedPoint() {
}

// Delete force associated with the point, decrement other point indices
ed.forces[ed.selectedPt] = th.Vf2{0, 0}
forces := ForceSet{}
for ptIndex, force in ed.forces {
if force.mag() != 0 && ptIndex > ed.selectedPt {
ed.forces[ptIndex] = th.Vf2{0, 0}
ed.forces[ptIndex - 1] = force
if force.mag() == 0 {continue}
if ptIndex < ed.selectedPt {
forces[ptIndex] = force
} else if ptIndex > ed.selectedPt {
forces[ptIndex - 1] = force
}
}
}
ed.forces = forces

// Delete constraint associated with the point, decrement other point indices
ed.constraints[ed.selectedPt] = false
constraints := PointSet{}
for ptIndex, exists in ed.constraints {
if exists && ptIndex > ed.selectedPt {
ed.constraints[ptIndex] = false
ed.constraints[ptIndex - 1] = true
if !exists {continue}
if ptIndex < ed.selectedPt {
constraints[ptIndex] = true
} else if ptIndex > ed.selectedPt {
constraints[ptIndex - 1] = true
}
}
ed.constraints = constraints

// Delete point
ed.pts = delete(ed.pts, ed.selectedPt)
Expand Down
6 changes: 3 additions & 3 deletions fem.um
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ fn getPtDisplacements(unconstrainedDofDisplacements: matrix.Matrix, dofConstrain
displacements := make([]th.Vf2, numPts)

dof := 0
for pt in displacements {
for pt, displacement^ in displacements {
if dofConstraints[2 * pt] {continue}

displacements[pt].x = unconstrainedDofDisplacements[dof][0]
displacements[pt].y = unconstrainedDofDisplacements[dof + 1][0]
displacement.x = unconstrainedDofDisplacements[dof][0]
displacement.y = unconstrainedDofDisplacements[dof + 1][0]

dof += 2
}
Expand Down
2 changes: 1 addition & 1 deletion matrix.um
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type (

fn assert(cond: bool, msg: str = "") {
if !cond {
error("Assertion failed " + msg)
exit(-1, "Assertion failed " + msg)
}
}

Expand Down

0 comments on commit 382326f

Please sign in to comment.