} break;
case 8: { // RIGHT
+ float y = rects[layer->selection].y;
+ float x = position.x;
+ float h = rects[layer->selection].h;
+ for (size_t i = 0; i < dynarray_count(layer->rects); ++i) {
+ if (i == (size_t) layer->selection) continue;
+
+ const Rect b = rects[i];
+ if (segment_overlap(vec(y, y + h), vec(b.y, b.y + b.h))) {
+ temp_snap(&x, b.x, b.w, SNAPPING_THRESHOLD);
+ }
+ }
+
layer->inter_rect = rect_from_points(
rect_position(rects[layer->selection]),
- vec(position.x,
+ vec(x,
rects[layer->selection].y + rects[layer->selection].h));
} break;
case 9: { // TOP,RIGHT
+ float x = position.x;
+ float y = position.y;
+ float w = rects[layer->selection].w;
+ float h = rects[layer->selection].h;
+ for (size_t i = 0; i < dynarray_count(layer->rects); ++i) {
+ if (i == (size_t) layer->selection) continue;
+
+ const Rect b = rects[i];
+ if (segment_overlap(vec(y, y + h), vec(b.y, b.y + b.h))) {
+ temp_snap(&x, b.x, b.w, SNAPPING_THRESHOLD);
+ }
+
+ if (segment_overlap(vec(x, x + w), vec(b.x, b.x + b.w))) {
+ temp_snap(&y, b.y, b.h, SNAPPING_THRESHOLD);
+ }
+ }
+
layer->inter_rect = rect_from_points(
- vec(rects[layer->selection].x, position.y),
- vec(position.x,
+ vec(rects[layer->selection].x, y),
+ vec(x,
rects[layer->selection].y + rects[layer->selection].h));
} break;
case 12: { // BOTTOM,RIGHT
+ float x = position.x;
+ float y = position.y;
+ float w = rects[layer->selection].w;
+ float h = rects[layer->selection].h;
+ for (size_t i = 0; i < dynarray_count(layer->rects); ++i) {
+ if (i == (size_t) layer->selection) continue;
+
+ const Rect b = rects[i];
+ if (segment_overlap(vec(y, y + h), vec(b.y, b.y + b.h))) {
+ temp_snap(&x, b.x, b.w, SNAPPING_THRESHOLD);
+ }
+
+ if (segment_overlap(vec(x, x + w), vec(b.x, b.x + b.w))) {
+ temp_snap(&y, b.y, b.h, SNAPPING_THRESHOLD);
+ }
+ }
+
layer->inter_rect = rect_from_points(
rect_position(rects[layer->selection]),
- position);
+ vec(x, y));
} break;
}
} break;