Ejemplo n.º 1
0
        private bool TryInferTypes()
        {
            var inferred = false;

            foreach (ExtendedTypeReference unresolvedType in
                     _typeRegistrar.GetUnresolved().OfType <ExtendedTypeReference>())
            {
                if (Scalars.TryGetScalar(unresolvedType.Type.Type, out Type? scalarType))
                {
                    inferred = true;

                    ExtendedTypeReference typeReference = _typeInspector.GetTypeRef(scalarType);
                    _unregistered.Add(typeReference);
                    _typeRegistrar.MarkResolved(unresolvedType);
                    _typeRegistry.TryRegister(unresolvedType, typeReference);
                }
                else if (SchemaTypeResolver.TryInferSchemaType(
                             _typeInspector, unresolvedType, out ExtendedTypeReference schemaType))
                {
                    inferred = true;

                    _unregistered.Add(schemaType);
                    _typeRegistrar.MarkResolved(unresolvedType);
                }
            }

            return(inferred);
        }
Ejemplo n.º 2
0
        public override bool Contains(Vector2Double position)
        {
            if (Curve == null)
            {
                return(false);
            }

            if (leftComponent is SpecificationComponent && (Curve.GetPoint(leftComponent.Position) - position).Length < 15)
            {
                return(false);
            }
            if (rightComponent is SpecificationComponent && (Curve.GetPoint(rightComponent.Position) - position).Length < 15)
            {
                return(false);
            }

            foreach (double testedPosition in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1))
            {
                if ((Curve.GetPoint(testedPosition) - position).Length < 10)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override void MouseMove(Vector2Double mousePosition)
        {
            if (IsDragging)
            {
                if (IsShiftDown)
                {
                    double closestPosition =
                        (
                            from position in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1)
                            let distance = (Curve.GetPoint(position) - mousePosition).Length
                                           orderby distance ascending
                                           select position
                        )
                        .First();

                    CurrentPosition = closestPosition;
                    point           = Curve.GetPoint(closestPosition);
                }
                else
                {
                    Point += DragVector * SlowDownFactor;
                }

                OnSpecificationChanged();
                Changed();
            }

            base.MouseMove(mousePosition);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sorts the input array based on each element's two's complement bitwise representation.
        /// </summary>
        public void Sort(Span <int> span)
        {
            for (int i = 0; i < 32; i += 4)
            {
                bool hasRemain = false;

                for (int j = 0; j < span.Length; j++)
                {
                    uint number = Scalars.Int32ToUInt32Bits(span[j]);

                    uint remain = number >> i;
                    uint digit  = remain & 0b1111;

                    if (i == 28)
                    {
                        digit ^= 0b1000;
                    }

                    buckets[digit].Add(number);
                    hasRemain |= remain != 0;
                }

                Copy(span, uintToIntConverter);
                Clear();

                if (!hasRemain)
                {
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        private enDev2ColumnArgumentDirection AddScalarsShape(XmlNode c, ref XmlAttribute descAttribute, ref XmlAttribute columnIoDirection)
        {
            enDev2ColumnArgumentDirection columnDirection;

            if (c.Attributes != null)
            {
                descAttribute     = c.Attributes["Description"];
                columnIoDirection = c.Attributes["ColumnIODirection"];
            }
            var descriptionValue = "";

            columnDirection = enDev2ColumnArgumentDirection.None;
            if (descAttribute != null)
            {
                descriptionValue = descAttribute.Value;
            }
            if (columnIoDirection != null)
            {
                Enum.TryParse(columnIoDirection.Value, true, out columnDirection);
            }
            var scalar = new Scalar {
                Name = c.Name, Description = descriptionValue, IODirection = columnDirection, IsEditable = true
            };

            Scalars.Add(scalar);
            ShapeScalars.Add(scalar);
            return(columnDirection);
        }
Ejemplo n.º 6
0
        private bool TryInferTypes()
        {
            bool inferred = false;

            foreach (IClrTypeReference unresolvedType in _typeRegistrar.GetUnresolved())
            {
                if (Scalars.TryGetScalar(unresolvedType.Type, out IClrTypeReference schemaType))
                {
                    inferred = true;

                    _unregistered.Add(schemaType);
                    _typeRegistrar.MarkResolved(unresolvedType);

                    if (!_clrTypeReferences.ContainsKey(unresolvedType))
                    {
                        _clrTypeReferences.Add(unresolvedType, schemaType);
                    }
                }
                else if (SchemaTypeResolver.TryInferSchemaType(unresolvedType, out schemaType))
                {
                    inferred = true;

                    _unregistered.Add(schemaType);
                    _typeRegistrar.MarkResolved(unresolvedType);
                }
            }

            return(inferred);
        }
Ejemplo n.º 7
0
        public static WaveletCollection FromWaveletData(IEnumerable <double> waveletData)
        {
            int index = 0;

            double smoothingCoefficient = waveletData.ElementAt(index++);

            List <List <double> > decomposition = new List <List <double> >();

            int levelCount = (int)Scalars.Logarithm(2, waveletData.Count());

            for (int levelIndex = 0; levelIndex < levelCount; levelIndex++)
            {
                List <double> level = new List <double>();

                int itemCount = (int)Scalars.Exponentiate(2, levelIndex);

                for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
                {
                    level.Add(waveletData.ElementAt(index++));
                }

                decomposition.Add(level);
            }

            return(new WaveletCollection(smoothingCoefficient, decomposition));
        }
Ejemplo n.º 8
0
        public static ValueTerm IntegrateTrapezoid(FunctionTerm function, OrderedRange <double> bounds, int segmentCount)
        {
            if (segmentCount < 1)
            {
                throw new ArgumentOutOfRangeException("segmentCount");
            }

            ValueTerm segmentWidth = Terms.Constant(bounds.Length() / segmentCount);

            IEnumerable <ValueTerm> values =
                (
                    from segmentPosition in Scalars.GetIntermediateValuesSymmetric(bounds.Start, bounds.End, segmentCount)
                    select function.Apply(Terms.Constant(segmentPosition))
                )
                .ToArray();

            return(Terms.Product
                   (
                       segmentWidth,
                       Terms.Sum
                       (
                           Enumerables.Concatenate
                           (
                               Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.First())),
                               values.Skip(1).SkipLast(1),
                               Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.Last()))
                           )
                       )
                   ));
        }
