Skip to content

Commit b222675

Browse files
committed
Rename to circuit
1 parent 4e2a891 commit b222675

3 files changed

Lines changed: 38 additions & 37 deletions

File tree

src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl App {
307307
pub fn circuit(&self) -> &Circuit {
308308
&self.db.circuit
309309
}
310+
310311
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
311312
egui_extras::install_image_loaders(&cc.egui_ctx);
312313
if let Some(storage) = cc.storage {

src/connection_manager.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ pub struct ConnectionManager {
9595
}
9696

9797
impl ConnectionManager {
98-
pub fn new(db: &Circuit, canvas_config: &CanvasConfig) -> Self {
98+
pub fn new(circuit: &Circuit, canvas_config: &CanvasConfig) -> Self {
9999
let mut new = Self {
100100
dirty_instances: Default::default(),
101101
spatial_index: Default::default(),
102102
pin_position_cache: Default::default(),
103103
canvas_config: canvas_config.clone(),
104104
};
105-
new.rebuild_spatial_index(db);
105+
new.rebuild_spatial_index(circuit);
106106
new
107107
}
108108

@@ -119,14 +119,14 @@ impl ConnectionManager {
119119
}
120120

121121
/// Update the spatial index for all pins in the database
122-
pub fn rebuild_spatial_index(&mut self, db: &Circuit) {
122+
pub fn rebuild_spatial_index(&mut self, circuit: &Circuit) {
123123
self.spatial_index.clear();
124124
self.pin_position_cache.clear();
125125

126126
// Index all pins by their grid cell
127-
for (instance_id, _) in &db.types {
128-
for pin in db.pins_of(instance_id) {
129-
let pos = db.pin_position(pin, &self.canvas_config);
127+
for (instance_id, _) in &circuit.types {
128+
for pin in circuit.pins_of(instance_id) {
129+
let pos = circuit.pin_position(pin, &self.canvas_config);
130130
let cell = GridCell::from_pos(pos);
131131

132132
self.spatial_index.entry(cell).or_default().push(pin);
@@ -137,9 +137,9 @@ impl ConnectionManager {
137137
}
138138

139139
/// Update spatial index for specific pins that have moved
140-
fn update_spatial_index_for_pins(&mut self, db: &Circuit, pins: &[Pin]) {
140+
fn update_spatial_index_for_pins(&mut self, circuit: &Circuit, pins: &[Pin]) {
141141
for &pin in pins {
142-
let new_pos = db.pin_position(pin, &self.canvas_config);
142+
let new_pos = circuit.pin_position(pin, &self.canvas_config);
143143

144144
// Remove from old cell if position changed
145145
if let Some(old_pos) = self.pin_position_cache.get(&pin)
@@ -161,10 +161,10 @@ impl ConnectionManager {
161161
}
162162

163163
/// Find potential connections for a pin using spatial indexing
164-
pub fn find_connections_for_pin(&self, db: &Circuit, pin: Pin) -> Vec<Connection> {
164+
pub fn find_connections_for_pin(&self, circuit: &Circuit, pin: Pin) -> Vec<Connection> {
165165
let mut wire_connections = Vec::new();
166166
let mut non_wire_connections = Vec::new();
167-
let pin_pos = db.pin_position(pin, &self.canvas_config);
167+
let pin_pos = circuit.pin_position(pin, &self.canvas_config);
168168
let cell = GridCell::from_pos(pin_pos);
169169

170170
// Check this cell and neighboring cells
@@ -175,7 +175,7 @@ impl ConnectionManager {
175175
continue;
176176
}
177177

178-
let other_pos = db.pin_position(other_pin, &self.canvas_config);
178+
let other_pos = circuit.pin_position(other_pin, &self.canvas_config);
179179
let distance = (pin_pos - other_pos).length();
180180

181181
// First pin will move to attach
@@ -186,7 +186,7 @@ impl ConnectionManager {
186186
};
187187

188188
if distance <= SNAP_THRESHOLD && self.validate_connection(connection) {
189-
let is_wire = matches!(db.ty(other_pin.ins), InstanceKind::Wire);
189+
let is_wire = matches!(circuit.ty(other_pin.ins), InstanceKind::Wire);
190190
if is_wire {
191191
wire_connections.push(connection);
192192
} else {
@@ -198,7 +198,7 @@ impl ConnectionManager {
198198
}
199199

200200
// For wire pins, prefer non-wire connections over wire connections
201-
if matches!(db.ty(pin.ins), InstanceKind::Wire) && !non_wire_connections.is_empty() {
201+
if matches!(circuit.ty(pin.ins), InstanceKind::Wire) && !non_wire_connections.is_empty() {
202202
non_wire_connections
203203
} else {
204204
let mut all = non_wire_connections;
@@ -281,21 +281,21 @@ impl ConnectionManager {
281281
}
282282
}
283283

284-
pub fn pins_to_update(&mut self, db: &Circuit) -> Vec<Pin> {
284+
pub fn pins_to_update(&mut self, circuit: &Circuit) -> Vec<Pin> {
285285
let mut pins_to_update = Vec::new();
286286

287287
for &instance_id in &self.dirty_instances {
288-
for pin in db.pins_of(instance_id) {
288+
for pin in circuit.pins_of(instance_id) {
289289
pins_to_update.push(pin);
290290
}
291291
}
292292
pins_to_update.sort_unstable();
293293
pins_to_update.dedup();
294294

295-
if pins_to_update.len() > db.types.len() / 4 {
296-
self.rebuild_spatial_index(db);
295+
if pins_to_update.len() > circuit.types.len() / 4 {
296+
self.rebuild_spatial_index(circuit);
297297
} else {
298-
self.update_spatial_index_for_pins(db, &pins_to_update);
298+
self.update_spatial_index_for_pins(circuit, &pins_to_update);
299299
}
300300
pins_to_update
301301
}

src/simulator.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ impl Simulator {
9797
Self::default()
9898
}
9999

100-
fn rebuild_sorted_instances(&self, db: &Circuit) -> Vec<InstanceId> {
101-
let mut ids: Vec<InstanceId> = db.types.keys().collect();
100+
fn rebuild_sorted_instances(&self, circuit: &Circuit) -> Vec<InstanceId> {
101+
let mut ids: Vec<InstanceId> = circuit.types.keys().collect();
102102
ids.sort_unstable();
103103
ids
104104
}
@@ -157,17 +157,17 @@ impl Simulator {
157157
.collect()
158158
}
159159

160-
fn evaluate(&mut self, db: &Circuit, id: InstanceId) {
160+
fn evaluate(&mut self, circuit: &Circuit, id: InstanceId) {
161161
self.evaluated.insert(id);
162-
match db.ty(id) {
162+
match circuit.ty(id) {
163163
InstanceKind::Wire => {
164-
self.evaluate_wire(db, id);
164+
self.evaluate_wire(circuit, id);
165165
}
166166
InstanceKind::Gate(_) => {
167-
self.evaluate_gate(db, id);
167+
self.evaluate_gate(circuit, id);
168168
}
169169
InstanceKind::Lamp => {
170-
self.evaluate_lamp(db, id);
170+
self.evaluate_lamp(circuit, id);
171171
}
172172
InstanceKind::Power | InstanceKind::Module(_) => {}
173173
InstanceKind::Clock => {
@@ -180,14 +180,14 @@ impl Simulator {
180180
}
181181
}
182182

183-
fn evaluate_power(&mut self, db: &Circuit, id: InstanceId) {
184-
let p = db.get_power(id);
183+
fn evaluate_power(&mut self, circuit: &Circuit, id: InstanceId) {
184+
let p = circuit.get_power(id);
185185
let out = power_output(id);
186186
let val = if p.on { Value::One } else { Value::Zero };
187187
self.current.insert(out, val);
188188
}
189189

190-
fn evaluate_wire(&mut self, db: &Circuit, id: InstanceId) {
190+
fn evaluate_wire(&mut self, circuit: &Circuit, id: InstanceId) {
191191
let input = {
192192
let start = wire_start(id);
193193
let end = wire_end(id);
@@ -204,23 +204,23 @@ impl Simulator {
204204
wire_start(id)
205205
};
206206

207-
let result = self.get_pin_value(db, input);
207+
let result = self.get_pin_value(circuit, input);
208208

209209
self.current.insert(input, result);
210210
self.current.insert(other, result);
211211
}
212212

213-
fn evaluate_gate(&mut self, db: &Circuit, id: InstanceId) {
214-
let InstanceKind::Gate(kind) = db.ty(id) else {
213+
fn evaluate_gate(&mut self, circuit: &Circuit, id: InstanceId) {
214+
let InstanceKind::Gate(kind) = circuit.ty(id) else {
215215
return;
216216
};
217217

218218
let inp1 = gate_inp1(id);
219219
let inp2 = gate_inp2(id);
220220
let out = gate_output(id);
221221

222-
let a = self.get_pin_value(db, inp1);
223-
let b = self.get_pin_value(db, inp2);
222+
let a = self.get_pin_value(circuit, inp1);
223+
let b = self.get_pin_value(circuit, inp2);
224224

225225
let out_val = match kind {
226226
GateKind::And => a.and(b),
@@ -234,14 +234,14 @@ impl Simulator {
234234
self.current.insert(out, out_val);
235235
}
236236

237-
fn evaluate_lamp(&mut self, db: &Circuit, id: InstanceId) {
237+
fn evaluate_lamp(&mut self, circuit: &Circuit, id: InstanceId) {
238238
let inp = lamp_input(id);
239-
let val = self.get_pin_value(db, inp);
239+
let val = self.get_pin_value(circuit, inp);
240240
self.current.insert(inp, val);
241241
}
242242

243-
fn get_pin_value(&self, db: &Circuit, pin: Pin) -> Value {
244-
let mut connected = db.connected_pins(pin);
243+
fn get_pin_value(&self, circuit: &Circuit, pin: Pin) -> Value {
244+
let mut connected = circuit.connected_pins(pin);
245245
connected.push(pin);
246246
connected.sort_unstable();
247247
connected.dedup();

0 commit comments

Comments
 (0)