Skip to content

Commit

Permalink
fixed bug in converting from gridless 3D positions to square grid pos…
Browse files Browse the repository at this point in the history
…itions
  • Loading branch information
dave-doty committed Nov 1, 2020
1 parent 4c50667 commit cc44388
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/src/middleware/helix_grid_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ helix_grid_offsets_middleware(Store<AppState> store, dynamic action, NextDispatc
Geometry geometry = store.state.design.geometry;
Map<int, GridPosition> new_grid_positions_map = {
for (var helix in store.state.design.helices_in_group(action.group_name).values)
helix.idx: util.position3d_to_grid(helix.position, action.grid, geometry)
helix.idx: util.position3d_to_grid_position(helix.position, action.grid, geometry)
};
Set<GridPosition> new_grid_positions_set = Set<GridPosition>.from(new_grid_positions_map.values);
// if lengths don't match, there's a duplicate grid position
Expand Down
4 changes: 2 additions & 2 deletions lib/src/reducers/helices_reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@ BuiltMap<int, Helix> helix_grid_change_reducer(
helix_builder.grid = action.grid;
if (!action.grid.is_none() && helix.grid_position == null) {
helix_builder.grid_position =
util.position3d_to_grid(helix.position, action.grid, geometry).toBuilder();
util.position3d_to_grid_position(helix.position, action.grid, geometry).toBuilder();
helix_builder.position_ = null;
}
if (action.grid.is_none() && helix.position_ == null) {
helix_builder.grid_position = null;
//NOTE: it's important to use helix.grid (i.e., the OLD grid, since util.grid_to_position3d will crash
// if given the none grid)
helix_builder.position_ =
util.grid_to_position3d(helix.grid_position, helix.grid, geometry).toBuilder();
util.grid_position_to_position3d(helix.grid_position, helix.grid, geometry).toBuilder();
}
new_helices[idx] = helix_builder.build();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/state/helix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ abstract class Helix with BuiltJsonSerializable, UnusedFields implements Built<H
@nullable
Position3D get position_;

Position3D get position => position_ ?? util.grid_to_position3d(grid_position, grid, geometry);
Position3D get position => position_ ?? util.grid_position_to_position3d(grid_position, grid, geometry);

/// Helix rotation of the backbone of the forward strand at the helix's minimum base offset. (y-z)
double get roll;
Expand Down
10 changes: 5 additions & 5 deletions lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,11 @@ GridPosition position_2d_to_grid_position_diameter_1_circles(Grid grid, num z, n
if (h % 2 == 0) {
int remainder_by_3 = y.floor() % 3;
if (remainder_by_3 == 2) {
// y += 0.5;
y -= 0.5;
}
} else if (h % 2 == 1) {
int remainder_by_3 = (y - cos(2 * pi / 6)).floor() % 3;
if (remainder_by_3 == 1) {
// y += cos(2 * pi / 6);
y -= cos(2 * pi / 6);
}
}
Expand Down Expand Up @@ -784,12 +782,14 @@ GridPosition position_2d_to_grid_position_diameter_1_circles(Grid grid, num z, n
return gp;
}

GridPosition position3d_to_grid(Position3D position, Grid grid, Geometry geometry) {
var gp = position_2d_to_grid_position_diameter_1_circles(grid, position.z, position.y);
GridPosition position3d_to_grid_position(Position3D position, Grid grid, Geometry geometry) {
var position_normalized_diameter_1 = position * (1.0 / geometry.distance_between_helices_nm);
var gp = position_2d_to_grid_position_diameter_1_circles(grid,
position_normalized_diameter_1.z, position_normalized_diameter_1.y);
return gp;
}

Position3D grid_to_position3d(GridPosition grid_position, Grid grid, Geometry geometry) {
Position3D grid_position_to_position3d(GridPosition grid_position, Grid grid, Geometry geometry) {
num y, z;
if (grid == Grid.square) {
z = grid_position.h * geometry.distance_between_helices_nm;
Expand Down
8 changes: 4 additions & 4 deletions test/reducer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5534,9 +5534,9 @@ main() {
Grid grid = Grid.none;
state = app_state_reducer(state, GridChange(grid: grid, group_name: constants.default_group_name));

var expected_position_h0 = util.grid_to_position3d(
var expected_position_h0 = util.grid_position_to_position3d(
two_helices_design.helices[0].grid_position, Grid.square, two_helices_design.geometry);
var expected_position_h1 = util.grid_to_position3d(
var expected_position_h1 = util.grid_position_to_position3d(
two_helices_design.helices[1].grid_position, Grid.square, two_helices_design.geometry);

expect(state.design.default_group().grid, Grid.none);
Expand Down Expand Up @@ -5568,9 +5568,9 @@ main() {
expected_position1.rebuild((b) => b.x = original_helix1.min_offset * geometry.base_width_svg);

GridPosition expected_grid_position0 =
util.position3d_to_grid(expected_position0, grid, no_grid_two_helices_design.geometry);
util.position3d_to_grid_position(expected_position0, grid, no_grid_two_helices_design.geometry);
GridPosition expected_grid_position1 =
util.position3d_to_grid(expected_position1, grid, no_grid_two_helices_design.geometry);
util.position3d_to_grid_position(expected_position1, grid, no_grid_two_helices_design.geometry);

Helix new_helix0 = no_grid_two_helices_design.helices.values.first.rebuild((b) => b
..grid = grid
Expand Down

0 comments on commit cc44388

Please sign in to comment.