Example #1
0
        public bool Validate(NaturalRect roi)
        {
            Contract.Requires <InvalidOperationException>(this.ConstraintsAreValid);
            bool h_ok = Validate1D(HMax, HPositionUnit, HSizeUnit, roi.Left, roi.Width);
            bool v_ok = Validate1D(VMax, VPositionUnit, VSizeUnit, roi.Top, roi.Height);

            return(h_ok && v_ok);

            // we should really do this properly, perhaps spitting out informative
            // error messages.  and definitely doing either contracts, or
            // thorough unit tests with simulated and/or real hardware.
        }
Example #2
0
        public NaturalRect CoerceDown(NaturalRect rect)
        {
            Contract.Requires <InvalidOperationException>(this.ConstraintsAreValid);
            Contract.Requires <ArgumentOutOfRangeException>(rect.Left >= 0);
            Contract.Requires <ArgumentOutOfRangeException>(rect.Top >= 0);
            Contract.Requires <ArgumentOutOfRangeException>(rect.Width > 0);
            Contract.Requires <ArgumentOutOfRangeException>(rect.Height > 0);
            Contract.Requires <ArgumentOutOfRangeException>(rect.Width >= HSizeUnit);
            Contract.Requires <ArgumentOutOfRangeException>(rect.Height >= VSizeUnit);

            return(new NaturalRect(RoundDownLeft(rect.Left), RoundDownTop(rect.Top),
                                   RoundDownWidth(rect.Width), RoundDownHeight(rect.Height)));
        }