/// <summary> /// Initializes static members of the <see cref="GisTools"/> class. /// </summary> static GisTools() { CoordinateConversionManager = new CoordinateConversionManager(); GridCellManager = new GridCellManager(); GeoJsonUtils = new GeoJsonUtils(); GeometryTools = new GeometryTools(); }
private void RecalculateGeneralObjectLocation(GameSession gameSession, ICelestialObject celestialObject, EngineSettings settings) { var speedInTick = celestialObject.Speed / settings.UnitsPerSecond; var position = GeometryTools.MoveObject( new PointF(celestialObject.PositionX, celestialObject.PositionY), speedInTick, celestialObject.Direction); if (celestialObject is Missile missile) { var target = gameSession.GetCelestialObject(missile.TargetId).ToSpaceship(); var direction = GeometryTools.Azimuth(target.GetLocation(), missile.GetLocation()); position = GeometryTools.MoveObject(new PointF(celestialObject.PositionX, celestialObject.PositionY), speedInTick, direction); } Logger.Debug($"Object '{celestialObject.Name}' id='{celestialObject.Id}' moved from {celestialObject.GetLocation()} to {position}"); celestialObject.PreviousPositionX = celestialObject.PositionX; celestialObject.PreviousPositionY = celestialObject.PositionY; celestialObject.PositionX = position.X; celestialObject.PositionY = position.Y; }
private void OnSketchFinished() { ConfigUtil.type = "water"; IFeature pFeat = null; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); pFeat.Store(); m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.Message); m_editor.AbortOperation(); } finally { if (pFeat != null) { (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); } pFeat = null; } }
/// <summary> /// Clip intensity to project perimeter, fix geometry for intersection & difference /// Attention: "side effect" = geometry of intensity changes /// </summary> /// <param name="intens"></param> public void clipToProject(Intensity intens) { // trick to make all geometries valid for Intersection / Difference: Buffer(0.001) <<<<<<<<<<<<<<<<<<<<<< intens.geometry = GeometryTools.Polygon2Multipolygon(intens.geometry.Buffer(0.001)); //intensity can't be outside of perimeter var perimeter = DBManager.ActiveSession.QueryOver <Perimeter>().Where(p => p.Project.Id == intens.Project.Id).List <Perimeter>().FirstOrDefault(); if (perimeter == null || perimeter.geometry == null) { throw new NullReferenceException(nameof(perimeter) + " " + nameof(perimeter.geometry)); } IGeometry clippedIntens = perimeter.geometry.Intersection(intens.geometry); //keep multipolygon geometry clippedIntens = GeometryTools.Polygon2Multipolygon(clippedIntens.Buffer(0.001)); //area difference due to intersection double areaDifference = intens.geometry.Area - clippedIntens.Area; Debug.WriteLine($"PROJECT CLIPPING: Intensity {intens.ID}: area diff = {areaDifference:F2}, new area = {clippedIntens.Area:F2}, type: {intens.geometry.GeometryType} -> {clippedIntens.GeometryType}"); //assign new geometry intens.geometry = (MultiPolygon)clippedIntens; }
protected void AddOneCircle(int sid) { var edges = this.indexData.edgeToAdd.CPUData; var edgeCount = 0; var vBase = this.pCount; var center = new float3(UnityEngine.Random.value, UnityEngine.Random.value, 0) * 0.01f; var cid = vcount; var rand = UnityEngine.Random.value; var circle = GeometryTools.GenerateCirclePoint(vcount, this.radius); foreach (var i in Enumerable.Range(0, vcount)) { var i1 = i; var i2 = (i + 1) % vcount; edges[edgeCount++] = new EdgeToAdd(sid, i1 + vBase, i2 + vBase, circle[i1] + center, circle[i2] + center); } if (this.withCenter) { foreach (var i in Enumerable.Range(0, vcount)) { edges[edgeCount++] = new EdgeToAdd(sid, i + vBase, cid + vBase, circle[i] + center, center); } this.pCount += vcount + 1; } else { this.pCount += vcount; } while (edgeCount < edges.Length) { edges[edgeCount++] = new EdgeToAdd(-1, -1, -1, 0, 0); } }
private void OnSketchFinished() { IFeature pFeat; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); pFeat.Store(); m_editor.StopOperation("Add Point and split line"); (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); } catch (Exception ex) { MessageBox.Show("Error in the Add Point and Split\n" + ex.Message); m_editor.AbortOperation(); } finally { pFeat = null; } }
public static void DrawActiveCelestialObjects(IScreenInfo screenInfo, TacticalEnvironment environment) { var activeObject = environment.GetActiveObject(); if (activeObject is null) { return; } var pen = new Pen(Color.Gray); var spaceshipScreenLocation = UITools.ToScreenCoordinates(screenInfo, activeObject.GetLocation()); screenInfo.GraphicSurface.DrawEllipse(pen, spaceshipScreenLocation.X - 20, spaceshipScreenLocation.Y - 20, 40, 40); var mouseScreenLocation = UITools.ToScreenCoordinates(screenInfo, environment.GetMouseCoordinates()); var distance = GeometryTools.Distance(spaceshipScreenLocation, mouseScreenLocation); var direction = GeometryTools.Azimuth(spaceshipScreenLocation, mouseScreenLocation); var destinationPoint = GeometryTools.MoveObject(mouseScreenLocation, distance - 20, direction); if (distance > 20) { screenInfo.GraphicSurface.DrawLine(pen, mouseScreenLocation.X, mouseScreenLocation.Y, destinationPoint.X, destinationPoint.Y); } }
static void Postfix(ref SaberMovementData ____movementData, ref Transform ____topPos, ref Transform ____bottomPos, ref SaberTypeObject ____saberType) { if (!Config.enabled) { return; } var data = typeof(SaberMovementData).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(____movementData) as BladeMovementDataElement[]; int nextAddIndex = (int)typeof(SaberMovementData).GetField("_nextAddIndex", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(____movementData); var num = data.Length; int addIndex = nextAddIndex == 0 ? num - 1 : nextAddIndex - 1; var prevAddIndex = addIndex == 0 ? num - 1 : addIndex - 1; Vector3 prevTopPos = data[prevAddIndex].topPos; Vector3 prevBottomPos = data[prevAddIndex].bottomPos; var throwaway = Vector3.zero; Quaternion orientation = Quaternion.identity; var topPos = ____topPos.position; var bottomPos = ____bottomPos.position; GeometryTools.ThreePointsToBox(topPos, bottomPos, (prevBottomPos + prevTopPos) * 0.5f, out throwaway, out throwaway, out orientation); //Logger.log.Debug("test"); PlaneVisualizerController.instance.visualizer.UpdatePlane(topPos, orientation, ____saberType.saberType); }
public static ICelestialObject GenerateNpcShip(GameSession gameSession, int spaceShipClass, int spaceShipType, int standing) { var spaceship = gameSession.GetPlayerSpaceShip().ToSpaceship(); Spaceship newCelestialObject = null; switch (spaceShipType) { case 12: newCelestialObject = Fury.Generate(); break; default: break; } if (newCelestialObject != null) { newCelestialObject.PositionX = spaceship.PositionX + Math.Abs(500 + RandomGenerator.GetInteger(-20, 20)); newCelestialObject.PositionY = spaceship.PositionY + Math.Abs(500 + RandomGenerator.GetInteger(-20, 20)); newCelestialObject.Speed = newCelestialObject.MaxSpeed; newCelestialObject.Direction = GeometryTools.Azimuth(spaceship.GetLocation(), newCelestialObject.GetLocation()); } return(newCelestialObject); }
private void OnSketchFinished() { IFeature pFeat; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); pFeat.Store(); m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.Message); m_editor.AbortOperation(); } finally { pFeat = null; } }
private void FillControls(Spaceship targetSpaceship, ICelestialObject playerSpaceship) { txtCelestialObjectName.Text = targetSpaceship.Name; var shieldsMax = (int)targetSpaceship.ShieldsMax; var shieldCurrent = (int)targetSpaceship.Shields; crlShields.Maximum = shieldsMax; crlShields.CurrentValue = shieldCurrent; crlShields.Refresh(); if (txtDirection.Text != Math.Round(targetSpaceship.Direction, 2) + "") { txtDirection.Text = Math.Round(targetSpaceship.Direction, 2) + ""; } if (txtSpeed.Text != Math.Round(targetSpaceship.Speed, 2) + "") { txtSpeed.Text = Math.Round(targetSpaceship.Speed, 2) + ""; } if (txtDistance.Text != Math.Round(GeometryTools.Distance(targetSpaceship.GetLocation(), playerSpaceship.GetLocation()), 2) + "") { txtDistance.Text = Math.Round(GeometryTools.Distance(targetSpaceship.GetLocation(), playerSpaceship.GetLocation()), 2) + ""; } }
protected override void OnClick() { double jumpDistance = ConfigUtil.GetConfigValue("CreateJumps_Distance", 10.0); jumpDistance = jumpDistance * 2; //doubled so the height of the jump will be represented by this number GeometryTools.CreateJumps(ArcMap.Application, GeometryTools.JumpTypes.Over, jumpDistance); }
public static void DrawArrow(IScreenInfo screenInfo, ICelestialObject currentObject, Color color, int arrowSize = 4) { var screenCoordinates = UITools.ToScreenCoordinates(screenInfo, new PointF(currentObject.PositionX, currentObject.PositionY)); var endArrowPoint = GeometryTools.MoveObject(screenCoordinates, 12, currentObject.Direction); DrawArrow(screenInfo.GraphicSurface, new SpaceMapVector(screenCoordinates, endArrowPoint, currentObject.Direction), color, arrowSize); }
public void ToRelativeCoordinatesTest() { var _screenParameters = GetScreen(); var mouseScreenCoordinates = GeometryTools.ToRelativeCoordinates(new PointF(110, 120), _screenParameters.Center); Assert.AreEqual(new PointF(-850, -420), mouseScreenCoordinates); }
public void DrawArrow(IScreenInfo screenInfo, Color color, int arrowSize = 4) { var direction = int.Parse(txtSpacecraftDirection.Text); var endArrowPoint = GeometryTools.MoveObject(SpacecraftLocation, 12, direction); DrawArrow(screenInfo.GraphicSurface, new SpaceMapVector(SpacecraftLocation, endArrowPoint, direction), color, arrowSize); }
private void MapClick(object sender, MouseEventArgs e) { var mouseScreenCoordinates = GeometryTools.ToRelativeCoordinates(e.Location, _screenParameters.Center); var mouseMapCoordinates = GeometryTools.ToTacticalMapCoordinates(mouseScreenCoordinates, _screenParameters.CenterScreenOnMap); _environment.OuterSpaceTracker.Refresh(_environment.Session, mouseMapCoordinates, MouseArguments.LeftClick); }
protected override void OnMouseDown(MouseEventArgs arg) { ConfigUtil.type = "water"; ESRI.ArcGIS.Geometry.IPoint point = ArcMap.Document.CurrentLocation;//ArcMap.Document.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), point, true, false, true); }
protected override void OnClick() { ConfigUtil.type = "gas"; GeometryTools.AddRotate(ArcMap.Application, ConfigUtil.GetConfigValue("AddRotateSuspendAA", "true"), ConfigUtil.GetConfigValue("AdditionalRotate_SpinAngle", 0.0)); }
public static Line CalculateLineByAngle(PointF center, float direction, float length) { var result = new Line( GeometryTools.MoveObject(center, length, direction.To360Degrees()), GeometryTools.MoveObject(center, length, (direction - 180).To360Degrees()) ); return(result); }
public void LineLineTest() { //var result = GeometryTools.GetCrossLineToLinePoint(new PointF(0, 0), new PointF(100, 0), new PointF(50, 50), // new PointF(50, -50)); //Assert.Fail(); var x = GeometryTools.Azimuth(new PointF(0, 0), new PointF(-1, 0)); }
public void ToTacticalMapCoordinatesTest() { var _screenParameters = GetScreen(); var mouseScreenCoordinates = GeometryTools.ToRelativeCoordinates(new PointF(110, 120), _screenParameters.Center); var mouseMapCoordinates = GeometryTools.ToTacticalMapCoordinates(mouseScreenCoordinates, _screenParameters.CenterScreenOnMap); Assert.AreEqual(new PointF(9150, 9580), mouseMapCoordinates); }
public void GetAngleBetweenVectorsTest(int sx, int sy, int ex1, int ey1, int ex2, int ey2, float expectedAngle) { IntPoint startPoint = new IntPoint(sx, sy); IntPoint vector1end = new IntPoint(ex1, ey1); IntPoint vector2end = new IntPoint(ex2, ey2); float angle = GeometryTools.GetAngleBetweenVectors(startPoint, vector1end, vector2end); Assert.AreEqual(expectedAngle, angle, 0.00001f); }
public void GetAngleBetweenVectorsTest(int sx, int sy, int ex1, int ey1, int ex2, int ey2, double expectedAngle) { IntPoint startPoint = new IntPoint(sx, sy); IntPoint vector1end = new IntPoint(ex1, ey1); IntPoint vector2end = new IntPoint(ex2, ey2); double angle = GeometryTools.GetAngleBetweenVectors(startPoint, vector1end, vector2end); Assert.AreApproximatelyEqual <double, double>(expectedAngle, angle, 0.000001); }
/// <summary> /// 获取地图的最小外包矩形 /// </summary> /// <returns></returns> internal MyRectangle GetMBR() { MyRectangle mbr = mapLayers[0].SpaceData.GetMBR(); //无图层时会报错 for (int i = 1; i < LayerNum; i++) { mbr = GeometryTools.GetMBR(mbr, mapLayers[i].SpaceData.GetMBR()); } return(mbr); }
private void OnSketchFinished() { ConfigUtil.type = "water"; IFeature pFeat = null; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); bool splitOccured = GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); try { //Check to see if the source feature is the Junction FC, if so, and a edge was split, the junction will be created, do not create it as to not construct an orphaned junction //https://github.com/Esri/local-government-desktop-addins/issues/239 bool storeFeature = true; INetworkFeature netFeature = pFeat as INetworkFeature; if (netFeature != null) { if (pFeat.Class.ObjectClassID == netFeature.GeometricNetwork.OrphanJunctionFeatureClass.FeatureClassID && pFeat.Class.CLSID.Value.ToString() == netFeature.GeometricNetwork.OrphanJunctionFeatureClass.CLSID.Value.ToString() && splitOccured == true) { storeFeature = false; } } if (storeFeature == true) { pFeat.Store(); } netFeature = null; m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore")); m_editor.AbortOperation(); } } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.ToString()); m_editor.AbortOperation(); } finally { if (pFeat != null) { (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); } pFeat = null; } }
public void GetAngleBetweenLinesTest(int sx1, int sy1, int ex1, int ey1, int sx2, int sy2, int ex2, int ey2, float expectedAngle) { IntPoint line1start = new IntPoint(sx1, sy1); IntPoint line1end = new IntPoint(ex1, ey1); IntPoint line2start = new IntPoint(sx2, sy2); IntPoint line2end = new IntPoint(ex2, ey2); float angle = GeometryTools.GetAngleBetweenLines(line1start, line1end, line2start, line2end); Assert.AreEqual(expectedAngle, angle, 0.00001f); }
public void GetAngleBetweenLinesTest(int sx1, int sy1, int ex1, int ey1, int sx2, int sy2, int ex2, int ey2, double expectedAngle) { IntPoint line1start = new IntPoint(sx1, sy1); IntPoint line1end = new IntPoint(ex1, ey1); IntPoint line2start = new IntPoint(sx2, sy2); IntPoint line2end = new IntPoint(ex2, ey2); double angle = GeometryTools.GetAngleBetweenLines(line1start, line1end, line2start, line2end); Assert.AreApproximatelyEqual <double, double>(expectedAngle, angle, 0.000001); }
public void ValidateGeometry_WhenInvalidPolygon_ThenInvalidResult() { SqlGeometry polygon = SqlGeometry.Parse("POLYGON((1 1, 4 1, 1 4, 4 4, 1 1))"); GeometryTools geometryTools = new GeometryTools(); GeometryValidationResult result = geometryTools.ValidateGeometry(polygon); Assert.IsFalse(result.IsValid); Assert.AreEqual(24404, result.StatusCode); Assert.AreEqual(GeometryValidationStatusId.NotValidBecausePolygonRingIntersectsItself, result.GeometryValidationStatusId); Assert.AreEqual("Not valid because polygon ring (1) intersects itself or some other ring.", result.Description); }
private void LabelChunkLoadOrder(Chunk chunk, int loadOrder) { var _loadOrderStyle = new GUIStyle() { alignment = TextAnchor.MiddleCenter, fontSize = 25 }; var centerpoint = GeometryTools.CenterOfRectangle(chunk.TopRightCorner, chunk.BottomLeftCorner); Handles.Label(centerpoint, loadOrder.ToString(), _loadOrderStyle); }
private void LabelBuilderCreationOrder(ChunkBuilder builder, int creationOrder) { var _loadOrderStyle = new GUIStyle() { alignment = TextAnchor.MiddleCenter, fontSize = 25 }; var centerpoint = GeometryTools.CenterOfRectangle(builder.TopRightCorner, builder.BottomLeftCorner); Handles.Label(centerpoint, creationOrder.ToString(), _loadOrderStyle); }