Add interfaces to move components

This commit is contained in:
Mikolaj Wielgus 2026-05-20 14:07:05 +02:00
parent 24af694c6b
commit 459c4b41ee
7 changed files with 88 additions and 4 deletions

View File

@ -2,8 +2,10 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
mod resolve;
mod select;
pub mod selections;
mod transforms;
use bimap::BiBTreeMap;
use derive_getters::{Dissolve, Getters};

View File

@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2026 Topola contributors
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{
board::{Board, selections::ComponentSelection},
compounds::ComponentId,
};
impl Board {
pub fn resolve_components(&self, selection: ComponentSelection) -> Vec<ComponentId> {
selection
.0
.clone()
.into_iter()
.filter_map(|selector| self.component_id(&selector.component))
.collect()
}
}

View File

@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2026 Topola contributors
//
// SPDX-License-Identifier: MIT OR Apache-2.0
mod move_by;

View File

@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2026 Topola contributors
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{Board, Vector2, compounds::ComponentId, selections::ComponentSelection};
impl Board {
pub fn move_components_by(
&mut self,
selection: &ComponentSelection,
translation: Vector2<i64>,
) {
self.move_resolved_components_by(&self.resolve_components(selection.clone()), translation);
}
pub fn move_resolved_components_by(
&mut self,
selection: &[ComponentId],
translation: Vector2<i64>,
) {
self.layout.move_components_by(selection, translation);
}
}

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pub mod primitives;
mod transforms;
use derive_getters::Getters;
use rstar::{
@ -122,12 +123,12 @@ impl Layout {
self.modify_joint_raw(id, |joint| f(&mut joint.spec));
let new_joint = self.joints[id.index()].clone();
for &segment in &new_joint.segments {
self.update_segment(segment);
for &segment_id in &new_joint.segments {
self.update_segment(segment_id);
}
for &via in &new_joint.vias {
self.update_via(via);
for &via_id in &new_joint.vias {
self.update_via(via_id);
}
}

View File

@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2026 Topola contributors
//
// SPDX-License-Identifier: MIT OR Apache-2.0
mod move_by;

View File

@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2026 Topola contributors
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{Layout, compounds::ComponentId, math::Vector2};
impl Layout {
pub fn move_component_by(&mut self, id: ComponentId, translation: Vector2<i64>) {
self.move_components_by(&[id], translation);
}
pub fn move_components_by(&mut self, ids: &[ComponentId], translation: Vector2<i64>) {
for id in ids {
let component = self.components[id.index()].clone();
for &joint_id in &component.joints {
self.modify_joint_raw(joint_id, |joint| joint.spec.position += translation);
}
for &segment_id in &component.segments {
self.update_segment(segment_id);
}
for &via_id in &component.vias {
self.update_via(via_id);
}
}
}
}