コード例 #1
0
ファイル: DateTimeTickSpacing.cs プロジェクト: olesar/Altaxo
        private bool InternalPreProcessScaleBoundaries(ref DateTime xorg, ref DateTime xend, bool isOrgExtendable, bool isEndExtendable)
        {
            _cachedMajorMinor = null;
            bool modified = false;

            if (!(xorg <= xend))
            {
                var h = xorg;
                xorg     = xend;
                xend     = h;
                modified = true;
            }
            if (xorg == xend)
            {
                var defaultSpanBy2 = TimeSpan.FromDays(1);
                if (xorg > (DateTime.MinValue + defaultSpanBy2))
                {
                    xorg -= defaultSpanBy2;
                }
                else
                {
                    xorg = DateTime.MinValue;
                }

                if (xend < DateTime.MaxValue - defaultSpanBy2)
                {
                    xend += defaultSpanBy2;
                }
                else
                {
                    xend = DateTime.MaxValue;
                }

                modified = true;
            }
            // here xorg should be < xend in any case
            if (!(xorg < xend))
            {
                throw new InvalidProgramException();
            }
            bool modGraceAndOneLever = GetOrgEndWithGraceAndOneLever(xorg, xend, isOrgExtendable, isEndExtendable, out var xOrgWithGraceAndOneLever, out var xEndWithGraceAndOneLever);
            bool modTickSnapping     = GetOrgEndWithTickSnappingOnly(xend - xorg, xorg, xend, isOrgExtendable, isEndExtendable, out var xOrgWithTickSnapping, out var xEndWithTickSnapping, out var decadesPerMajorTick, out var minorTicks);

            // now compare the two
            if (xOrgWithTickSnapping <= xOrgWithGraceAndOneLever && xEndWithTickSnapping >= xEndWithGraceAndOneLever)
            {
                // then there is no need to apply Grace and OneLever
                modified |= modTickSnapping;
            }
            else
            {
                modified |= modGraceAndOneLever;
                modified |= GetOrgEndWithTickSnappingOnly(xEndWithGraceAndOneLever - xOrgWithGraceAndOneLever, xOrgWithGraceAndOneLever, xEndWithGraceAndOneLever, isOrgExtendable, isEndExtendable, out xOrgWithTickSnapping, out xEndWithTickSnapping, out decadesPerMajorTick, out minorTicks);
            }

            xorg = xOrgWithTickSnapping;
            xend = xEndWithTickSnapping;

            _cachedMajorMinor = new CachedMajorMinor(xorg, xend, decadesPerMajorTick, minorTicks);

            return(modified);
        }
コード例 #2
0
ファイル: LinearTickSpacing.cs プロジェクト: Altaxo/Altaxo
		private bool InternalPreProcessScaleBoundaries(ref double xorg, ref double xend, bool isOrgExtendable, bool isEndExtendable)
		{
			_cachedMajorMinor = null;
			bool modified = false;

			if (xend == xorg)
			{
				if (xend == 0)
				{
					xorg = -1;
					xend = 1;
				}
				else
				{
					xend += 0.25 * Math.Abs(xend);
					xorg -= 0.25 * Math.Abs(xend);
				}
				modified = true;
			}

			if (!(xorg > double.MinValue && xorg < double.MaxValue))
			{
				xorg = double.MinValue;
				modified = true;
			}
			if (!(xend > double.MinValue && xend < double.MaxValue))
			{
				xend = double.MaxValue;
				modified = true;
			}
			if (!(xorg <= xend))
			{
				var h = xorg;
				xorg = xend;
				xend = h;
				modified = true;
			}
			// here xorg and xend should both be positive, with xorg < xend

			// try applying Grace and OneLever only ...
			double xOrgWithGraceAndOneLever, xEndWithGraceAndOneLever;
			bool modGraceAndOneLever = GetOrgEndWithGraceAndZeroLever(xorg, xend, isOrgExtendable, isEndExtendable, out xOrgWithGraceAndOneLever, out xEndWithGraceAndOneLever);

			// try applying tick snapping only (without Grace and OneLever)
			double xOrgWithTickSnapping, xEndWithTickSnapping;
			double majorTickSpan;
			int minorTicks;
			bool modTickSnapping = GetOrgEndWithTickSnappingOnly(xend - xorg, xorg, xend, isOrgExtendable, isEndExtendable, out xOrgWithTickSnapping, out xEndWithTickSnapping, out majorTickSpan, out minorTicks);

			// now compare the two
			if (xOrgWithTickSnapping <= xOrgWithGraceAndOneLever && xEndWithTickSnapping >= xEndWithGraceAndOneLever)
			{
				// then there is no need to apply Grace and OneLever
				modified |= modTickSnapping;
			}
			else
			{
				modified |= modGraceAndOneLever;
				modified |= GetOrgEndWithTickSnappingOnly(xEndWithGraceAndOneLever - xOrgWithGraceAndOneLever, xOrgWithGraceAndOneLever, xEndWithGraceAndOneLever, isOrgExtendable, isEndExtendable, out xOrgWithTickSnapping, out xEndWithTickSnapping, out majorTickSpan, out minorTicks);
			}

			xorg = xOrgWithTickSnapping;
			xend = xEndWithTickSnapping;

			_cachedMajorMinor = new CachedMajorMinor(xOrgWithTickSnapping, xEndWithTickSnapping, majorTickSpan, minorTicks);

			return modified; ;
		}
