Ejemplo n.º 1
0
        private bool ParseFix(string line, TrackSegment trackSegment, DateTime date)
        {
            if (string.IsNullOrWhiteSpace(line))
                return false;

            var match = Regex.Match(line, B_LINE_REGEX);
            if (match.Success)
            {
                string h = match.Groups["h"].Value;
                string m = match.Groups["m"].Value;
                string s = match.Groups["s"].Value;
                string coord = match.Groups["coord"].Value;
                string validAlt = match.Groups["validAlt"].Value;
                string presAlt = match.Groups["presAlt"].Value;
                string gpsAlt = match.Groups["gpsAlt"].Value;

                var cood = ParseCoordinate(coord);
                var fix = new Fix(cood.Latitude, cood.Longitude, double.Parse(gpsAlt), date.AddHours(int.Parse(h)).AddMinutes(int.Parse(m)).AddSeconds(int.Parse(s)));

                trackSegment.Fixes.Add(fix);
                return true;
            }
            return false;
        }
Ejemplo n.º 2
0
 public bool BiasGreaterThan(Fix a, Fix b)
 {
     return(a >= b * settings.biasRelative + a * settings.biasAbsolute);
 }
Ejemplo n.º 3
0
 public void RemoveFix(Fix fix)
 {
     FixDic[fix.PropertyID].Remove(fix);
 }
Ejemplo n.º 4
0
        public void RatioTest()
        {
            var fix = Fix.Ratio(1, 2);

            FixAssert.AssertEquals(fix, 0.5f, Epsilon);
        }
Ejemplo n.º 5
0
 private void Awake()
 {
     instance = this;
     s        = settings;
     resting  = (settings.gravity * settings.deltaTime).GetMagnitudeSquared() + Fix.Epsilon;
 }
Ejemplo n.º 6
0
 public void Sub(ref FixVec2 b)
 {
     _x -= b._x;
     _y -= b._y;
 }
Ejemplo n.º 7
0
 public FixVec2(Fix x, Fix y)
 {
     _x = x;
     _y = y;
 }
Ejemplo n.º 8
0
 public AABB(FixVec2 p, Fix r)
     : this(p.X - r, p.Y - r, p.X + r, p.Y + r)
 {
 }
Ejemplo n.º 9
0
 /// Constructs a cpBB centered on a point with the given extents (half sizes).
 public AABB(FixVec2 c, Fix hwMax, Fix hhMax) : this(c.X - hwMax, c.Y - hhMax, c.X + hwMax, c.Y + hhMax)
 {
 }
Ejemplo n.º 10
0
 public AngularDamping(Fix value)
 {
     Value = value;
 }
 public WeightedBehaviourBuilder(AcceptSteeringBehaviour accept, TFinalizeResult result, Fix weight)
 {
     _accept = accept;
     _result = result;
     _weight = weight;
 }
Ejemplo n.º 12
0
        private void Visit(Result result, string resultPointer)
        {
            Analyze(result, resultPointer);

            if (result.Locations != null)
            {
                Location[] locations        = result.Locations.ToArray();
                string     locationsPointer = resultPointer.AtProperty(SarifPropertyName.Locations);

                for (int i = 0; i < locations.Length; ++i)
                {
                    Location location        = locations[i];
                    string   locationPointer = locationsPointer.AtIndex(i);

                    Visit(location, locationPointer);
                }
            }

            if (result.CodeFlows != null)
            {
                CodeFlow[] codeFlows        = result.CodeFlows.ToArray();
                string     codeFlowsPointer = resultPointer.AtProperty(SarifPropertyName.CodeFlows);

                for (int i = 0; i < codeFlows.Length; ++i)
                {
                    CodeFlow codeFlow        = codeFlows[i];
                    string   codeFlowPointer = codeFlowsPointer.AtIndex(i);

                    Visit(codeFlow, codeFlowPointer);
                }
            }

            if (result.Stacks != null)
            {
                Stack[] stacks        = result.Stacks.ToArray();
                string  stacksPointer = resultPointer.AtProperty(SarifPropertyName.Stacks);

                for (int i = 0; i < stacks.Length; ++i)
                {
                    Stack  stack        = stacks[i];
                    string stackPointer = stacksPointer.AtIndex(i);

                    Visit(stack, stackPointer);
                }
            }

            if (result.RelatedLocations != null)
            {
                AnnotatedCodeLocation[] relatedLocations = result.RelatedLocations.ToArray();
                string relatedLocationsPointer           = resultPointer.AtProperty(SarifPropertyName.RelatedLocations);

                for (int i = 0; i < relatedLocations.Length; ++i)
                {
                    AnnotatedCodeLocation relatedLocation = relatedLocations[i];
                    string relatedLocationPointer         = relatedLocationsPointer.AtIndex(i);

                    Visit(relatedLocation, relatedLocationPointer);
                }
            }

            if (result.Fixes != null)
            {
                Fix[]  fixes        = result.Fixes.ToArray();
                string fixesPointer = resultPointer.AtProperty(SarifPropertyName.Fixes);

                for (int i = 0; i < fixes.Length; ++i)
                {
                    Fix    fix        = fixes[i];
                    string fixPointer = fixesPointer.AtIndex(i);

                    Visit(fix, fixPointer);
                }
            }
        }