Ejemplo n.º 9
0
        public static IEnumerable <Wave> SignalToSpectrum(IEnumerable <double> signal, double length)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }
            if (length <= 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            Complex[] spectrum = DiscreteFourierTransform.TransformForward(signal.Select(sample => (Complex)sample)).ToArray();

            for (int spectrumIndex = 0; spectrumIndex < spectrum.Length; spectrumIndex++)
            {
                double frequencyIndex  = spectrumIndex > spectrum.Length / 2 ? spectrumIndex - spectrum.Length : spectrumIndex;
                double frequency       = frequencyIndex / length;
                double cosineAmplitude = spectrum[spectrumIndex].Real;
                double sineAmplitude   = spectrum[spectrumIndex].Imaginary;
                double mixedAmplitude  = Scalars.SquareRoot(cosineAmplitude.Square() + sineAmplitude.Square());
                double amplitude       = mixedAmplitude / Scalars.SquareRoot(spectrum.Length);
                double phase           = Scalars.ArcTangent(sineAmplitude, cosineAmplitude);

                yield return(new Wave(frequency, amplitude, -phase / (2 * Math.PI) + 0.25));
            }
        }
Ejemplo n.º 10
0
        void PopulateForEachXmlElement(XmlNodeList children, IDictionary <string, int> indexCache)
        {
            foreach (XmlNode c in children)
            {
                var hasCorrectIoDirection      = true;
                var columnIoDirectionAttribute = c.Attributes?["ColumnIODirection"];
                if (columnIoDirectionAttribute != null)
                {
                    var columnIoDirectionValue             = columnIoDirectionAttribute.Value;
                    var hasCorrectIoDirectionFromAttribute = columnIoDirectionValue == enDev2ColumnArgumentDirection.Output.ToString() || columnIoDirectionValue == enDev2ColumnArgumentDirection.Both.ToString();
                    hasCorrectIoDirection = hasCorrectIoDirectionFromAttribute;
                }

                if (DataListUtil.IsSystemTag(c.Name) && !hasCorrectIoDirection)
                {
                    continue;
                }
                var recSet        = RecordSets.FirstOrDefault(set => set.Name == c.Name);
                var shapeRecSet   = ShapeRecordSets.FirstOrDefault(set => set.Name == c.Name);
                var scalar        = Scalars.FirstOrDefault(scalar1 => scalar1.Name == c.Name);
                var complexObject = ComplexObjects.FirstOrDefault(o => o.Name == "@" + c.Name);
                if (complexObject != null)
                {
                    SetComplexObjectValue(c, complexObject);
                }
                else
                {
                    SetScalarOrEcordsetValue(indexCache, c, recSet, shapeRecSet, scalar);
                }
            }
        }
