Skip to content

Commit

Permalink
Merge branch 'master' into rearrange_and_rename_dcel_code
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Nov 12, 2022
2 parents 0ff2da8 + a40e571 commit 5d3f2d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 0 additions & 2 deletions geom/dcel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ func newDCELFromGeometries(a, b Geometry) (*doublyConnectedEdgeList, error) {
dcel.assignFaces()
dcel.populateInSetLabels()

//dumpDCEL(dcel)

return dcel, nil
}

Expand Down
14 changes: 12 additions & 2 deletions geom/dcel_fixup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ func (d *doublyConnectedEdgeList) fixVertices() {
}

func (d *doublyConnectedEdgeList) fixVertex(v *vertexRecord) {
// Sort the edges radially.
// Create slice of incident edges so that they can be sorted radially.
incidents := make([]*halfEdgeRecord, 0, len(v.incidents))
for e := range v.incidents {
incidents = append(incidents, e)
}
if len(incidents) >= 3 {

// If there are 2 or less edges, then the edges are already trivially
// sorted around the vertex with relation to each other.
alreadySorted := len(incidents) <= 2

// Perform the sort.
if !alreadySorted {
// TODO: consider using a solution like
// https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order
// instead of using trigonometry.
sort.Slice(incidents, func(i, j int) bool {
// Sort edges in ascending order of their angle relative to the
// x-axis. This is a stricter sort than necessary but is easy to
// implement. We only really care that the edges are sorted
// relative to each other (we don't care about the starting point).
ei := incidents[i]
ej := incidents[j]
di := ei.seq.GetXY(1).Sub(ei.seq.GetXY(0))
Expand Down

0 comments on commit 5d3f2d6

Please sign in to comment.