1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use imageproc::drawing::{draw_hollow_rect_mut, draw_line_segment_mut, Canvas};
use crate::factorio::util::{
scaled_draw_rect, vector_add, vector_multiply, vector_normalize, vector_substract,
};
use crate::graph::entity_graph::{BlockedQuadTree, ResourceQuadTree};
use crate::types::{Position, Rect};
use parking_lot::RwLockReadGuard;
use std::collections::HashMap;
#[allow(clippy::clone_on_copy, clippy::cast_lossless)]
pub fn arrow_mut<C>(canvas: &mut C, start: (f32, f32), end: (f32, f32), color: C::Pixel, size: f64)
where
C: Canvas,
C::Pixel: 'static,
{
draw_line_segment_mut(canvas, start, end, color.clone());
if size > 1. {
let h = size * 3.0_f64.sqrt();
let w = size.clone();
let start_position = Position::new(start.0.clone() as f64, start.1.clone() as f64);
let end_position = Position::new(end.0.clone() as f64, end.1.clone() as f64);
let u = vector_normalize(&vector_substract(&end_position, &start_position));
let vw = vector_multiply(&Position::new(-u.y(), u.x()), w);
let vv = vector_substract(&end_position, &vector_multiply(&u, h));
let v1 = vector_add(&vv, &vw);
let v2 = vector_substract(&vv, &vw);
draw_line_segment_mut(
canvas,
end.clone(),
(v1.x() as f32, v1.y() as f32),
color.clone(),
);
draw_line_segment_mut(
canvas,
end.clone(),
(v2.x() as f32, v2.y() as f32),
color.clone(),
);
draw_line_segment_mut(
canvas,
(v1.x() as f32, v1.y() as f32),
(v2.x() as f32, v2.y() as f32),
color.clone(),
);
}
}
#[allow(clippy::clone_on_copy, clippy::cast_lossless)]
pub fn draw_blocked_rects_mut<C>(
canvas: &mut C,
blocked: RwLockReadGuard<BlockedQuadTree>,
bounding_box: &Rect,
scaling_factor: f64,
color_mineable: C::Pixel,
color_unmineable: C::Pixel,
) where
C: Canvas,
C::Pixel: 'static,
{
for (minable, rect, _id) in blocked.query(bounding_box.clone().into()) {
if let Some(draw_rect) = scaled_draw_rect(bounding_box, rect, scaling_factor.clone()) {
draw_hollow_rect_mut(
canvas,
draw_rect,
if *minable {
color_mineable.clone()
} else {
color_unmineable.clone()
},
);
}
}
}
#[allow(clippy::clone_on_copy)]
pub fn draw_resource_rects_mut<C>(
canvas: &mut C,
resources: RwLockReadGuard<ResourceQuadTree>,
bounding_box: &Rect,
scaling_factor: f64,
colors: HashMap<&str, C::Pixel>,
invalid_color: C::Pixel,
) where
C: Canvas,
C::Pixel: 'static,
{
for (name, rect, _id) in resources.query(bounding_box.clone().into()) {
if let Some(draw_rect) = scaled_draw_rect(bounding_box, rect, scaling_factor.clone()) {
draw_hollow_rect_mut(
canvas,
draw_rect,
colors.get(name.as_str()).unwrap_or(&invalid_color).clone(),
);
}
}
}