Ejemplo n.º 11
0
        private bool InferSchemaTypesFromUnresolved()
        {
            bool resolved = false;

            foreach (IClrTypeReference unresolvedType in Unresolved.ToList())
            {
                if (Scalars.TryGetScalar(unresolvedType.Type,
                                         out IClrTypeReference schemaType))
                {
                    resolved = true;
                    _unregistered.Add(schemaType);
                    Unresolved.Remove(unresolvedType);
                    if (!ClrTypes.ContainsKey(unresolvedType))
                    {
                        ClrTypes.Add(unresolvedType, schemaType);
                    }
                }
                else if (SchemaTypeResolver.TryInferSchemaType(unresolvedType,
                                                               out schemaType))
                {
                    resolved = true;
                    _unregistered.Add(schemaType);
                    Unresolved.Remove(unresolvedType);
                }
            }

            return(resolved);
        }
Ejemplo n.º 12
0
        public static Wave operator +(Wave wave1, Wave wave2)
        {
            if (wave1.frequency != wave2.frequency)
            {
                throw new ArgumentException("The frequencies of 'wave1' and 'wave2' don't match.");
            }

            double basePhase       = wave1.phase;
            double phaseDifference = wave2.phase - wave1.phase;

            double frequency = Items.Equal(wave1.frequency, wave2.frequency);
            double amplitude = Scalars.SquareRoot
                               (
                wave1.amplitude.Square() +
                2 * wave1.amplitude * wave2.amplitude * Scalars.PSine(phaseDifference + 0.25) +
                wave2.amplitude.Square()
                               );
            double phase =
                basePhase +
                Scalars.ArcTangent
                (
                    wave2.amplitude * Scalars.PSine(phaseDifference),
                    wave1.amplitude + wave2.amplitude * Scalars.PSine(phaseDifference + 0.25)
                )
                / (2 * Math.PI);

            return(new Wave(frequency, amplitude, phase));
        }
