Skip to content

Commit

Permalink
clean up logic
Browse files Browse the repository at this point in the history
rename variables and remove unecessary steps;
fix error in idsWithinCriterion when skipsMeasure=true
  • Loading branch information
buscandoaverroes committed Apr 15, 2024
1 parent 96fe569 commit c4af4af
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions transform/voxel_around_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ func GetSpatialIdsWithinRadiusOfLine(startPoint *object.Point, endPoint *object.

// the closest.measure object to determine IDs not on the path line but within the criterion distance
var measure1 = closest.Measure{}
// the distances from each SpatialID in uniqueMegaBoxIDs to the route path line
var measureDistances1 []float64
// the slice of Spatial IDs created by combining the result of all adjacent 26 SpatialIDs from all spatialIDs on the route line
var megaBoxIds []string
// the slice of unique Spatial IDs (non-duplicates) from megaBoxIDs
var uniqueMegaBoxIds []string
// the Spatial IDs in uniqueMegaBoxIds with the IDs on the route path line removed
var noLinePathMegaBoxIds []string
// the slice of Spatial Ids from noLinePathMegaBoxIds found within the radius but not on the route line
// the slice of ExtendedSpatialIDs around the Ids on the route line. (returned result already cleaned for duplicates).
var idsAroundVoxcels []string
// the Extended Spatial IDs with the IDs on the route path line removed
var idsAroundLine []string // fix this
// the slice of Extended Spatial Ids from noLinePathIdsAroundLine found within the radius but not on the route line
var idsToAdd []string
// points is the [2]slice / list of startPoint and endPoint in geodesic format (lat/lon)
var points = []*object.Point{startPoint, endPoint}
Expand Down Expand Up @@ -95,20 +91,18 @@ func GetSpatialIdsWithinRadiusOfLine(startPoint *object.Point, endPoint *object.
}

// Return the SpatialIDs within the box created by hLayers and vLayers
megaBoxIds, error = operated.GetNspatialIdsAroundVoxcels(idsOnLine, hLayers, vLayers)
idsAroundVoxcels, error = operated.GetNspatialIdsAroundVoxcels(idsOnLine, hLayers, vLayers)
if error != nil {
return nil, error
}

// Make unique list of spatial ids
uniqueMegaBoxIds = common.Unique(megaBoxIds)

// Subtract the spatial ids in the line
noLinePathMegaBoxIds = common.Difference(uniqueMegaBoxIds, idsOnLine)
// Remove the spatial ids in the line from the ids around the line so that only the ids around the line remain
idsAroundLine = common.Difference(idsAroundVoxcels, idsOnLine)

// if skipsMeasurement=true, measure the distance between the route line and each id in idsAroundLine
if !skipsMeasurement {

for _, id := range noLinePathMegaBoxIds {
for _, id := range idsAroundLine {

// Get 8 vertexes of the SpatialID
IdVertexes, error := shape.GetPointOnExtendedSpatialId(id, enum.Vertex)
Expand Down Expand Up @@ -142,8 +136,6 @@ func GetSpatialIdsWithinRadiusOfLine(startPoint *object.Point, endPoint *object.
// dist is the closest distance between the line (ConvexHull[0]) and the vertexes of Spatial ID[i]
var dist = measure1.Distance

measureDistances1 = append(measureDistances1, dist)

// Since MeasureNonnegativeDistance() was used the distance value in dist
// will always be non-zero. If dist < radius, add the spatialID to idsToAdd
if dist < (radius) {
Expand All @@ -156,7 +148,8 @@ func GetSpatialIdsWithinRadiusOfLine(startPoint *object.Point, endPoint *object.
idsWithinCriterion = common.Unique(common.Union(idsToAdd, idsOnLine))

} else {
idsWithinCriterion = megaBoxIds
// if skipsMeasurement=false, return all ids in noLinePathIdsAroundLine and combine with idsOnLine
idsWithinCriterion = common.Unique(common.Union(idsAroundLine, idsOnLine))
}

return idsWithinCriterion, nil
Expand Down

0 comments on commit c4af4af

Please sign in to comment.