Skip to content

Commit 08f7a04

Browse files
committed
fix anchor generation and UI updates
1 parent 6a83ef2 commit 08f7a04

File tree

6 files changed

+215
-177
lines changed

6 files changed

+215
-177
lines changed

string-bean-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ path = "src/main.rs"
1111
clap = { version = "4.3.19", features = ["derive"] }
1212
image = "0.24.6"
1313
string-bean = { path = "../string-bean" }
14-
line_drawing = "1.0.0"

string-bean-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> Result<(), std::io::Error> {
4141
.map(|angle| {
4242
(
4343
x_mid as f64 + radius * angle.cos(),
44-
y_mid as f64 * radius * angle.sin(),
44+
y_mid as f64 + radius * angle.sin(),
4545
)
4646
})
4747
.collect();

string-bean-wasm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
string-bean = { path = "../string-bean" }
1313
wasm-bindgen = "0.2.87"
14-
line_drawing = "1.0.0"

string-bean-wasm/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
22

3-
use line_drawing::XiaolinWu;
4-
53
#[wasm_bindgen]
64
pub fn plan_as_json(
75
line_count: u32,
@@ -15,12 +13,15 @@ pub fn plan_as_json(
1513
image_buffer: &[u8],
1614
start_anchor: usize,
1715
) -> JsValue {
16+
let (x_mid, y_mid) = (width / 2, height / 2);
17+
let radius = radius.min(x_mid.min(y_mid)) as f64;
18+
1819
let anchors: Vec<_> = (0..anchor_count)
1920
.map(|anchor| anchor as f64 * 2.0 * std::f64::consts::PI / anchor_count as f64)
2021
.map(|angle| {
2122
(
22-
radius as f64 * (1.0 + angle.cos()),
23-
radius as f64 * (1.0 + angle.sin()),
23+
x_mid as f64 + radius * angle.cos(),
24+
y_mid as f64 + radius * angle.sin(),
2425
)
2526
})
2627
.collect();
@@ -49,6 +50,7 @@ pub fn plan_as_json(
4950
.join(","),
5051
))
5152
}
53+
5254
/// https://playtechs.blogspot.com/2007/03/raytracing-on-grid.html
5355
fn grid_raytrace(
5456
x0: f64,

string-bean/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ where
109109
/// Apply changes from a line, persisting the pixel changes to the image
110110
fn apply_line(&mut self, src: FPos, dst: FPos) {
111111
for ((x, y), intensity) in self.trace_line(src, dst) {
112-
self.image_mask_inverted[x + y * self.image_height] -= self.line_weight;
112+
self.image_mask_inverted[x + y * self.image_height] -= intensity * self.line_weight;
113113
}
114114
}
115115

@@ -126,7 +126,7 @@ where
126126
let line_penalty: Precision = line
127127
.into_iter()
128128
.map(|((x, y), intensity)| {
129-
self.image_mask_inverted[x + y * self.image_height] - self.line_weight
129+
self.image_mask_inverted[x + y * self.image_height] - intensity * self.line_weight
130130
})
131131
.map(|p| match p < 0.0 {
132132
true => -self.lightness_penalty * p,

0 commit comments

Comments
 (0)