/* Retourne 1 si le polygone décrit par la liste de point est uniforme en fonction de la ligne verticale, sinon 0. Peu importe que le polygone soit simple (pas d'auto-intersection) ou non. Testé avec Borland C++ 4.02 en modèle small parJim Mischel 12/16/94. Nécessite: L41-2.C L41-3.ASM L41-4.C L40-4.ASM L40-4.C L40-5.ASM A compiler avec la ligne de commande: bcc -ms l24-1.c l24-2.c l24-3.asm l24-4.c l22-4.asm l23-4.c l23-5.asm */ #include "polygon.h" #define SIGNUM(a) ((a>0)?1:((a<0)?-1:0)) int PolygonIsMonotoneVertical(struct PointListHeader * VertexList) { int i, Length, DeltaYSign, PreviousDeltaYSign; int NumYReversals = 0; struct Point *VertexPtr = VertexList->PointPtr; /* Trois points ou moins ne peuvent pas faire un polygone uniforme-vertical */ if ((Length=VertexList->Length) < 4) return(1); /* Parcourt le premier coté non horizontal */ PreviousDeltaYSign = SIGNUM(VertexPtr[Length-1].Y - VertexPtr[0].Y); i = 0; while ((PreviousDeltaYSign == 0) && (i < (Length-1))) { PreviousDeltaYSign = SIGNUM(VertexPtr[i].Y - VertexPtr[i+1].Y); i++; } if (i == (Length-1)) return(1); /* le polygone est une ligne plate */ /* A présent compte les inversion en Y. do { if ((DeltaYSign = SIGNUM(VertexPtr[i].Y - VertexPtr[i+1].Y)) != 0) { if (DeltaYSign != PreviousDeltaYSign) { /* Change de direction Y; il n'est pas uniforme-vertical si la direction Y est inversée trois fois* / if (++NumYReversals > 2) return(0); PreviousDeltaYSign = DeltaYSign; } } } while (i++ < (Length-1)); return(1); /* c'est un polygone uniforme-vertical*/ }