aboutsummaryrefslogtreecommitdiff
path: root/src/tool/icon_tool.rs
diff options
context:
space:
mode:
authorArne Dußin2020-11-27 22:55:00 +0100
committerArne Dußin2020-11-27 22:55:00 +0100
commit4c4b57dc24bc36b3091931c9dcc36f6b1894a017 (patch)
tree83f835eb850f249eff2e7694707464c9d4713a69 /src/tool/icon_tool.rs
parent99e935b63bb023cfd46c8f3d81074d3faf7ce592 (diff)
downloadgraf_karto-4c4b57dc24bc36b3091931c9dcc36f6b1894a017.tar.gz
graf_karto-4c4b57dc24bc36b3091931c9dcc36f6b1894a017.zip
Change to f64 as the preferred floating point number
Diffstat (limited to 'src/tool/icon_tool.rs')
-rw-r--r--src/tool/icon_tool.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs
index 4b3a1eb..e972c1c 100644
--- a/src/tool/icon_tool.rs
+++ b/src/tool/icon_tool.rs
@@ -19,9 +19,9 @@ pub const ICON_DIR: &str = "assets/icons";
struct IconFileInfo {
/// The position the icon should be anchored in pixels. This is the Vector it will be moved by
/// relative to the mouse pointer (to the left and up).
- anchor: Vec2<f32>,
+ anchor: Vec2<f64>,
/// The scale of the icon as expressed in image pixels per real meter.
- pixels_per_m: f32,
+ pixels_per_m: f64,
}
#[derive(Clone, Serialize, Deserialize)]
@@ -29,9 +29,9 @@ pub struct IconInfo {
/// The id of the icon is the icons position in the currently loaded icon_data vector.
pub icon_id: usize,
/// The position of the icon on the map, given by the vector in meters.
- pub position: Vec2<f32>,
+ pub position: Vec2<f64>,
/// Rotation of the icon texture in degrees.
- pub rotation: f32,
+ pub rotation: f64,
}
pub struct IconTool {
@@ -132,7 +132,7 @@ impl Tool for IconTool {
) {
// Update the position of the icon that should be drawn to the current mouse position.
let snapped_mouse_pos_m = snap_to_grid(
- transform.point_px_to_m(rl.get_mouse_position().into()),
+ transform.point_px_to_m(&rl.get_mouse_position().into()),
SNAP_SIZE,
);
self.current_icon.position = snapped_mouse_pos_m;
@@ -161,14 +161,14 @@ impl Tool for IconTool {
let (texture, info) = &self.icon_data[icon.icon_id];
// Round the position to whole pixels to fix rotation problems.
let mut position_px =
- transform.point_m_to_px(icon.position - (info.anchor / info.pixels_per_m));
- position_px.x = position_px.x as i32 as f32;
- position_px.y = position_px.y as i32 as f32;
+ transform.point_m_to_px(&(icon.position - (info.anchor / info.pixels_per_m)));
+ position_px.x = position_px.x.floor();
+ position_px.y = position_px.y.floor();
rld.draw_texture_ex(
texture,
position_px,
- icon.rotation,
- transform.pixels_per_m() / info.pixels_per_m,
+ icon.rotation as f32,
+ (transform.pixels_per_m() / info.pixels_per_m) as f32,
Color {
r: 255,
g: 255,
@@ -183,14 +183,14 @@ impl Tool for IconTool {
let (texture, info) = &self.icon_data[self.current_icon.icon_id];
// Round the position to whole pixels to fix rotation problems.
let mut position_px = transform
- .point_m_to_px(self.current_icon.position - (info.anchor / info.pixels_per_m));
- position_px.x = position_px.x as i32 as f32;
- position_px.y = position_px.y as i32 as f32;
+ .point_m_to_px(&(self.current_icon.position - (info.anchor / info.pixels_per_m)));
+ position_px.x = position_px.x.floor();
+ position_px.y = position_px.y.floor();
rld.draw_texture_ex(
texture,
position_px,
- self.current_icon.rotation,
- transform.pixels_per_m() / info.pixels_per_m,
+ self.current_icon.rotation as f32,
+ (transform.pixels_per_m() / info.pixels_per_m) as f32,
Color {
r: 120,
g: 200,