/// <summary> /// 적의 시야 범위를 바닥에 표시합니다. /// 이 표시는 점점 투명해지다가 사라집니다. /// </summary> /// <param name="enemyPos"></param> /// <returns></returns> IEnumerator SightDistanceAnimation(Vector3 enemyPos) { if (myDistanceSprite != null) { myDistanceSprite.GetComponent <DistanceSprite>().Disappear(); myDistanceSprite = null; } Vector3 v = new Vector3(enemyPos.x, enemyPos.y, -0.25f); myDistanceSprite = Instantiate(distanceSprite, v, Quaternion.identity); if (distanceType != DistanceType.None) { myDistanceSprite.GetComponent <SpriteRenderer>().sprite = Resources.Load(distanceType.ToString() + sightDistance, typeof(Sprite)) as Sprite; } float frame = 40f; for (int i = 0; i < frame; i++) { if (myDistanceSprite == null) { break; } myDistanceSprite.GetComponent <SpriteRenderer>().color = Color.Lerp(Color.yellow, ColorManager.ChangeAlpha(Color.yellow, 0f), i / frame); yield return(null); } myDistanceSprite.GetComponent <DistanceSprite>().Disappear(0); myDistanceSprite = null; StartCoroutine(LeaveDistanceAnimation()); }
/// <summary> /// Renders javascript to set distance type and unit. /// </summary> /// <remarks>The distance type and unit are then added to the URL to be used on the server.</remarks> /// <param name="writer">HtmlTextWriter</param> protected override void RenderJS(HtmlTextWriter writer) { // Since this is runtime behavior do it only if there is context. RenderJS(writer, ClientCommand, "ImgTool"); writer.AddAttribute("language", "javascript"); writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript"); writer.RenderBeginTag(HtmlTextWriterTag.Script); writer.WriteLine(string.Format("{0}Cmd.distanceType = '{1}';", UniqueID, DistanceType.ToString())); writer.WriteLine(string.Format("{0}Cmd.distanceUnit = '{1}';", UniqueID, DistanceUnit.ToString())); writer.RenderEndTag(); }
public void WriteJson(ElasticsearchCrudJsonWriter elasticsearchCrudJsonWriter) { elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("geo_distance"); elasticsearchCrudJsonWriter.JsonWriter.WriteStartObject(); elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName(_field); _location.WriteJson(elasticsearchCrudJsonWriter); JsonHelper.WriteValue("distance", _distance.GetDistanceUnit(), elasticsearchCrudJsonWriter); JsonHelper.WriteValue("distance_type", _distanceType.ToString(), elasticsearchCrudJsonWriter, _distanceTypeSet); JsonHelper.WriteValue("optimize_bbox", _optimizeBbox.ToString(), elasticsearchCrudJsonWriter, _optimizeBboxSet); elasticsearchCrudJsonWriter.JsonWriter.WriteEndObject(); }
public static DirectionsResponse Directions(double[] origin, double[] destination, DistanceType type, DistanceUnit unit, bool sensor) { string url = APIUrl + "directions/json"; string[] parameters = { "origin", "destination", "mode", "units", "sensor" }; string[] values = { origin[0].ToString() + "," + origin[1].ToString() , destination[0].ToString() + "," + destination[1].ToString(), type.ToString(), unit.ToString(), ((sensor) ? "true" : "false") }; ArrayList headers = new ArrayList(); string response = Utils.Request.ReadResponse(Utils.Request.Get(url, Encoding.UTF8, parameters, values, headers), Encoding.UTF8); DirectionsResponse dr = jss.Deserialize<DirectionsResponse>(response); return dr; }
public static double FindDistance(IList <double> firstPointCoordinates, IList <double> secondPointCoordinates, DistanceType distanceToCalculate) { if (firstPointCoordinates == null) { throw new ArgumentNullException("firstPointCoordinates"); } if (secondPointCoordinates == null) { throw new ArgumentNullException("secondPointCoordinates"); } if (firstPointCoordinates.Count() != secondPointCoordinates.Count()) { throw new ArgumentException("Coordinate collections of both points should be the same size"); } if (firstPointCoordinates.Contains(double.NaN) || firstPointCoordinates.Contains(double.NegativeInfinity) || firstPointCoordinates.Contains(double.PositiveInfinity)) { throw new ArgumentOutOfRangeException("firstPointCoordinates", "Coordinates must be represented by valid floating point numbers"); } if (secondPointCoordinates.Contains(double.NaN) || secondPointCoordinates.Contains(double.NegativeInfinity) || secondPointCoordinates.Contains(double.PositiveInfinity)) { throw new ArgumentOutOfRangeException("secondPointCoordinates", "Coordinates must be represented by valid floating point numbers"); } switch (distanceToCalculate) { case DistanceType.Euclidean: return(FindEuclideanDistance(firstPointCoordinates, secondPointCoordinates)); case DistanceType.Manhattan: return(FindManhattanDistance(firstPointCoordinates, secondPointCoordinates)); default: throw new InvalidDataException(distanceToCalculate.ToString() + " is not supported"); } }
public static DirectionsResponse Directions(double[] origin, double[] destination, DistanceType type, DistanceUnit unit, bool sensor) { string url = APIUrl + "directions/json"; string[] parameters = { "origin", "destination", "mode", "units", "sensor" }; string[] values = { origin[0].ToString() + "," + origin[1].ToString(), destination[0].ToString() + "," + destination[1].ToString(), type.ToString(), unit.ToString(), ((sensor) ? "true" : "false") }; ArrayList headers = new ArrayList(); string response = Utils.Request.ReadResponse(Utils.Request.Get(url, Encoding.UTF8, parameters, values, headers), Encoding.UTF8); DirectionsResponse dr = jss.Deserialize <DirectionsResponse>(response); return(dr); }
private void WriteValues(ElasticsearchCrudJsonWriter elasticsearchCrudJsonWriter) { JsonHelper.WriteValue("field", _field, elasticsearchCrudJsonWriter); elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("origin"); _origin.WriteJson(elasticsearchCrudJsonWriter); JsonHelper.WriteValue("unit", _unit.ToString(), elasticsearchCrudJsonWriter, _unitSet); JsonHelper.WriteValue("distance_type", _distanceType.ToString(), elasticsearchCrudJsonWriter, _distanceTypeSet); JsonHelper.WriteValue("keyed", _keyed, elasticsearchCrudJsonWriter, _keyedSet); elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("ranges"); elasticsearchCrudJsonWriter.JsonWriter.WriteStartArray(); foreach (var rangeAggregationParameter in _ranges) { rangeAggregationParameter.WriteJson(elasticsearchCrudJsonWriter); } elasticsearchCrudJsonWriter.JsonWriter.WriteEndArray(); if (_scriptSet) { elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("script"); elasticsearchCrudJsonWriter.JsonWriter.WriteRawValue("\"" + _script + "\""); if (_paramsSet) { elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName("params"); elasticsearchCrudJsonWriter.JsonWriter.WriteStartObject(); foreach (var item in _params) { elasticsearchCrudJsonWriter.JsonWriter.WritePropertyName(item.ParameterName); elasticsearchCrudJsonWriter.JsonWriter.WriteValue(item.ParameterValue); } elasticsearchCrudJsonWriter.JsonWriter.WriteEndObject(); } } }
/// <summary> /// How to compute the distance. /// Can either be arc (better precision) or plane (faster). Defaults to arc. /// </summary> public GeoDistanceFilter <T> DistanceType(DistanceType distanceType) { RegisterJsonPart("'distance_type': {0}", distanceType.ToString().Quotate()); return(this); }
/// <summary> /// Create a OclBruteForce Matcher using the specific distance type /// </summary> /// <param name="distanceType">The distance type</param> public OclBruteForceMatcher(DistanceType distanceType) { if (distanceType == DistanceType.Hamming) { if (typeof(T) != typeof(byte)) { throw new ArgumentException("Hamming distance type requires model descriptor to be Matrix<Byte>"); } } if (typeof(T) != typeof(byte) && typeof(T) != typeof(float)) { throw new NotImplementedException(String.Format("Data type of {0} is not supported", typeof(T).ToString())); } switch (distanceType) { case (DistanceType.Hamming): _distanceType = OclMatcherDistanceType.HammingDist; break; case (DistanceType.L1): _distanceType = OclMatcherDistanceType.L1Dist; break; case (DistanceType.L2): _distanceType = OclMatcherDistanceType.L2Dist; break; default: throw new NotImplementedException(String.Format("Distance type of {0} is not implemented in GPU.", distanceType.ToString())); } _ptr = OclInvoke.oclBruteForceMatcherCreate(_distanceType); }