/// /// <summary> * fitsTransforms - checks whether <code>matrix</code> matches the /// * <code>Transforms</code> attribute specified for this Evaluation /// * </summary> /// * <param name="matrix"> /// * matrix to test </param> /// * <returns> boolean - true, if <code>matrix</code> matches the Transforms or /// * if Transforms is not specified </returns> /// private bool fitsTransforms(JDFMatrix matrix) { if (!hasAttribute(AttributeName.TRANSFORMS)) { return(true); } double nT; // negative tolerance double pT; // positive tolerance if (hasAttribute(AttributeName.TOLERANCE)) { nT = getTolerance().X; pT = getTolerance().Y; } else { nT = pT = JDFBaseDataTypes_Fields.EPSILON; } double a = matrix.A; double b = matrix.B; double c = matrix.C; double d = matrix.D; double det = (a * d - b * c); if (det == 0) { return(false); } a = a / Math.Sqrt(Math.Abs(det)); b = b / Math.Sqrt(Math.Abs(det)); c = c / Math.Sqrt(Math.Abs(det)); d = d / Math.Sqrt(Math.Abs(det)); List <ValuedEnum> vTransf = getTransforms(); int siz = vTransf.Count; for (int i = 0; i < siz; i++) { EnumOrientation orientation = EnumOrientation.getEnum(vTransf[i].getName()); //.intValue()); if (orientation.Equals(EnumOrientation.Flip0)) // a=1 b=0 c=0 d=-1 { if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT)) { return(true); } continue; } // a=0 b=-1 else if (orientation.Equals(EnumOrientation.Flip90)) // c=-1 d=0 { if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } // a=-1 b=0 else if (orientation.Equals(EnumOrientation.Flip180)) // c=0 d=1 { if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT)) { return(true); } continue; } // a=0 b=1 else if (orientation.Equals(EnumOrientation.Flip270)) // c=1 d=0 { if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } // a=1 b=0 else if (orientation.Equals(EnumOrientation.Rotate0)) // c=0 d=1 { if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT)) { return(true); } continue; } // a=0 b=1 else if (orientation.Equals(EnumOrientation.Rotate90)) // c=-1 // d=0 { if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } // a=-1 else if (orientation.Equals(EnumOrientation.Rotate180)) // b=0 // c=0 // d=-1 { if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT)) { return(true); } continue; } // a=0 else if (orientation.Equals(EnumOrientation.Rotate270)) // b=-1 // c=1 // d=0 { if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } else { return(true); } } return(false); }
/// /// <summary> * fitsTransforms - checks whether <code>matrix</code> matches the /// * AllowedTransforms or PresentTransforms, specified for this State /// * </summary> /// * <param name="matrix"> /// * matrix to test </param> /// * <param name="transforms"> /// * switches between AllowedTransforms and PresentTransforms. </param> /// * <returns> boolean - true, if <code>matrix</code> matches the Transforms or /// * if AllowedTransforms is not specified </returns> /// private bool fitsTransforms(JDFMatrix matrix, EnumFitsValue transforms) { if (transforms == null || transforms.Equals(EnumFitsValue.Allowed)) { if (!hasAttribute(AttributeName.ALLOWEDTRANSFORMS)) { return(true); } } else { if (!hasAttribute(AttributeName.ALLOWEDTRANSFORMS) && !hasAttribute(AttributeName.PRESENTTRANSFORMS)) { return(true); } } double nT = JDFBaseDataTypes_Fields.EPSILON; // negative tolerance double pT = JDFBaseDataTypes_Fields.EPSILON; // positive tolerance double a = matrix.A; double b = matrix.B; double c = matrix.C; double d = matrix.D; double det = (a * d - b * c); if (det == 0) { return(false); } a = a / Math.Sqrt(Math.Abs(det)); b = b / Math.Sqrt(Math.Abs(det)); c = c / Math.Sqrt(Math.Abs(det)); d = d / Math.Sqrt(Math.Abs(det)); List <ValuedEnum> vTransf; if (transforms == null || transforms.Equals(EnumFitsValue.Allowed)) { vTransf = getAllowedTransforms(); } else { vTransf = getPresentTransforms(); } int siz = vTransf.Count; for (int i = 0; i < siz; i++) { EnumOrientation orientation = (EnumOrientation)vTransf[i]; if (orientation.Equals(EnumOrientation.Flip0)) // a=1 b=0 c=0 d=-1 { if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT)) { return(true); } continue; } // a=0 b=-1 else if (orientation.Equals(EnumOrientation.Flip90)) // c=-1 d=0 { if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } // a=-1 b=0 else if (orientation.Equals(EnumOrientation.Flip180)) // c=0 d=1 { if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT)) { return(true); } continue; } // a=0 b=1 else if (orientation.Equals(EnumOrientation.Flip270)) // c=1 d=0 { if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } // a=1 b=0 else if (orientation.Equals(EnumOrientation.Rotate0)) // c=0 d=1 { if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT)) { return(true); } continue; } // a=0 b=1 else if (orientation.Equals(EnumOrientation.Rotate90)) // c=-1 // d=0 { if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } // a=-1 else if (orientation.Equals(EnumOrientation.Rotate180)) // b=0 // c=0 // d=-1 { if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT)) { return(true); } continue; } // a=0 else if (orientation.Equals(EnumOrientation.Rotate270)) // b=-1 // c=1 // d=0 { if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT)) { return(true); } continue; } else { return(true); } } return(false); }