Exemple #1
0
        public static Point2D In(this UnitPoint2D unitPoint, SIPrefix targetSIPrefix, IUnitDefinition targetUnit)
        {
            var multiplier = new UnitValue(unitPoint.Unit, 1).In(targetSIPrefix, targetUnit);

            return(new Point2D(
                       multiplier * unitPoint.X,
                       multiplier * unitPoint.Y));
        }
Exemple #2
0
        public static Point2D In(this UnitPoint2D unitPoint, CompoundUnit targetUnit)
        {
            var multiplier = new UnitValue(unitPoint.Unit, 1).In(targetUnit);

            return(new Point2D(
                       multiplier * unitPoint.X,
                       multiplier * unitPoint.Y));
        }
Exemple #3
0
        public void DeserializationIsBackwardCompatible(string version, string json)
        {
            UnitPoint2D unitPoint = null;

            Assert.That(() => unitPoint = JsonConvert.DeserializeObject <UnitPoint2D>(json), Throws.Nothing);
            Assert.That(unitPoint, Is.Not.Null);
            Assert.That(unitPoint.In(SIPrefix.Milli, Unit.Meter).X, Is.EqualTo(1.5).Within(1e-6));
            Assert.That(unitPoint.In(SIPrefix.Milli, Unit.Meter).Y, Is.EqualTo(6.3).Within(1e-6));
        }
Exemple #4
0
        public void SerializationRoundTrip()
        {
            var         unitPoint = new UnitPoint2D(SIPrefix.Milli, Unit.Meter, 1.5, 6.3);
            var         json      = JsonConvert.SerializeObject(unitPoint);
            UnitPoint2D reconstructedUnitPoint = null;

            Assert.That(() => reconstructedUnitPoint = JsonConvert.DeserializeObject <UnitPoint2D>(json), Throws.Nothing);
            Assert.That(reconstructedUnitPoint, Is.Not.Null);
            Assert.That(reconstructedUnitPoint.Unit, Is.EqualTo(unitPoint.Unit));
            Assert.That(reconstructedUnitPoint.X, Is.EqualTo(unitPoint.X));
            Assert.That(reconstructedUnitPoint.Y, Is.EqualTo(unitPoint.Y));
        }
Exemple #5
0
        public static UnitVector2D VectorTo(this UnitPoint2D unitPoint1, UnitPoint2D unitPoint2)
        {
#if CHECK_UNITS
            if (unitPoint1.Unit != unitPoint2.Unit)
            {
                throw new InvalidOperationException($"Cannot calculate vector between points with different units, got {unitPoint1.Unit} and {unitPoint2.Unit}");
            }
#endif
            var commonUnit = unitPoint1.Unit;
            var vector     = unitPoint1.VectorTo((Point2D)unitPoint2);

            return(vector.To(commonUnit));
        }
Exemple #6
0
        public static UnitValue DistanceTo(this UnitPoint2D unitPoint1, UnitPoint2D unitPoint2)
        {
#if CHECK_UNITS
            if (unitPoint1.Unit != unitPoint2.Unit)
            {
                throw new InvalidOperationException($"Cannot calculate distance between points with different units, got {unitPoint1.Unit} and {unitPoint2.Unit}");
            }
#endif
            var commonUnit = unitPoint1.Unit;
            var distance   = unitPoint1.DistanceTo((Point2D)unitPoint2);

            return(distance.To(commonUnit));
        }
Exemple #7
0
        public void CanCreateAllPrefixUnitCombinations()
        {
            var prefixes = EnumExtensions.GetValues <SIPrefix>();
            var units    = Unit.Effective.AllUnits.ToList();

            foreach (var prefix in prefixes)
            {
                foreach (var unit in units)
                {
                    UnitPoint2D unitPoint = null;
                    Assert.That(() => unitPoint = new UnitPoint2D(prefix, unit, 4.2, -1.1), Throws.Nothing);
                    Assert.That(unitPoint, Is.Not.Null);
                    if (unit.InSet(Unit.Celsius, Unit.Fahrenheit)) // Because celsius/fahrenheit has a fixed offset,
                    // very small values are lost because of insignificance compared to offset
                    {
                        continue;
                    }

                    Assert.That(unitPoint.In(prefix, unit).X, Is.EqualTo(4.2).Within(1e-6));
                    Assert.That(unitPoint.In(prefix, unit).Y, Is.EqualTo(-1.1).Within(1e-6));
                }
            }
        }
 public RamachandranPlotFixedDistribution(AminoAcidName aminoAcidName, UnitPoint2D targetPhiPsi)
 {
     targetPhi     = targetPhiPsi.In(Unit.Degree).X.To(Unit.Degree);
     targetPsi     = targetPhiPsi.In(Unit.Degree).Y.To(Unit.Degree);
     AminoAcidName = aminoAcidName;
 }
Exemple #9
0
 public static Point2D In(this UnitPoint2D unitPoint, IUnitDefinition targetUnit)
 {
     return(unitPoint.In(SIPrefix.None, targetUnit));
 }