ManevilleF / hexx

Hexagonal tools lib in rust
Apache License 2.0
276 stars 22 forks source link

Grid edges and vertices #154

Closed ManevilleF closed 4 months ago

ManevilleF commented 4 months ago

Adresses #153

ManevilleF commented 4 months ago

@f-hoenix Thanks for the feedback, I see the problem with the offset, I'll fix it once I have merged #156 and add tests and an example reproducing this use case

f-hoenix commented 4 months ago

Sorry didn't have the chance to review the PR In any case it's working just fine 👍

ManevilleF commented 4 months ago

Sorry didn't have the chance to review the PR In any case it's working just fine 👍

Glad to hear it, the implementation is still young so don't hesitate opening follow up issues or PRs

f-hoenix commented 4 months ago

Mmmh I still have something weird that I did not notice I had this code to draw an 'area'

    pub fn draw_borders(
        self: &Self,
        layout: &HexLayout,
        gizmos: &mut Gizmos,
        color: Color,
    ) {
        for edge in self.edges.iter() {
            let vertices = layout.edge_coordinates(edge.rotate_ccw(1));      // <<<< Notice the rotate
            draw_gizmo_between_vec2(gizmos, vertices[0], vertices[1], color);
        }
    }

Result : image

If I remove the rotate: image

No issue when using flat layout

I don't think the issue is in the code that creates the edges of an area (group of hexes) because it's layout agnostic:

    pub fn recalculate_edges(self: &mut Self) {
        self.edges = HashSet::new();
        for tile in &self.tiles {
            for n in tile.all_neighbors() {
                if !self.tiles.contains(&n) {
                    let direction = tile.neighbor_direction(n).unwrap();
                    self.edges.insert(GridEdge { origin: *tile, direction });
                }
            }
        }
    }
ManevilleF commented 4 months ago

Probably an error in the angle calculation in pointy layout, I'll try to reproduce in an example and fix it before release

ManevilleF commented 4 months ago

@f-hoenix I could reproduce the issue:

Screenshot 2024-03-25 at 10 58 03

This new example and the associated fix will be part of #157

f-hoenix commented 4 months ago

Awesome !