summaryrefslogtreecommitdiff
path: root/src/net_notch.c
blob: c0ab9d7ac88fd5d5cebed45b1ed2909b8e00f86a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include "fracture.h"

void net_notch(net_t *net, double notch_len, cholmod_common *c) {
	for (uint_t i = 0; i < net->graph->ne; i++) {
		uint_t v1, v2;
		double v1x, v1y, v2x, v2y, dx, dy;
		bool crosses_center, not_wrapping, correct_length;

		v1 = net->graph->ev[2 * i];
		v2 = net->graph->ev[2 * i + 1];

		v1x = net->graph->vx[2 * v1];
		v1y = net->graph->vx[2 * v1 + 1];
		v2x = net->graph->vx[2 * v2];
		v2y = net->graph->vx[2 * v2 + 1];

		dx = v1x - v2x;
		dy = v1y - v2y;

		crosses_center = (v1y >= 0.5 && v2y <= 0.5) || (v1y <= 0.5 && v2y >= 0.5);
		not_wrapping = fabs(dy) < 0.5;
		correct_length = 0 <= v1x + dx / dy * (v1y - 0.5) <= notch_len;

		if (crosses_center && not_wrapping && correct_length) {
			break_edge(net, i, c);
		}
	}
}