static inline struct SupportPoint SegmentSupportPoint(const cpSegmentShape *seg, const cpVect n) { if(cpvdot(seg->ta, n) > cpvdot(seg->tb, n)) { return SupportPointNew(seg->ta, 0); } else { return SupportPointNew(seg->tb, 1); } }
static inline struct SupportPoint PolySupportPoint(const cpPolyShape *poly, const cpVect n) { const struct cpSplittingPlane *planes = poly->planes; int i = PolySupportPointIndex(poly->count, planes, n); return SupportPointNew(planes[i].v0, i); }
static struct SupportPoint ShapePoint(const cpShape *shape, const int i) { switch(shape->klass->type){ case CP_CIRCLE_SHAPE: { return SupportPointNew(((cpCircleShape *)shape)->tc, 0); } case CP_SEGMENT_SHAPE: { cpSegmentShape *seg = (cpSegmentShape *)shape; return SupportPointNew(i == 0 ? seg->ta : seg->tb, i); } case CP_POLY_SHAPE: { cpPolyShape *poly = (cpPolyShape *)shape; // Poly shapes may change vertex count. int index = (i < poly->count ? i : 0); return SupportPointNew(poly->planes[index].v0, index); } default: { return SupportPointNew(cpvzero, 0); } } }
static inline struct SupportPoint CircleSupportPoint(const cpCircleShape *circle, const cpVect n) { return SupportPointNew(circle->tc, 0); }