Skip to content

Commit acb6446

Browse files
committed
"fix" wall resize gizmo
1 parent a42916b commit acb6446

File tree

2 files changed

+121
-95
lines changed

2 files changed

+121
-95
lines changed

src/components/wall.rs

+24
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,32 @@ impl Wall for CircWall {
498498
}
499499

500500
fn set_center(&mut self, x: u32, y: u32) {
501+
let x_offset = x as i32 - self.center.x as i32;
502+
let y_offset = y as i32 - self.center.y as i32;
503+
let mut new_resize_point_x = self.resize_point.x as i32 + x_offset;
504+
let mut new_resize_point_y = self.resize_point.y as i32 + y_offset;
505+
501506
self.center.x = x;
502507
self.center.y = y;
508+
509+
if new_resize_point_x < 0 {
510+
new_resize_point_x = (self.radius + self.center.x) as i32;
511+
new_resize_point_y = self.center.y as i32;
512+
} else if new_resize_point_x > 699 {
513+
new_resize_point_x = (self.center.x - self.radius) as i32;
514+
new_resize_point_y = self.center.y as i32;
515+
}
516+
517+
if new_resize_point_y < 0 {
518+
new_resize_point_x = self.center.x as i32;
519+
new_resize_point_y = (self.radius + self.center.y) as i32;
520+
} else if new_resize_point_y > 699 {
521+
new_resize_point_x = self.center.x as i32;
522+
new_resize_point_y = (self.center.y - self.radius) as i32;
523+
}
524+
525+
self.resize_point.x = new_resize_point_x as u32;
526+
self.resize_point.y = new_resize_point_y as u32;
503527
}
504528