コード例 #3
0
        private bool InternalPreProcessScaleBoundaries(ref double xorg, ref double xend, bool isOrgExtendable, bool isEndExtendable)
        {
            _cachedMajorMinor = null;
            bool modified = false;

            if (xend == xorg)
            {
                if (xend == 0)
                {
                    xorg = -1;
                    xend = 1;
                }
                else
                {
                    xend += 0.25 * Math.Abs(xend);
                    xorg -= 0.25 * Math.Abs(xend);
                }
                modified = true;
            }

            if (!(xorg > double.MinValue && xorg < double.MaxValue))
            {
                xorg     = double.MinValue;
                modified = true;
            }
            if (!(xend > double.MinValue && xend < double.MaxValue))
            {
                xend     = double.MaxValue;
                modified = true;
            }
            if (!(xorg <= xend))
            {
                var h = xorg;
                xorg     = xend;
                xend     = h;
                modified = true;
            }

            bool modGraceAndOneLever = GetOrgEndWithGraceAndZeroLever(xorg, xend, isOrgExtendable, isEndExtendable, out var xOrgWithGraceAndOneLever, out var xEndWithGraceAndOneLever);
            bool modTickSnapping     = GetOrgEndWithTickSnappingOnly(xend - xorg, xorg, xend, isOrgExtendable, isEndExtendable, out var xOrgWithTickSnapping, out var xEndWithTickSnapping, out var majorTickSpan, out var minorTicks);

            // now compare the two
            if (xOrgWithTickSnapping <= xOrgWithGraceAndOneLever && xEndWithTickSnapping >= xEndWithGraceAndOneLever)
            {
                // then there is no need to apply Grace and OneLever
                modified |= modTickSnapping;
            }
            else
            {
                modified |= modGraceAndOneLever;
                modified |= GetOrgEndWithTickSnappingOnly(xEndWithGraceAndOneLever - xOrgWithGraceAndOneLever, xOrgWithGraceAndOneLever, xEndWithGraceAndOneLever, isOrgExtendable, isEndExtendable, out xOrgWithTickSnapping, out xEndWithTickSnapping, out majorTickSpan, out minorTicks);
            }

            xorg = xOrgWithTickSnapping;
            xend = xEndWithTickSnapping;

            _cachedMajorMinor = new CachedMajorMinor(xOrgWithTickSnapping, xEndWithTickSnapping, majorTickSpan, minorTicks);

            return(modified);

            ;
        }
コード例 #4
0
ファイル: Log10TickSpacing.cs プロジェクト: Altaxo/Altaxo
		private bool InternalPreProcessScaleBoundaries(ref double xorg, ref double xend, bool isOrgExtendable, bool isEndExtendable)
		{
			_cachedMajorMinor = null;
			bool modified = false;

			// both xorg and xend have to be positive finite
			if (xorg == xend)
			{
				xorg /= 4;
				xend *= 4;
				modified = true;
			}
			if (!(xorg > 0 && xorg < double.MaxValue))
			{
				xorg = double.Epsilon;
				modified = true;
			}
			if (!(xend > 0 && xend < double.MaxValue))
			{
				xend = double.MaxValue;
				modified = true;
			}
			if (!(xorg <= xend))
			{
				var h = xorg;
				xorg = xend;
				xend = h;
				modified = true;
			}
			// here xorg and xend should both be positive, with xorg < xend

			// try applying Grace and OneLever only ...
			double xOrgWithGraceAndOneLever, xEndWithGraceAndOneLever;
			bool modGraceAndOneLever = GetOrgEndWithGraceAndOneLever(xorg, xend, isOrgExtendable, isEndExtendable, out xOrgWithGraceAndOneLever, out xEndWithGraceAndOneLever);

			// try applying tick snapping only (without Grace and OneLever)
			double xOrgWithTickSnapping, xEndWithTickSnapping;
			int decadesPerMajorTick, minorTicks;
			bool modTickSnapping = GetOrgEndWithTickSnappingOnly(Math.Log10(xend) - Math.Log10(xorg), xorg, xend, isOrgExtendable, isEndExtendable, out xOrgWithTickSnapping, out xEndWithTickSnapping, out decadesPerMajorTick, out minorTicks);

			// now compare the two
			if (xOrgWithTickSnapping <= xOrgWithGraceAndOneLever && xEndWithTickSnapping >= xEndWithGraceAndOneLever)
			{
				// then there is no need to apply Grace and OneLever
				modified |= modTickSnapping;
			}
			else
			{
				modified |= modGraceAndOneLever;
				modified |= GetOrgEndWithTickSnappingOnly(Math.Log10(xEndWithGraceAndOneLever) - Math.Log10(xOrgWithGraceAndOneLever), xOrgWithGraceAndOneLever, xEndWithGraceAndOneLever, isOrgExtendable, isEndExtendable, out xOrgWithTickSnapping, out xEndWithTickSnapping, out decadesPerMajorTick, out minorTicks);
			}

			xorg = xOrgWithTickSnapping;
			xend = xEndWithTickSnapping;

			_cachedMajorMinor = new CachedMajorMinor(xorg, xend, decadesPerMajorTick, minorTicks);

			return modified;
		}