Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/rct.c')
-rw-r--r--source/blender/blenlib/intern/rct.c194
1 files changed, 92 insertions, 102 deletions
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index bf3c8730b01..f952b62cb61 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -238,15 +238,14 @@ static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], c
if (div == 0.0) {
return 1; /* co-linear */
}
- else {
- const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) -
- (v1[0] - v3[0]) * (v4[1] - v3[1])) /
- div;
- const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) -
- (v1[0] - v3[0]) * (v2[1] - v1[1])) /
- div;
- return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
- }
+
+ const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) -
+ (v1[0] - v3[0]) * (v4[1] - v3[1])) /
+ div;
+ const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) -
+ (v1[0] - v3[0]) * (v2[1] - v1[1])) /
+ div;
+ return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
}
static int isect_segments_fl(const float v1[2],
const float v2[2],
@@ -258,15 +257,14 @@ static int isect_segments_fl(const float v1[2],
if (div == 0.0) {
return 1; /* co-linear */
}
- else {
- const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) -
- (v1[0] - v3[0]) * (v4[1] - v3[1])) /
- div;
- const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) -
- (v1[0] - v3[0]) * (v2[1] - v1[1])) /
- div;
- return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
- }
+
+ const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) -
+ (v1[0] - v3[0]) * (v4[1] - v3[1])) /
+ div;
+ const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) -
+ (v1[0] - v3[0]) * (v2[1] - v1[1])) /
+ div;
+ return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
}
bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2])
@@ -289,31 +287,30 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2])
if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) {
return true;
}
- else {
- /* both points are outside but may intersect the rect */
- int tvec1[2];
- int tvec2[2];
- /* diagonal: [/] */
- tvec1[0] = rect->xmin;
- tvec1[1] = rect->ymin;
- tvec2[0] = rect->xmin;
- tvec2[1] = rect->ymax;
- if (isect_segments_i(s1, s2, tvec1, tvec2)) {
- return true;
- }
- /* diagonal: [\] */
- tvec1[0] = rect->xmin;
- tvec1[1] = rect->ymax;
- tvec2[0] = rect->xmax;
- tvec2[1] = rect->ymin;
- if (isect_segments_i(s1, s2, tvec1, tvec2)) {
- return true;
- }
+ /* both points are outside but may intersect the rect */
+ int tvec1[2];
+ int tvec2[2];
+ /* diagonal: [/] */
+ tvec1[0] = rect->xmin;
+ tvec1[1] = rect->ymin;
+ tvec2[0] = rect->xmin;
+ tvec2[1] = rect->ymax;
+ if (isect_segments_i(s1, s2, tvec1, tvec2)) {
+ return true;
+ }
- /* no intersection */
- return false;
+ /* diagonal: [\] */
+ tvec1[0] = rect->xmin;
+ tvec1[1] = rect->ymax;
+ tvec2[0] = rect->xmax;
+ tvec2[1] = rect->ymin;
+ if (isect_segments_i(s1, s2, tvec1, tvec2)) {
+ return true;
}
+
+ /* no intersection */
+ return false;
}
bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[2])
@@ -336,31 +333,30 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[
if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) {
return true;
}
- else {
- /* both points are outside but may intersect the rect */
- float tvec1[2];
- float tvec2[2];
- /* diagonal: [/] */
- tvec1[0] = rect->xmin;
- tvec1[1] = rect->ymin;
- tvec2[0] = rect->xmin;
- tvec2[1] = rect->ymax;
- if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
- return true;
- }
- /* diagonal: [\] */
- tvec1[0] = rect->xmin;
- tvec1[1] = rect->ymax;
- tvec2[0] = rect->xmax;
- tvec2[1] = rect->ymin;
- if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
- return true;
- }
+ /* both points are outside but may intersect the rect */
+ float tvec1[2];
+ float tvec2[2];
+ /* diagonal: [/] */
+ tvec1[0] = rect->xmin;
+ tvec1[1] = rect->ymin;
+ tvec2[0] = rect->xmin;
+ tvec2[1] = rect->ymax;
+ if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
+ return true;
+ }
- /* no intersection */
- return false;
+ /* diagonal: [\] */
+ tvec1[0] = rect->xmin;
+ tvec1[1] = rect->ymax;
+ tvec2[0] = rect->xmax;
+ tvec2[1] = rect->ymin;
+ if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
+ return true;
}
+
+ /* no intersection */
+ return false;
}
bool BLI_rcti_isect_circle(const rcti *rect, const float xy[2], const float radius)
@@ -890,15 +886,14 @@ bool BLI_rctf_isect(const rctf *src1, const rctf *src2, rctf *dest)
}
return true;
}
- else {
- if (dest) {
- dest->xmin = 0;
- dest->xmax = 0;
- dest->ymin = 0;
- dest->ymax = 0;
- }
- return false;
+
+ if (dest) {
+ dest->xmin = 0;
+ dest->xmax = 0;
+ dest->ymin = 0;
+ dest->ymax = 0;
}
+ return false;
}
bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest)
@@ -920,15 +915,14 @@ bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest)
}
return true;
}
- else {
- if (dest) {
- dest->xmin = 0;
- dest->xmax = 0;
- dest->ymin = 0;
- dest->ymax = 0;
- }
- return false;
+
+ if (dest) {
+ dest->xmin = 0;
+ dest->xmax = 0;
+ dest->ymin = 0;
+ dest->ymax = 0;
}
+ return false;
}
bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2])
@@ -943,13 +937,12 @@ bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2])
}
return true;
}
- else {
- if (range_x) {
- range_x[0] = 0;
- range_x[1] = 0;
- }
- return false;
+
+ if (range_x) {
+ range_x[0] = 0;
+ range_x[1] = 0;
}
+ return false;
}
bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2])
@@ -964,13 +957,12 @@ bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2])
}
return true;
}
- else {
- if (range_y) {
- range_y[0] = 0;
- range_y[1] = 0;
- }
- return false;
+
+ if (range_y) {
+ range_y[0] = 0;
+ range_y[1] = 0;
}
+ return false;
}
bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2])
@@ -985,13 +977,12 @@ bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2])
}
return true;
}
- else {
- if (range_x) {
- range_x[0] = 0;
- range_x[1] = 0;
- }
- return false;
+
+ if (range_x) {
+ range_x[0] = 0;
+ range_x[1] = 0;
}
+ return false;
}
bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2])
@@ -1006,13 +997,12 @@ bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2])
}
return true;
}
- else {
- if (range_y) {
- range_y[0] = 0;
- range_y[1] = 0;
- }
- return false;
+
+ if (range_y) {
+ range_y[0] = 0;
+ range_y[1] = 0;
}
+ return false;
}
void BLI_rcti_rctf_copy(rcti *dst, const rctf *src)