Skip to content

Commit

Permalink
merge upstream main
Browse files Browse the repository at this point in the history
  • Loading branch information
msparkles committed Jan 24, 2024
1 parent c086451 commit 3d2be43
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
25 changes: 12 additions & 13 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ impl HexLayout {
})
}

#[must_use]
/// Computes hexagonal coordinates `hex` into world/pixel coordinates
pub fn hex_to_world_pos(&self, hex: Hex) -> Vec2 {
self.fractional_hex_to_world_pos(hex.as_vec2())
}

#[must_use]
/// Computes fractional hexagonal coordinates `hex` into world/pixel coordinates
pub fn fractional_hex_to_world_pos(&self, hex: Vec2) -> Vec2 {
self.hex_to_center_aligned_world_pos(hex) + self.origin
}

#[allow(clippy::cast_precision_loss)]
#[must_use]
pub(crate) fn hex_to_center_aligned_world_pos(&self, hex: Vec2) -> Vec2 {
Expand All @@ -79,19 +91,6 @@ impl HexLayout {
* self.axis_scale()
}

#[must_use]
/// Computes hexagonal coordinates `hex` into world/pixel coordinates
pub fn hex_to_world_pos(&self, hex: Hex) -> Vec2 {
self.fractional_hex_to_world_pos(vec2(hex.x as f32, hex.y as f32))
}

#[allow(clippy::cast_precision_loss)]
#[must_use]
/// Computes fractional hexagonal coordinates `hex` into world/pixel coordinates
pub fn fractional_hex_to_world_pos(&self, hex: Vec2) -> Vec2 {
self.fractional_hex_to_world_pos(vec2(hex.x as f32, hex.y as f32)) + self.origin
}

#[allow(clippy::cast_precision_loss, clippy::cast_possible_truncation)]
#[must_use]
/// Computes world/pixel coordinates `pos` into fractional hexagonal coordinates
Expand Down
3 changes: 2 additions & 1 deletion src/mesh/column_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ impl<'l> ColumnMeshBuilder<'l> {
.build();
// We store the offset to match the `self.pos`
let pos = if self.center_aligned {
self.layout.hex_to_center_aligned_world_pos(self.pos)
self.layout
.hex_to_center_aligned_world_pos(self.pos.as_vec2())
} else {
self.layout.hex_to_world_pos(self.pos)
};
Expand Down
3 changes: 2 additions & 1 deletion src/mesh/plane_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ impl<'l> PlaneMeshBuilder<'l> {
let mut mesh = MeshInfo::center_aligned_hexagonal_plane(self.layout);
// We store the offset to match the `self.pos`
let pos = if self.center_aligned {
self.layout.hex_to_center_aligned_world_pos(self.pos)
self.layout
.hex_to_center_aligned_world_pos(self.pos.as_vec2())
} else {
self.layout.hex_to_world_pos(self.pos)
};
Expand Down

0 comments on commit 3d2be43

Please sign in to comment.