Skip to content

Commit

Permalink
Removed splits in Polygon editor, replace by internal vertices and po…
Browse files Browse the repository at this point in the history
…lygon support.
  • Loading branch information
reduz committed Jan 8, 2019
1 parent d8c40bc commit e46f28e
Show file tree
Hide file tree
Showing 9 changed files with 766 additions and 224 deletions.
2 changes: 2 additions & 0 deletions core/math/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/print_string.h"

/* this implementation is very inefficient, commenting unless bugs happen. See the other one.
bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
Vector<int> indices = Geometry::triangulate_polygon(p_polygon);
Expand All @@ -42,6 +43,7 @@ bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2>
}
return false;
}
*/

void Geometry::MeshData::optimize_vertices() {

Expand Down
32 changes: 31 additions & 1 deletion core/math/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ class Geometry {
return (cn.cross(an) > 0) == orientation;
}

static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon);
//static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon);

static Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 *p_segment) {

Expand Down Expand Up @@ -815,6 +815,36 @@ class Geometry {
return sum > 0.0f;
}

/* alternate implementation that should be faster */
static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
int c = p_polygon.size();
if (c < 3)
return false;
const Vector2 *p = p_polygon.ptr();
Vector2 further_away(-1e20, -1e20);
Vector2 further_away_opposite(1e20, 1e20);

for (int i = 0; i < c; i++) {
further_away.x = MAX(p[i].x, further_away.x);
further_away.y = MAX(p[i].y, further_away.y);
further_away_opposite.x = MIN(p[i].x, further_away_opposite.x);
further_away_opposite.y = MIN(p[i].y, further_away_opposite.y);
}

further_away += (further_away - further_away_opposite) * Vector2(1.221313, 1.512312); // make point outside that wont intersect with points in segment from p_point

int intersections = 0;
for (int i = 0; i < c; i++) {
const Vector2 &v1 = p[i];
const Vector2 &v2 = p[(i + 1) % c];
if (segment_intersects_segment_2d(v1, v2, p_point, further_away, NULL)) {
intersections++;
}
}

return (intersections & 1);
}

static PoolVector<PoolVector<Face3> > separate_objects(PoolVector<Face3> p_array);

static PoolVector<Face3> wrap_geometry(PoolVector<Face3> p_array, real_t *p_error = NULL); ///< create a "wrap" that encloses the given geometry
Expand Down
67 changes: 67 additions & 0 deletions editor/icons/icon_edit_internal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions editor/icons/icon_editor_internal_handle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions editor/icons/icon_remove_internal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e46f28e

Please sign in to comment.