505529
fn get_reflection_factor(&self) -> f32 {

src/render/draw.rs

+97-95
Original file line numberDiff line numberDiff line change
@@ -114,107 +114,109 @@ pub fn draw_overlays(
114114
}
115115
}
116116
}
117-
}
118-
}
119-
120-
for wall in circ_walls_overlay.iter() {
121-
let mut b_x = 0i32;
122-
let mut b_y = wall.radius as i32;
123-
let mut d = 1 - wall.radius as i32;
124-
// TODO: don't name this var _thickness_, also it is in px
125-
let thickness = 5;
126-
while b_x <= b_y {
127-
for (x, y, t_x, t_y) in [
128-
(
129-
wall.center.x as i32 + b_x,
130-
wall.center.y as i32 + b_y,
131-
1,
132-
-thickness,
133-
), // 0
134-
(
135-
wall.center.x as i32 + b_x,
136-
wall.center.y as i32 - b_y,
137-
1,
138-
thickness,
139-
), // 1
140-
(
141-
wall.center.x as i32 - b_x,
142-
wall.center.y as i32 + b_y,
143-
1,
144-
-thickness,
145-
), // 2
146-
(
147-
wall.center.x as i32 - b_x,
148-
wall.center.y as i32 - b_y,
149-
1,
150-
thickness,
151-
), // 3
152-
(
153-
wall.center.x as i32 + b_y,
154-
wall.center.y as i32 + b_x,
155-
-thickness,
156-
1,
157-
), // 4
158-
(
159-
wall.center.x as i32 + b_y,
160-
wall.center.y as i32 - b_x,
161-
-thickness,
162-
1,
163-
), // 5
164-
(
165-
wall.center.x as i32 - b_y,
166-
wall.center.y as i32 + b_x,
167-
thickness,
168-
1,
169-
), // 6
170-
(
171-
wall.center.x as i32 - b_y,
172-
wall.center.y as i32 - b_x,
173-
thickness,
174-
1,
175-
), // 7
176-
] {
177-
if x >= 0 && x < SIMULATION_WIDTH as i32 && y >= 0 && y < SIMULATION_HEIGHT as i32 {
178-
// angle in [0, 2pi)
179-
let mut angle = if (y - wall.center.y as i32) <= 0 {
180-
((x as f32 - wall.center.x as f32) / wall.radius as f32).acos()
181-
} else {
182-
TAU - ((x as f32 - wall.center.x as f32) / wall.radius as f32).acos()
183-
};
184-
185-
angle = (angle + wall.rotation_angle.to_radians()) % TAU;
186-
187-
if angle >= wall.open_circ_segment.to_radians() / 2.
188-
&& angle <= TAU - wall.open_circ_segment.to_radians() / 2.
189-
|| !wall.is_hollow
117+
} else {
118+
let mut b_x = 0i32;
119+
let mut b_y = wall.radius as i32;
120+
let mut d = 1 - wall.radius as i32;
121+
// TODO: don't name this var _thickness_, also it is in px
122+
let thickness = 5;
123+
while b_x <= b_y {
124+
for (x, y, t_x, t_y) in [
125+
(
126+
wall.center.x as i32 + b_x,
127+
wall.center.y as i32 + b_y,
128+
1,
129+
-thickness,
130+
), // 0
131+
(
132+
wall.center.x as i32 + b_x,
133+
wall.center.y as i32 - b_y,
134+
1,
135+
thickness,
136+
), // 1
137+
(
138+
wall.center.x as i32 - b_x,
139+
wall.center.y as i32 + b_y,
140+
1,
141+
-thickness,
142+
), // 2
143+
(
144+
wall.center.x as i32 - b_x,
145+
wall.center.y as i32 - b_y,
146+
1,
147+
thickness,
148+
), // 3
149+
(
150+
wall.center.x as i32 + b_y,
151+
wall.center.y as i32 + b_x,
152+
-thickness,
153+
1,
154+
), // 4
155+
(
156+
wall.center.x as i32 + b_y,
157+
wall.center.y as i32 - b_x,
158+
-thickness,
159+
1,
160+
), // 5
161+
(
162+
wall.center.x as i32 - b_y,
163+
wall.center.y as i32 + b_x,
164+
thickness,
165+
1,
166+
), // 6
167+
(
168+
wall.center.x as i32 - b_y,
169+
wall.center.y as i32 - b_x,
170+
thickness,
171+
1,
172+
), // 7
173+
] {
174+
if x >= 0
175+
&& x < SIMULATION_WIDTH as i32
176+
&& y >= 0
177+
&& y < SIMULATION_HEIGHT as i32
190178
{
191-
for cur_x in if t_x > 0 { 0..t_x } else { (t_x + 1)..1 } {
192-
for cur_y in if t_y > 0 { 0..t_y } else { (t_y + 1)..1 } {
193-
let index =
194-
(x + cur_x) as u32 + (y + cur_y) as u32 * SIMULATION_WIDTH;
195-
let r = raw_pixles[index as usize].r;
196-
let g = raw_pixles[index as usize].g;
197-
let b = raw_pixles[index as usize].b;
198-
199-
raw_pixles[index as usize] = Pixel {
200-
r: map_range(0, 255, 100, 175, r as u32) as u8,
201-
g: map_range(0, 255, 80, 80, g as u32) as u8,
202-
b: map_range(0, 255, 80, 80, b as u32) as u8,
203-
a: 255,
204-
};
179+
// angle in [0, 2pi)
180+
let mut angle = if (y - wall.center.y as i32) <= 0 {
181+
((x as f32 - wall.center.x as f32) / wall.radius as f32).acos()
182+
} else {
183+
TAU - ((x as f32 - wall.center.x as f32) / wall.radius as f32).acos()
184+
};
185+
186+
angle = (angle + wall.rotation_angle.to_radians()) % TAU;
187+
188+
if angle >= wall.open_circ_segment.to_radians() / 2.
189+
&& angle <= TAU - wall.open_circ_segment.to_radians() / 2.
190+
|| !wall.is_hollow
191+
{
192+
for cur_x in if t_x > 0 { 0..t_x } else { (t_x + 1)..1 } {
193+
for cur_y in if t_y > 0 { 0..t_y } else { (t_y + 1)..1 } {
194+
let index =
195+
(x + cur_x) as u32 + (y + cur_y) as u32 * SIMULATION_WIDTH;
196+
let r = raw_pixles[index as usize].r;
197+
let g = raw_pixles[index as usize].g;
198+
let b = raw_pixles[index as usize].b;
199+
200+
raw_pixles[index as usize] = Pixel {
201+
r: map_range(0, 255, 100, 175, r as u32) as u8,
202+
g: map_range(0, 255, 80, 80, g as u32) as u8,
203+
b: map_range(0, 255, 80, 80, b as u32) as u8,
204+
a: 255,
205+
};
206+
}
205207
}
206208
}
207209
}
208210
}
209-
}
210211

211-
if d < 0 {
212-
d = d + 2 * b_x + 3;
213-
b_x += 1;
214-
} else {
215-
d = d + 2 * (b_x - b_y) + 5;
216-
b_x += 1;
217-
b_y -= 1;
212+
if d < 0 {
213+
d = d + 2 * b_x + 3;
214+
b_x += 1;
215+
} else {
216+
d = d + 2 * (b_x - b_y) + 5;
217+
b_x += 1;
218+
b_y -= 1;
219+
}
218220
}
219221
}
220222
}

0 commit comments

Comments
 (0)