Skip to content

Commit

Permalink
better format & remove redundant realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
imrn99 committed Oct 28, 2024
1 parent bfcae6f commit 89b010f
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions honeycomb-kernels/src/grisubal/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,7 @@ pub(super) fn generate_intersection_data<T: CoordsFloat>(
// trivial case:
// v1 & v2 belong to the same cell
0 => {
//new_segments.insert(
// make_geometry_vertex!(geometry, v1_id),
// make_geometry_vertex!(geometry, v2_id),
//);
[
make_geometry_vertex!(geometry, v1_id),
make_geometry_vertex!(geometry, v2_id)
].windows(2).map(transform
).collect::<Vec<_>>()
vec![(make_geometry_vertex!(geometry, v1_id), make_geometry_vertex!(geometry, v2_id))]
}
// ok case:
// v1 & v2 belong to neighboring cells
Expand Down Expand Up @@ -288,11 +280,10 @@ pub(super) fn generate_intersection_data<T: CoordsFloat>(
let id = i_ids.start;
intersection_metadata[id] = (dart_id, t);

[
make_geometry_vertex!(geometry, v1_id),
GeometryVertex::Intersec(id),
make_geometry_vertex!(geometry, v2_id)
].windows(2).map(transform).collect::<Vec<_>>()
vec![
(make_geometry_vertex!(geometry, v1_id), GeometryVertex::Intersec(id)),
(GeometryVertex::Intersec(id), make_geometry_vertex!(geometry, v2_id)),
]
}
// highly annoying case:
// v1 & v2 do not belong to neighboring cell
Expand Down Expand Up @@ -333,17 +324,23 @@ pub(super) fn generate_intersection_data<T: CoordsFloat>(

GeometryVertex::Intersec(id)
});

// because of how the range is written, we need to reverse the iterator in one case
// to keep intersection ordered from v1 to v2 (i.e. ensure the segments we build are correct)
let mut vs: VecDeque<GeometryVertex> = if i > 0 {
tmp.collect()
} else {
tmp.rev().collect()
};

// complete the vertex list
vs.push_front(make_geometry_vertex!(geometry, v1_id));
vs.push_back(make_geometry_vertex!(geometry, v2_id));
vs.make_contiguous().windows(2).map(transform
).collect::<Vec<_>>()

vs.make_contiguous()
.windows(2)
.map(transform)
.collect::<Vec<_>>()
}
(0, j) => {
// we can solve the intersection equation
Expand Down Expand Up @@ -373,18 +370,23 @@ pub(super) fn generate_intersection_data<T: CoordsFloat>(

GeometryVertex::Intersec(id)
});

// because of how the range is written, we need to reverse the iterator in one case
// to keep intersection ordered from v1 to v2 (i.e. ensure the segments we build are correct)
let mut vs: VecDeque<GeometryVertex> = if j > 0 {
tmp.collect()
} else {
tmp.rev().collect()
};

// complete the vertex list
vs.push_front(make_geometry_vertex!(geometry, v1_id));
vs.push_back(make_geometry_vertex!(geometry, v2_id));
vs.make_contiguous().windows(2).map(transform
).collect::<Vec<_>>()

vs.make_contiguous()
.windows(2)
.map(transform)
.collect::<Vec<_>>()
}
(i, j) => {
// in order to process this, we'll consider a "sub-grid" & use the direction of the segment to
Expand Down Expand Up @@ -472,6 +474,7 @@ pub(super) fn generate_intersection_data<T: CoordsFloat>(
None
})
.collect();

// sort intersections from v1 to v2
intersec_data.retain(|(s, _, _)| (T::zero() <= *s) && (*s <= T::one()));
// panic unreachable because of the retain above; there's no s s.t. s == NaN
Expand All @@ -497,9 +500,12 @@ pub(super) fn generate_intersection_data<T: CoordsFloat>(
GeometryVertex::Intersec(id)
}
}));

vs.push(make_geometry_vertex!(geometry, v2_id));
vs.windows(2).map(transform
).collect::<Vec<_>>()

vs.windows(2)
.map(transform)
.collect::<Vec<_>>()
}
}
}
Expand Down

0 comments on commit 89b010f

Please sign in to comment.