Ejemplo n.º 13
0
        public IEnumerable <XElement> GetSvgPaths()
        {
            Kurve.Curves.Curve curve = optimizer.GetCurve(specification);

            IEnumerable <string> curveCommands = Enumerables.Concatenate
                                                 (
                Enumerables.Create(Svg.MoveTo(curve.GetPoint(0))),
                from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                let controlPoint1 = curve.GetPoint(positions.Item1) + (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item1)
                                    let controlPoint2 = curve.GetPoint(positions.Item2) - (1.0 / (3 * SegmentCount)) * curve.GetVelocity(positions.Item2)
                                                        let point2 = curve.GetPoint(positions.Item2)
                                                                     select Svg.CurveTo(controlPoint1, controlPoint2, point2)
                                                 );

            yield return(Svg.PathShape(curveCommands, null, Colors.Black, 2));

            IEnumerable <string> curvatureMarkersCommands =
                (
                    from positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges()
                    let position = Enumerables.Average(positions.Item1, positions.Item2)
                                   let curvatureVector = CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position)
                                                         select Svg.Line(curve.GetPoint(position), curve.GetPoint(position) + curvatureVector)
                );

            yield return(Svg.PathShape(curvatureMarkersCommands, null, Colors.Blue, 0.5));

            foreach (PointCurveSpecification pointCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <PointCurveSpecification>())
            {
                Vector2Double point = curve.GetPoint(pointCurveSpecification.Position);

                yield return(Svg.CircleShape(point, 10, Colors.Red, null, 0));
            }
            foreach (DirectionCurveSpecification directionCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <DirectionCurveSpecification>())
            {
                Vector2Double directionVector = curve.GetDirectionVector(directionCurveSpecification.Position);
                Vector2Double start           = curve.GetPoint(directionCurveSpecification.Position) - 1000 * directionVector;
                Vector2Double end             = curve.GetPoint(directionCurveSpecification.Position) + 1000 * directionVector;

                yield return(Svg.LineShape(start, end, null, Colors.Green, 2));
            }
            foreach (CurvatureCurveSpecification curvatureCurveSpecification in specification.BasicSpecification.CurveSpecifications.OfType <CurvatureCurveSpecification>())
            {
                if (curvatureCurveSpecification.Curvature == 0)
                {
                    Vector2Double directionVector = curve.GetDirectionVector(curvatureCurveSpecification.Position);
                    Vector2Double start           = curve.GetPoint(curvatureCurveSpecification.Position) - 1000 * directionVector;
                    Vector2Double end             = curve.GetPoint(curvatureCurveSpecification.Position) + 1000 * directionVector;

                    yield return(Svg.LineShape(start, end, null, Colors.Blue, 2));
                }
                else
                {
                    Vector2Double center = curve.GetPoint(curvatureCurveSpecification.Position) - (1.0 / curvatureCurveSpecification.Curvature) * curve.GetNormalVector(curvatureCurveSpecification.Position);
                    double        radius = 1.0 / curvatureCurveSpecification.Curvature.Absolute();

                    yield return(Svg.CircleShape(center, radius, null, Colors.Blue, 2));
                }
            }
        }
Ejemplo n.º 14
0
        public async Task InspectAsync(IRVisClient rVisClient)
        {
            if (_pathToContainingDirectory.IsntAString())
            {
                SetUpStaging();
            }
            RequireDirectory(_pathToContainingDirectory);
            var pathToCode = Combine(_pathToContainingDirectory, _codeFileName);

            await rVisClient.ClearAsync();

            var inspection = await rVisClient.InspectSymbolsAsync(pathToCode);

            SymbolInfos = inspection.ToArr();

            UnaryFunctions = SymbolInfos
                             .Filter(si =>
                                     si.Level == 0 &&
                                     si.Symbol.IsAString() &&
                                     si.SymbolType == SymbolType.Function &&
                                     si.Length == 1)
                             .OrderBy(si => si.Symbol)
                             .ToArr();

            Scalars = SymbolInfos
                      .Filter(si =>
                              si.Level == 0 &&
                              si.Symbol.IsAString() &&
                              si.SymbolType == SymbolType.Vector &&
                              si.Length == 1 &&
                              si.Scalar.HasValue)
                      .OrderBy(si => si.Symbol)
                      .ToArr();

            ScalarSets = SymbolInfos
                         .Filter(si =>
                                 si.Level == 0 &&
                                 si.Symbol.IsAString() &&
                                 (si.SymbolType == SymbolType.Vector || si.SymbolType == SymbolType.List) &&
                                 si.Names?.Length > 1 &&
                                 si.Value?.NRows == 1)
                         .OrderBy(si => si.Symbol)
                         .ToArr();

            DataSets = SymbolInfos
                       .Filter(si =>
                               si.Level == 0 &&
                               si.Value?.ColumnNames.All(cn => cn.IsAString()) == true &&
                               si.Value?.NRows > 1)
                       .OrderBy(si => si.Symbol)
                       .ToArr();

            ParameterCandidates = Scalars.Map(s => new ParameterCandidate(s));

            ValueCandidates = DataSets.Map(ds => new ValueCandidate(ds, SymbolInfos));
        }