Ejemplo n.º 13
0
 public FixVec2(Fix x, Fix y)
 {
     X = x;
     Y = y;
 }
Ejemplo n.º 14
0
 private FixVec2 ScalarMultiply(Fix value)
 {
     return(new FixVec2(X * value, Y * value));
 }
Ejemplo n.º 15
0
 private FixVec2 ScalarAdd(Fix value)
 {
     return(new FixVec2(X + value, Y + value));
 }
Ejemplo n.º 16
0
 /// Constructs a cpBB for a circle with the given position and radius.
 public static AABB NewForCircle(FixVec2 p, Fix r)
 {
     return(new AABB(p.X - r, p.Y - r, p.X + r, p.Y + r));
 }
Ejemplo n.º 17
0
 public static FixVec2 ClampMagnitude(FixVec2 vector, Fix maxMagnitude)
 {
     ClampMagnitude(ref vector, maxMagnitude);
     return(vector);
 }
Ejemplo n.º 18
0
 private static void Render <T>(T model, Func <Action <T>, Action <T> > f)
 {
     Fix(f)(model);
 }
Ejemplo n.º 19
0
 public void Scale(ref Fix scale)
 {
     _x *= scale;
     _y *= scale;
 }
Ejemplo n.º 20
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        var valueLabelRect = new Rect(position.x, position.y, 50, position.height);
        var valueXRect     = new Rect(position.x + 65, position.y, 50, position.height);
        var valueYRect     = new Rect(position.x + 115, position.y, 50, position.height);
        var buttonRect     = new Rect(position.x + 175, position.y, 20, position.height);

        EditorGUI.LabelField(valueLabelRect, $"{Fix.RawToString(property.FindPropertyRelative("x").FindPropertyRelative("raw").intValue)},{Fix.RawToString(property.FindPropertyRelative("y").FindPropertyRelative("raw").intValue)}");

        valX = EditorGUI.DoubleField(valueXRect, valX);
        valY = EditorGUI.DoubleField(valueYRect, valY);

        if (GUI.Button(buttonRect, "A"))
        {
            property.FindPropertyRelative("x").FindPropertyRelative("raw").intValue = Fix.DoubleToRaw(valX);
            property.FindPropertyRelative("y").FindPropertyRelative("raw").intValue = Fix.DoubleToRaw(valY);
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 21
0
 public Position(Fix x, Fix y)
 {
     Value = new FixVec2(x, y);
 }
Ejemplo n.º 22
0
        internal void Raycast(ITreeRaycastCallback callback, FixVec2 pointA, FixVec2 pointB)
        {
            FixVec2 r = pointB - pointA;

            if (r.GetMagnitudeSquared() <= Fix.zero)
            {
                return;
            }
            r.Normalize();

            // v is perpendicular to the segment.
            FixVec2 v     = FixVec2.Cross(Fix.one, r);
            FixVec2 abs_v = FixVec2.Abs(v);

            // Separating axis for segment (Gino, p80).
            // |dot(v, p1 - c)| > dot(|v|, h)

            Fix maxFraction = Fix.one;

            // Build a bounding box for the segment.
            AABB    segmentAABB = new AABB();
            FixVec2 t           = pointA + maxFraction * (pointB - pointA);

            segmentAABB.min = FixVec2.Min(pointA, t);
            segmentAABB.max = FixVec2.Max(pointA, t);

            Stack <int> stack = new Stack <int>();

            stack.Push(rootIndex);

            while (stack.Count > 0)
            {
                var nodeId = stack.Pop();
                if (nodeId == nullNode)
                {
                    continue;
                }

                var node = nodes[nodeId];

                if (!node.aabb.Overlaps(segmentAABB))
                {
                    continue;
                }

                // Separating axis for segment (Gino, p80).
                // |dot(v, p1 - c)| > dot(|v|, h)
                var c          = node.aabb.GetCenter();
                var h          = node.aabb.GetExtents();
                var separation = FixMath.Abs(FixVec2.Dot(v, pointA - c)) - FixVec2.Dot(abs_v, h);
                if (separation > Fix.zero)
                {
                    continue;
                }

                if (node.IsLeaf())
                {
                    Fix value = callback.RayCastCallback(pointA, pointB, maxFraction, nodeId);

                    if (value == Fix.zero)
                    {
                        // The client has terminated the ray cast.
                        return;
                    }

                    if (value > Fix.zero)
                    {
                        // Update segment bounding box.
                        maxFraction = value;
                        FixVec2 g = pointA + maxFraction * (pointB - pointA);
                        segmentAABB.min = FixVec2.Min(pointA, g);
                        segmentAABB.max = FixVec2.Max(pointA, g);
                    }
                }
                else
                {
                    stack.Push(node.leftChildIndex);
                    stack.Push(node.rightChildIndex);
                }
            }
        }
Ejemplo n.º 23
0
        public void CreateDecimalTest()
        {
            var fix = Fix.CreateDecimal(1, 12, 2);

            FixAssert.AssertEquals(fix, 1.12f, Epsilon);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Pick the best sibling for a leaf node using "Branch and Bound" algorithm.
        /// </summary>
        /// <param name="leafIndex">The index of the leaf node we want a sibling for.</param>
        private int PickBestSibling(AABB leafAABB)
        {
            int index = rootIndex;

            while (!nodes[index].IsLeaf())
            {
                int childLeft  = nodes[index].leftChildIndex;
                int childRight = nodes[index].rightChildIndex;

                Fix area = nodes[index].aabb.Area();

                AABB combinedAABB = AABB.Union(nodes[index].aabb, leafAABB);
                Fix  combinedArea = combinedAABB.Area();

                // Cost of creating a new parent for this node and the new leaf
                Fix cost = 2 * combinedArea;

                // Minimum cost of pushing the leaf further down the tree
                Fix inheritanceCost = 2 * (combinedArea - area);

                // Cost of descending into left child
                Fix costLeft;
                if (nodes[childLeft].IsLeaf())
                {
                    AABB aabb = AABB.Union(leafAABB, nodes[childLeft].aabb);
                    costLeft = aabb.Area() + inheritanceCost;
                }
                else
                {
                    AABB aabb    = AABB.Union(leafAABB, nodes[childLeft].aabb);
                    Fix  oldArea = nodes[childLeft].aabb.Area();
                    Fix  newArea = aabb.Area();
                    costLeft = (newArea - oldArea) + inheritanceCost;
                }

                // Cost of descending into right child
                Fix costRight;
                if (nodes[childRight].IsLeaf())
                {
                    AABB aabb = AABB.Union(leafAABB, nodes[childRight].aabb);
                    costRight = AABB.Area(aabb) + inheritanceCost;
                }
                else
                {
                    AABB aabb    = AABB.Union(leafAABB, nodes[childRight].aabb);
                    Fix  oldArea = AABB.Area(nodes[childRight].aabb);
                    Fix  newArea = AABB.Area(aabb);
                    costRight = (newArea - oldArea) + inheritanceCost;
                }

                // Descend according to the minimum cost.
                if (cost < costLeft && cost < costRight)
                {
                    break;
                }

                // Descend
                if (costLeft < costRight)
                {
                    index = childLeft;
                }
                else
                {
                    index = childRight;
                }
            }
            return(index);
        }
Ejemplo n.º 25
0
 public void StepPhysics(Fix dt)
 {
     physicsScene.Step();
 }
Ejemplo n.º 26
0
 public FixTrans2 Rotate(Fix radians)
 {
     return(MakeRotation(radians) * this);
 }
Ejemplo n.º 27
0
        public static TFRaycastHit2D Raycast(FixVec2 origin, FixVec2 direction, Fix distance, TFLayerMask mask)
        {
            TFRaycastHit2D hit = physicsScene.Raycast(origin, direction, distance, mask);

            return(hit);
        }
Ejemplo n.º 28
0
 private FixVec2 ScalarAdd(Fix value)
 {
     return(new FixVec2(_x + value, _y + value));
 }
Ejemplo n.º 29
0
        internal Result CreateResult(TSLintLogEntry entry)
        {
            entry = entry ?? throw new ArgumentNullException(nameof(entry));

            Result result = new Result()
            {
                RuleId  = entry.RuleName,
                Message = new Message {
                    Text = entry.Failure
                }
            };

            switch (entry.RuleSeverity)
            {
            case "ERROR":
                result.Level = ResultLevel.Error;
                break;

            case "WARN":
            case "WARNING":
                result.Level = ResultLevel.Warning;
                break;

            case "DEFAULT":
            default:
                result.Level = ResultLevel.Note;
                break;
            }

            Region region = new Region()
            {
                // The TSLint logs have line and column start at 0, Sarif has them starting at 1, so add 1 to each
                StartLine   = entry.StartPosition.Line + 1,
                StartColumn = entry.StartPosition.Character + 1,
                EndLine     = entry.EndPosition.Line + 1,
                EndColumn   = entry.EndPosition.Character + 1,

                CharOffset = entry.StartPosition.Position
            };

            int length = entry.EndPosition.Position - entry.StartPosition.Position;

            region.CharLength = length > 0 ? length : 0;

            Uri analysisTargetUri = new Uri(entry.Name, UriKind.Relative);

            var      physicalLocation = new PhysicalLocation(id: 0, fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null), region: region, contextRegion: null);
            Location location         = new Location()
            {
                PhysicalLocation = physicalLocation
            };

            result.Locations = new List <Location>()
            {
                location
            };

            if (entry.Fixes?.Any() == true)
            {
                IList <Replacement> replacements = new List <Replacement>();

                foreach (TSLintLogFix fix in entry.Fixes)
                {
                    Replacement replacement = new Replacement();

                    replacement.DeletedRegion = new Region
                    {
                        CharLength = fix.InnerLength,
                        CharOffset = fix.InnerStart
                    };

                    if (!string.IsNullOrEmpty(fix.InnerText))
                    {
                        replacement.InsertedContent = new FileContent
                        {
                            Text = fix.InnerText
                        };
                    }

                    replacements.Add(replacement);
                }

                FileChange sarifFileChange = new FileChange(fileLocation: new FileLocation(uri: analysisTargetUri, uriBaseId: null), replacements: replacements);

                Fix sarifFix = new Fix(description: null, fileChanges: new List <FileChange>()
                {
                    sarifFileChange
                });
                result.Fixes = new List <Fix> {
                    sarifFix
                };
            }

            return(result);
        }
Ejemplo n.º 30
0
 private FixVec2 ScalarMultiply(Fix value)
 {
     return(new FixVec2(_x * value, _y * value));
 }
Ejemplo n.º 31
0
        private bool ParseFix(string line, TrackSegment trackSegment)
        {
            if (line.IsNullOrWhitespace())
                return false;

            var match = Regex.Match(line, FIX_SENTENCE);
            if (match.Success)
            {
                int h = int.Parse(match.Groups["h"].Value);
                int m = int.Parse(match.Groups["m"].Value);
                double s = double.Parse(match.Groups["s"].Value);
                double alt = double.Parse(match.Groups["alt"].Value);
                double lat = ConvertOrd(match.Groups["lat"].Value, match.Groups["latd"].Value);
                double lon = ConvertOrd(match.Groups["lon"].Value, match.Groups["lond"].Value);

                var fix = new Fix(lat, lon, alt, DateTime.MinValue.AddHours(h).AddMinutes(m).AddSeconds(s));
                trackSegment.Fixes.Add(fix);

                return true;
            }
            return false;
        }
 public WeightedBehaviour(Fix weight, SteeringBehaviour behaviour)
 {
     _weight    = weight;
     _behaviour = behaviour;
 }