Skip to content

Commit

Permalink
SurfacePoint: add reduced() function
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshi84 committed Sep 10, 2020
1 parent dc8bd4e commit 0948d93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/geometrycentral/surface/surface_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ struct SurfacePoint {
// Return the nearest vertex to this surface point
inline Vertex nearestVertex() const;

// Return the equivalent surface point in the 'reduced' form (can be seen as the inverse of inSomeFace).
// An edge point may be reduced to a vertex point, and a face point may be reduced to an edge point or a vertex point.
inline SurfacePoint reduced() const;

// Linearly interpolate data at vertices to this point.
// T must support addition and multiplication by a double.
Expand Down
33 changes: 33 additions & 0 deletions include/geometrycentral/surface/surface_point.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,39 @@ inline Vertex SurfacePoint::nearestVertex() const {
return vertex;
}

inline SurfacePoint SurfacePoint::reduced() const {
switch (type) {
case SurfacePointType::Vertex: {
return *this;
}
case SurfacePointType::Edge: {
if (tEdge == 0. || tEdge == 1.)
return SurfacePoint(nearestVertex());
else
return *this;
}
case SurfacePointType::Face: {
if (faceCoords.x == 1. || faceCoords.y == 1. || faceCoords.z == 1.)
return SurfacePoint(nearestVertex());
else if (faceCoords.z == 0.) {
Edge e = face.halfedge().edge();
double tEdge = face == e.halfedge().face() ? faceCoords.y : faceCoords.x;
return SurfacePoint(e, tEdge);
} else if (faceCoords.x == 0.) {
Edge e = face.halfedge().next().edge();
double tEdge = face == e.halfedge().face() ? faceCoords.z : faceCoords.y;
return SurfacePoint(e, tEdge);
} else if (faceCoords.y == 0.) {
Edge e = face.halfedge().next().next().edge();
double tEdge = face == e.halfedge().face() ? faceCoords.x : faceCoords.z;
return SurfacePoint(e, tEdge);
} else {
return *this;
}
}
}
}

template <typename T>
inline T SurfacePoint::interpolate(const VertexData<T>& data) const {

Expand Down

0 comments on commit 0948d93

Please sign in to comment.