Ejemplo n.º 15
0
    public static bool TryInferSchemaTypeKind(
        ExtendedTypeReference unresolvedType,
        out TypeKind kind)
    {
        if (unresolvedType == null)
        {
            throw new ArgumentNullException(nameof(unresolvedType));
        }

        var typeInfo = new TypeInfo(unresolvedType);

        if (IsObjectTypeExtension(typeInfo))
        {
            kind = TypeKind.Object;
            return(true);
        }

        if (IsUnionType(typeInfo))
        {
            kind = TypeKind.Union;
            return(true);
        }

        if (IsInterfaceType(typeInfo))
        {
            kind = TypeKind.Interface;
            return(true);
        }

        if (IsObjectType(typeInfo))
        {
            kind = TypeKind.Object;
            return(true);
        }

        if (IsInputObjectType(typeInfo))
        {
            kind = TypeKind.InputObject;
            return(true);
        }

        if (IsEnumType(typeInfo))
        {
            kind = TypeKind.Enum;
            return(true);
        }

        if (Scalars.TryGetScalar(unresolvedType.Type.Type, out _))
        {
            kind = TypeKind.Scalar;
            return(true);
        }

        kind = default;
        return(false);
    }
Ejemplo n.º 16
0
        /// <summary>
        /// Sorts the input float array based on each element's IEEE 754 bit representation.
        /// </summary>
        public void Sort(Span <float> span)
        {
            for (int i = 0; i < 32; i += 4)
            {
                bool hasRemain = false;

                for (int j = 0; j < span.Length; j++)
                {
                    uint number = Scalars.SingleToUInt32Bits(span[j]);

                    uint remain = number >> i;
                    uint digit  = remain & 0b1111;

                    buckets[digit].Add(number);
                    hasRemain |= remain != 0;
                }

                if (i == 28)                 //The last pass requires a special copy to support negative numbers
                {
                    int index = 0;           //The filling index targeting array
                    int half  = buckets.Length / 2;

                    for (int j = buckets.Length - 1; j >= half; j--)
                    {
                        List <uint> bucket = buckets[j];

                        for (int k = bucket.Count - 1; k >= 0; k--)
                        {
                            span[index++] = Scalars.UInt32ToSingleBits(bucket[k]);
                        }
                    }

                    for (int j = 0; j < half; j++)
                    {
                        List <uint> bucket = buckets[j];

                        for (int k = 0; k < bucket.Count; k++)
                        {
                            span[index++] = Scalars.UInt32ToSingleBits(bucket[k]);
                        }
                    }
                }
                else
                {
                    Copy(span, uintToFloatConverter);
                }

                Clear();

                if (!hasRemain)
                {
                    break;
                }
            }
        }
Ejemplo n.º 17
0
        public double Map(double value)
        {
            if (value < source.Start || value > source.End)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            double fraction = (value - source.Start) / (source.End - source.Start);

            return(Scalars.InterpolateSine(destination.Start, destination.End, fraction));
        }
Ejemplo n.º 18
0
        public override void Draw(Context context)
        {
            if (Curve != null && IsSelected)
            {
                foreach (Tuple <double, double> positions in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1).GetRanges())
                {
                    Drawing.DrawLine(context, Curve.GetPoint(positions.Item1), Curve.GetPoint(positions.Item2), 8, Colors.Green.ReplaceAlpha(0.3));
                }
            }

            base.Draw(context);
        }
Ejemplo n.º 19
0
        static float FRSqrt(float value)
        {
            float x2 = value * 0.5F;
            int   i  = Scalars.SingleToInt32Bits(value);

            i = 0x5f3759df - (i >> 1);
            float y = Scalars.Int32ToSingleBits(i);

            y *= 1.5f - x2 * y * y;
            y *= 1.5f - x2 * y * y;

            return(y);
        }
