{
EDGEPT *Loop, *LoopStart, *Segment;
inT16 LastX, LastY, Xmean, Ymean;
inT32 NormX, NormY, DeltaX, DeltaY;
uinT16 NumBLFeatures, NumCNFeatures;
register inT32 pfX, pfY, dX, dY;
register int i;
NumBLFeatures = 0;
NumCNFeatures = 0;
Xsum = 0;
Ysum = 0;
LengthSum = 0;
while (OutLine !=
NULL) {
LoopStart = OutLine->
loop;
Loop = LoopStart;
do {
Segment = Loop;
n = 1;
DeltaX = NormX - LastX;
DeltaY = NormY - LastY;
Length =
MySqrt(DeltaX, DeltaY);
n = ((Length << 2) + Length + 32) >> 6;
if (n != 0) {
Xsum += ((LastX << 1) + DeltaX) * (int) Length;
Ysum += ((LastY << 1) + DeltaY) * (int) Length;
LengthSum += Length;
}
}
if (n != 0) {
LastX = NormX;
LastY = NormY;
}
}
while (Loop != LoopStart);
}
if (LengthSum == 0)
Xmean = (Xsum / (
inT32) LengthSum) >> 1;
Ymean = (Ysum / (
inT32) LengthSum) >> 1;
Ix = 0;
Iy = 0;
NumBLFeatures = 0;
int min_x = 0;
int max_x = 0;
while (OutLine !=
NULL) {
LoopStart = OutLine->
loop;
Loop = LoopStart;
LastX = Loop->
pos.
x - Xmean;
do {
Segment = Loop;
NormX = Loop->
pos.
x - Xmean;
if (NormY < Results->YBottom)
if (NormY > Results->
YTop)
n = 1;
DeltaX = NormX - LastX;
DeltaY = NormY - LastY;
Length =
MySqrt(DeltaX, DeltaY);
n = ((Length << 2) + Length + 32) >> 6;
if (n != 0) {
dX = (DeltaX << 8) / n;
dY = (DeltaY << 8) / n;
pfX = (LastX << 8) + (dX >> 1);
pfY = (LastY << 8) + (dY >> 1);
Ix += ((pfY >> 8) - Ymean) * ((pfY >> 8) - Ymean);
Iy += (pfX >> 8) * (pfX >> 8);
NumBLFeatures,
(
inT16) ((pfY >> 8) - 128),
NumBLFeatures++;
for (i = 1; i < n; i++) {
pfX += dX;
pfY += dY;
Ix += ((pfY >> 8) - Ymean) * ((pfY >> 8) - Ymean);
Iy += (pfX >> 8) * (pfX >> 8);
NumBLFeatures,
(
inT16) ((pfY >> 8) - 128),
NumBLFeatures++;
}
}
}
if (n != 0) {
LastX = NormX;
LastY = NormY;
}
}
while (Loop != LoopStart);
}
Results->
Width = max_x - min_x;
if (Ix == 0)
Ix = 1;
if (Iy == 0)
Iy = 1;
RxInv =
MySqrt2 (NumBLFeatures, Ix, &RxExp);
RyInv =
MySqrt2 (NumBLFeatures, Iy, &RyExp);
Results->
Rx = (
inT16) (51.2 / (
double) RxInv * pow (2.0, (
double) RxExp));
Results->
Ry = (
inT16) (51.2 / (
double) RyInv * pow (2.0, (
double) RyExp));
}
Results->
NumBL = NumBLFeatures;
NumCNFeatures = 0;
int OutLineIndex = -1;
while (OutLine !=
NULL) {
LoopStart = OutLine->
loop;
Loop = LoopStart;
LastX = (Loop->
pos.
x - Xmean) * RyInv;
LastY = (Loop->
pos.
y - Ymean) * RxInv;
OutLineIndex++;
do {
Segment = Loop;
NormX = (Loop->
pos.
x - Xmean) * RyInv;
NormY = (Loop->
pos.
y - Ymean) * RxInv;
n = 1;
DeltaX = NormX - LastX;
DeltaY = NormY - LastY;
Length =
MySqrt(DeltaX, DeltaY);
n = ((Length << 2) + Length + 32) >> 6;
if (n != 0) {
dX = (DeltaX << 8) / n;
dY = (DeltaY << 8) / n;
pfX = (LastX << 8) + (dX >> 1);
pfY = (LastY << 8) + (dY >> 1);
NumCNFeatures,
if (FeatureOutlineArray) {
FeatureOutlineArray[NumCNFeatures] = OutLineIndex;
}
NumCNFeatures++;
for (i = 1; i < n; i++) {
pfX += dX;
pfY += dY;
NumCNFeatures,
if (FeatureOutlineArray) {
FeatureOutlineArray[NumCNFeatures] = OutLineIndex;
}
NumCNFeatures++;
}
}
}
if (n != 0) {
LastX = NormX;
LastY = NormY;
}
}
while (Loop != LoopStart);
}
Results->
NumCN = NumCNFeatures;
}