DmtxFollow FollowStep2(DmtxFollow followBeg, int sign) { int patternIdx; DmtxFollow follow = new DmtxFollow(); if (Math.Abs(sign) != 1) { throw new Exception("Invalid parameter 'sign', can only be -1 or +1"); } if ((followBeg.Neighbor & 0x40) == 0x00) { throw new Exception("Invalid value for neighbor!"); } patternIdx = (sign < 0) ? followBeg.Neighbor & 0x07 : ((followBeg.Neighbor & 0x38) >> 3); follow.Loc = new DmtxPixelLoc() { X = followBeg.Loc.X + DmtxConstants.DmtxPatternX[patternIdx], Y = followBeg.Loc.Y + DmtxConstants.DmtxPatternY[patternIdx] }; follow.Step = followBeg.Step + sign; follow.Ptr = this._cache; follow.PtrIndex = DecodeGetCache(follow.Loc.X, follow.Loc.Y); return follow; }
DmtxFollow FollowSeekLoc(DmtxPixelLoc loc) { DmtxFollow follow = new DmtxFollow(); follow.Loc = loc; follow.Step = 0; follow.Ptr = this._cache; follow.PtrIndex = DecodeGetCache(follow.Loc.X, follow.Loc.Y); return follow; }
DmtxFollow FollowStep(DmtxRegion reg, DmtxFollow followBeg, int sign) { int patternIdx; int stepMod; int factor; DmtxFollow follow = new DmtxFollow(); if (Math.Abs(sign) != 1) { throw new Exception("Invalid parameter 'sign', can only be -1 or +1"); } factor = reg.StepsTotal + 1; if (sign > 0) stepMod = (factor + (followBeg.Step % factor)) % factor; else stepMod = (factor - (followBeg.Step % factor)) % factor; /* End of positive trail -- magic jump */ if (sign > 0 && stepMod == reg.JumpToNeg) { follow.Loc = reg.FinalNeg; } /* End of negative trail -- magic jump */ else if (sign < 0 && stepMod == reg.JumpToPos) { follow.Loc = reg.FinalPos; } /* Trail in progress -- normal jump */ else { patternIdx = (sign < 0) ? followBeg.Neighbor & 0x07 : ((followBeg.Neighbor & 0x38) >> 3); follow.Loc = new DmtxPixelLoc() { X = followBeg.Loc.X + DmtxConstants.DmtxPatternX[patternIdx], Y = followBeg.Loc.Y + DmtxConstants.DmtxPatternY[patternIdx] }; } follow.Step = followBeg.Step + sign; follow.Ptr = this._cache; follow.PtrIndex = DecodeGetCache(follow.Loc.X, follow.Loc.Y); return follow; }
DmtxFollow FollowSeek(DmtxRegion reg, int seek) { int i; int sign; DmtxFollow follow = new DmtxFollow(); follow.Loc = reg.FlowBegin.Loc; follow.Step = 0; follow.Ptr = this._cache; follow.PtrIndex = DecodeGetCache(follow.Loc.X, follow.Loc.Y); sign = (seek > 0) ? +1 : -1; for (i = 0; i != seek; i += sign) { follow = FollowStep(reg, follow, sign); if (Math.Abs(follow.Step) > reg.StepsTotal) { throw new Exception("Follow step count larger total step count!"); } } return follow; }