Ejemplo n.º 20
0
        public bool TryPredictTypeKind(ITypeReference typeRef, out TypeKind kind)
        {
            if (_typeLookup.TryNormalizeReference(typeRef, out ITypeReference namedTypeRef) &&
                _typeRegistry.TryGetType(namedTypeRef, out RegisteredType registeredType))
            {
                switch (registeredType.Type)
                {
                case INamedType namedType:
                    kind = namedType.Kind;
                    return(true);

                case DirectiveType:
                    kind = TypeKind.Directive;
                    return(true);

                default:
                    kind = default;
                    return(false);
                }
            }

            namedTypeRef ??= typeRef;

            switch (namedTypeRef)
            {
            case ExtendedTypeReference r:
                if (Scalars.TryGetScalar(r.Type.Type, out _))
                {
                    kind = TypeKind.Scalar;
                    return(true);
                }

                if (r.Type.IsSchemaType)
                {
                    kind = GetTypeKindFromSchemaType(r.Type);
                    return(true);
                }

                return(SchemaTypeResolver.TryInferSchemaTypeKind(r, out kind));

            case SchemaTypeReference r:
                kind = GetTypeKindFromSchemaType(TypeInspector.GetType(r.Type.GetType()));
                return(true);

            default:
                kind = default;
                return(false);
            }
        }
Ejemplo n.º 21
0
        // Intended for synthesis
        // Input \ Output | Real | Imaginary
        // ---------------|------|----------
        // Real           |  +   |     -
        // Imaginary      |  +   |     +
        static MatrixComplex GetReverseTransformation(int size)
        {
            MatrixComplex transformation = new MatrixComplex(size, size);

            Complex factor = (2 * Math.PI / size) * Complex.ImaginaryOne;

            for (int row = 0; row < transformation.RowCount; row++)
            {
                for (int column = 0; column < transformation.ColumnCount; column++)
                {
                    transformation[row, column] = Scalars.Exponentiate(-factor * row * column);
                }
            }

            return((1 / Scalars.SquareRoot(size)) * transformation);
        }
Ejemplo n.º 22
0
        public WaveletCollection(double smoothingCoefficient, IEnumerable <IEnumerable <double> > decomposition)
        {
            if (decomposition == null)
            {
                throw new ArgumentNullException("levels");
            }
            for (int levelIndex = 0; levelIndex < decomposition.Count(); levelIndex++)
            {
                if (decomposition.ElementAt(levelIndex).Count() != (int)Scalars.Exponentiate(2, levelIndex))
                {
                    throw new ArgumentException("parameter 'decomposition' doesn't have the correct format");
                }
            }

            this.smoothingCoefficient = smoothingCoefficient;
            this.decomposition        = decomposition;
        }
Ejemplo n.º 23
0
        public override void MouseUp(Vector2Double mousePosition, MouseButton mouseButton)
        {
            if (IsRightMouseDown)
            {
                double closestPosition =
                    (
                        from position in Scalars.GetIntermediateValuesSymmetric(leftComponent.Position, rightComponent.Position, SegmentSegmentCount + 1)
                        let distance = (Curve.GetPoint(position) - mousePosition).Length
                                       orderby distance ascending
                                       select position
                    )
                    .First();

                OnAddSpecification(closestPosition);
            }

            base.MouseUp(mousePosition, mouseButton);
        }
Ejemplo n.º 24
0
 public void Register(
     ITypeRegistrar typeRegistrar,
     IEnumerable <ITypeReference> typeReferences)
 {
     foreach (ISyntaxTypeReference typeReference in
              typeReferences.OfType <ISyntaxTypeReference>())
     {
         if (Scalars.TryGetScalar(
                 typeReference.Type.NamedType().Name.Value,
                 out IClrTypeReference namedTypeReference))
         {
             if (!typeRegistrar.IsResolved(namedTypeReference))
             {
                 typeRegistrar.Register(typeRegistrar.CreateInstance(namedTypeReference.Type));
             }
         }
     }
 }
