Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #855: overlapping domains should not be able to be drawn #860

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/middleware/strand_create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '../actions/actions.dart' as actions;
import '../state/app_state.dart';

strand_create_middleware(Store<AppState> store, dynamic action, NextDispatcher next) {
if (action is actions.StrandCreateStart) {
if (action is actions.StrandCreateStart) {
if (store.state.design.is_occupied(action.address)) {
return;
}
Expand Down
16 changes: 14 additions & 2 deletions lib/src/state/design.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'helix.dart';
import 'grid.dart';
import '../util.dart' as util;
import '../constants.dart' as constants;
import 'strand_creation.dart';
import 'substrand.dart';
import 'unused_fields.dart';
import 'domain_name_mismatch.dart';
Expand Down Expand Up @@ -1751,15 +1752,26 @@ abstract class Design with UnusedFields implements Built<Design, DesignBuilder>,
}

/// Return [Domain] at [address], INCLUSIVE, or null if there is none.
Domain domain_on_helix_at(Address address) {
Domain domain_on_helix_at(Address address, [StrandCreation strand_creation = null]) {
for (var domain in this.helix_idx_to_domains[address.helix_idx]) {
if (domain.contains_offset(address.offset) && domain.forward == address.forward) {
return domain;
} else if(strand_creation != null && overlap(domain, address.offset, strand_creation.start)){
return domain;
}
}
return null;
}

bool overlap(Domain domain, int offset, int start) {
int overlap_start = max(min(domain.start, domain.end), min(start, offset));
int overlap_end = min(max(domain.start, domain.end), max(start, offset));
if (overlap_start >= overlap_end) {
return false;
}
return true;
}

/// Return list of Substrands overlapping `substrand`.
List<Domain> _other_substrands_overlapping(Domain substrand) {
List<Domain> ret = [];
Expand Down Expand Up @@ -1883,7 +1895,7 @@ abstract class Design with UnusedFields implements Built<Design, DesignBuilder>,
// return view_orders.toBuiltList();
// }

bool is_occupied(Address address) => domain_on_helix_at(address) != null;
bool is_occupied(Address address, [StrandCreation strand_creation]) => domain_on_helix_at(address, strand_creation) != null;

@memoized
int max_offset_of_strands_at(int helix_idx) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/design.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class DesignViewComponent {
var new_address = Address(
helix_idx: strand_creation.helix.idx, offset: new_offset, forward: strand_creation.forward);
if (old_offset != new_offset &&
!app.state.design.is_occupied(new_address) && // can't draw strand over existing strand
!app.state.design.is_occupied(new_address, strand_creation) && // can't draw strand over existing strand
new_offset != strand_creation.original_offset && // can't put start and end at same offset
strand_creation.helix.min_offset <= new_offset && // can't go off end of helix
new_offset < strand_creation.helix.max_offset) {
Expand Down