mirror of
https://gitlab.kit.edu/uskyk/kv.git
synced 2024-11-24 18:05:03 +00:00
Fancy SVG display
This commit is contained in:
parent
900541c05f
commit
d130341176
@ -14,19 +14,20 @@ const COLORS: &'static [Color] = &[
|
|||||||
];
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let vars = [A, B, C];
|
||||||
let function = vec![0, 0, 1, 1, 1, 1, 1, 0].into_iter().map(Into::into).collect();
|
let function = vec![0, 0, 1, 1, 1, 1, 1, 0].into_iter().map(Into::into).collect();
|
||||||
let groups = find_groups(&function, &[A, B, C], One);
|
let groups = find_groups(&function, &vars, One);
|
||||||
eprintln!("all:");
|
eprintln!("all:");
|
||||||
for x in &groups {
|
for x in &groups {
|
||||||
eprintln!("{}", print_implicant(x));
|
eprintln!("{}", print_implicant(x));
|
||||||
}
|
}
|
||||||
eprintln!("prime:");
|
eprintln!("prime:");
|
||||||
let prime = find_prime(&function, &[A, B, C], One, &groups);
|
let prime = find_prime(&function, &vars, One, &groups);
|
||||||
for x in &prime {
|
for x in &prime {
|
||||||
eprintln!("{}", print_implicant(x));
|
eprintln!("{}", print_implicant(x));
|
||||||
}
|
}
|
||||||
eprintln!("solutions:");
|
eprintln!("solutions:");
|
||||||
let solutions = all_solutions(function.clone(), &[A, B, C], One, &prime, &groups);
|
let solutions = all_solutions(function.clone(), &vars, One, &prime, &groups);
|
||||||
for sol in solutions {
|
for sol in solutions {
|
||||||
for x in &prime {
|
for x in &prime {
|
||||||
eprint!("{} | ", print_implicant(x));
|
eprint!("{} | ", print_implicant(x));
|
||||||
@ -43,7 +44,7 @@ fn main() {
|
|||||||
|
|
||||||
let (grid, w, h) = grid(3);
|
let (grid, w, h) = grid(3);
|
||||||
println!("{}", BeginSvg { w: w * SIZE_FACTOR + 3, h: h * SIZE_FACTOR + 3 });
|
println!("{}", BeginSvg { w: w * SIZE_FACTOR + 3, h: h * SIZE_FACTOR + 3 });
|
||||||
for (i, (x, y)) in grid.iter().enumerate() {
|
for (i, &(x, y)) in grid.iter().enumerate() {
|
||||||
println!("{}",
|
println!("{}",
|
||||||
rectangle(1 + x * SIZE_FACTOR, 1 + y * SIZE_FACTOR, SIZE_FACTOR, SIZE_FACTOR)
|
rectangle(1 + x * SIZE_FACTOR, 1 + y * SIZE_FACTOR, SIZE_FACTOR, SIZE_FACTOR)
|
||||||
.fill(white())
|
.fill(white())
|
||||||
@ -51,11 +52,71 @@ fn main() {
|
|||||||
);
|
);
|
||||||
let mut rect = rectangle(1 + x * SIZE_FACTOR, 1 + y * SIZE_FACTOR, SIZE_FACTOR, SIZE_FACTOR)
|
let mut rect = rectangle(1 + x * SIZE_FACTOR, 1 + y * SIZE_FACTOR, SIZE_FACTOR, SIZE_FACTOR)
|
||||||
.fill(white())
|
.fill(white())
|
||||||
.stroke_opacity(0.7);
|
.stroke_opacity(0.7)
|
||||||
|
.inflate(-1, -1);
|
||||||
|
let mut ident = 1;
|
||||||
for (idx, &(mask, inv_mask)) in block_masks.iter().enumerate() {
|
for (idx, &(mask, inv_mask)) in block_masks.iter().enumerate() {
|
||||||
rect = rect.inflate(-2, -2);
|
rect = rect.inflate(-2, -2);
|
||||||
|
ident += 2;
|
||||||
if check_mask(i, mask, inv_mask) {
|
if check_mask(i, mask, inv_mask) {
|
||||||
println!("{}", rect.stroke(Stroke::Color(COLORS[idx], 2.0)));
|
// check cells around this one
|
||||||
|
let mut up = false;
|
||||||
|
let mut down = false;
|
||||||
|
let mut left = false;
|
||||||
|
let mut right = false;
|
||||||
|
for &var in &vars {
|
||||||
|
let j = i ^ var;
|
||||||
|
if check_mask(j, mask, inv_mask) {
|
||||||
|
let (x2, y2) = grid[j];
|
||||||
|
if (x + 1) % w == x2 && y == y2 {
|
||||||
|
right = true;
|
||||||
|
}
|
||||||
|
if x == x2 && (y + 1) % h == y2 {
|
||||||
|
down = true;
|
||||||
|
}
|
||||||
|
if x == x2 && y == (y2 + 1) % h {
|
||||||
|
up = true;
|
||||||
|
}
|
||||||
|
if x == (x2 + 1) % w && y == y2 {
|
||||||
|
left = true;
|
||||||
|
}
|
||||||
|
if !up && !down && !left && !right {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut sides = rect.sides();
|
||||||
|
for s in &mut sides {
|
||||||
|
*s = s.opacity(0.9);
|
||||||
|
}
|
||||||
|
if up {
|
||||||
|
println!("{}", sides[0].width(2.0).color(white()));
|
||||||
|
println!("{}", sides[2].width(2.0).color(COLORS[idx]).offset(0.0, -ident - 1));
|
||||||
|
println!("{}", sides[3].width(2.0).color(COLORS[idx]).offset(0.0, -ident - 1));
|
||||||
|
} else {
|
||||||
|
println!("{}", sides[0].width(2.0).color(COLORS[idx]));
|
||||||
|
}
|
||||||
|
if down {
|
||||||
|
println!("{}", sides[1].width(2.0).color(white()));
|
||||||
|
println!("{}", sides[2].width(2.0).color(COLORS[idx]).offset(0.0, ident + 1));
|
||||||
|
println!("{}", sides[3].width(2.0).color(COLORS[idx]).offset(0.0, ident + 1));
|
||||||
|
} else {
|
||||||
|
println!("{}", sides[1].width(2.0).color(COLORS[idx]));
|
||||||
|
}
|
||||||
|
if left {
|
||||||
|
println!("{}", sides[2].width(2.0).color(white()));
|
||||||
|
println!("{}", sides[0].width(2.0).color(COLORS[idx]).offset(-ident - 1, 0));
|
||||||
|
println!("{}", sides[1].width(2.0).color(COLORS[idx]).offset(-ident - 1, 0));
|
||||||
|
} else {
|
||||||
|
println!("{}", sides[2].width(2.0).color(COLORS[idx]));
|
||||||
|
}
|
||||||
|
if right {
|
||||||
|
println!("{}", sides[3].width(1.0).color(white()));
|
||||||
|
println!("{}", sides[0].width(2.0).color(COLORS[idx]).offset(ident + 1, 0));
|
||||||
|
println!("{}", sides[1].width(2.0).color(COLORS[idx]).offset(ident + 1, 0));
|
||||||
|
} else {
|
||||||
|
println!("{}", sides[3].width(2.0).color(COLORS[idx]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}",
|
println!("{}",
|
||||||
|
Loading…
Reference in New Issue
Block a user