Ejemplo n.º 25
0
        public override void Draw(Context context)
        {
            if (curve != null)
            {
                foreach (Tuple <double, double> positions in Scalars.GetIntermediateValuesSymmetric(0, 1, SegmentCount + 1).GetRanges())
                {
                    double position = Enumerables.Average(positions.Item1, positions.Item2);

                    Vector2Double curvatureVector = CurveOptimizer.CurvatureMarkersFactor * curve.GetCurvature(position) * curve.GetNormalVector(position);

                    Krach.Graphics.Color lineColor = StretchColor(curve.GetSpeed(position) / basicSpecification.CurveLength);

                    Drawing.DrawLine(context, curve.GetPoint(position), curve.GetPoint(position) + curvatureVector, 0.5, Colors.Blue);
                    Drawing.DrawLine(context, curve.GetPoint(positions.Item1), curve.GetPoint(positions.Item2), 2, lineColor);
                }
            }

            base.Draw(context);
        }
Ejemplo n.º 26
0
        private static ISchema CreateSchema(DocumentNode schema)
        {
            SchemaBuilder builder = SchemaBuilder.New();

            foreach (CustomScalarType type in schema.Definitions
                     .OfType <ScalarTypeDefinitionNode>()
                     .Where(t => !Scalars.IsBuiltIn(t.Name.Value))
                     .Select(t => new CustomScalarType(t)))
            {
                builder.AddType(type);
            }

            return(builder.Use(next => context => Task.CompletedTask)
                   .AddDocument(schema)
                   .AddDirectiveType <NameDirectiveType>()
                   .AddDirectiveType <TypeDirectiveType>()
                   .AddDirectiveType <SerializationDirectiveType>()
                   .AddDirectiveType <DelegateDirectiveType>()
                   .ModifyOptions(t => t.StrictValidation = false)
                   .Create());
        }
Ejemplo n.º 27
0
        public IEnumerable <double> TransformReverse(IEnumerable <double> waveletData)
        {
            if (!Scalars.IsPowerOf2(waveletData.Count()))
            {
                throw new ArgumentOutOfRangeException("waveletData");
            }

            IntPtr waveletWorkspace = Native.CreateWaveletWorkspace((uint)waveletData.Count());

            IntPtr dataPointer = waveletData.Copy();

            Native.WaveletTransformReverse(wavelet, waveletWorkspace, dataPointer, (uint)waveletData.Count(), 1);

            IEnumerable <double> signal = dataPointer.Read <double>(waveletData.Count());

            dataPointer.Free();

            Native.DisposeWaveletWorkspace(waveletWorkspace);

            return(signal);
        }
        public void Register(
            ITypeRegistrar typeRegistrar,
            IEnumerable <ITypeReference> typeReferences)
        {
            foreach (SyntaxTypeReference typeReference in
                     typeReferences.OfType <SyntaxTypeReference>())
            {
                if (Scalars.TryGetScalar(
                        typeReference.Type.NamedType().Name.Value,
                        out Type? scalarType))
                {
                    ExtendedTypeReference namedTypeReference =
                        _typeInspector.GetTypeRef(scalarType);

                    if (!typeRegistrar.IsResolved(namedTypeReference))
                    {
                        typeRegistrar.Register(
                            typeRegistrar.CreateInstance(namedTypeReference.Type.Type),
                            typeReference.Scope);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public DiscreteCurve(Curve curve, int segmentCount)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            if (segmentCount < 1)
            {
                throw new ArgumentOutOfRangeException("segmentCount");
            }

            this.items =
                (
                    from position in Scalars.GetIntermediateValuesSymmetric(0, 1, segmentCount + 1)
                    select new DiscreteCurveItem
                    (
                        curve.GetPoint(position),
                        curve.GetSpeed(position),
                        curve.GetDirection(position),
                        curve.GetCurvature(position)
                    )
                )
                .ToArray();
        }
Ejemplo n.º 30
0
        public static IEnumerable <FunctionTerm> BernsteinPolynomialBasis(int length)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            ValueTerm variable = Variable("x");

            int degree = length - 1;

            return
                ((
                     from index in Enumerable.Range(0, length)
                     select Product
                     (
                         Constant(Scalars.BinomialCoefficient(degree, index)),
                         Exponentiation(variable, Constant(index)),
                         Exponentiation(Difference(Constant(1), variable), Constant(degree - index))
                     )
                     .Abstract(variable)
                     )
                 .ToArray());
        }