首页 \ 问答 \ javascript逻辑返回奇怪的结果(javascript logic returning strange results)

javascript逻辑返回奇怪的结果(javascript logic returning strange results)

我有一个网格,我正在尝试将光标编程到,网格中有一个中心点,我试图让光标只能从该中心点移动x个方块,这里是我的代码

var makecursor = function (axis, operation) {
    oppositeAxis = axis === 'y' ? 'x' : 'y';

    // app.cursor contains the x and y coordinates of the cursor
    app.cursor[axis] = 

    // calcualte the difference between the current cursor location and the origin
    Math.abs( app.cursor[axis] - origin[axis] ) + 

   // calculate the difference between the opposite axis and
   // the origin and add it to the previous calculation
    Math.abs( app.cursor[oppositAxis] - origin[oppositeAxis] ) 

  // add the operation to be performed ( movement of cursor, 1 or -1 )
  + operation 

  // if the sum of the x, y and current operation are greater then the allowed
  // movement, then make "app.cursor[axis]" equal to itself (dont move) , 
  // otherwise make "app.cursor[axis]" equal to itself plus the operation ( move )

> origin.movement ? app.cursor[axis] : app.cursor[axis] + operation;
}

“操作”是1或-1,用于定向

“origin.movement”是您可以移动光标的原点的平方数。

我希望/期望的行为是从我的网格上的一个正方形,你只能移动“origin.movement”变量中指定的正方形。 但是当我打印出结果时,它返回了奇怪的数字,并且它没有正确计算位置,即原点应该为零,而是取而代之的是一个或两个,这取决于之前的运动,还有许多其他我没有的异常能够理解。 任何帮助这个问题将不胜感激,谢谢!


I have a grid that I am trying to program a cursor onto, there is a central point in the grid and I am trying to make the cursor only be able to move x amount of squares from that central point, here is the code I have

var makecursor = function (axis, operation) {
    oppositeAxis = axis === 'y' ? 'x' : 'y';

    // app.cursor contains the x and y coordinates of the cursor
    app.cursor[axis] = 

    // calcualte the difference between the current cursor location and the origin
    Math.abs( app.cursor[axis] - origin[axis] ) + 

   // calculate the difference between the opposite axis and
   // the origin and add it to the previous calculation
    Math.abs( app.cursor[oppositAxis] - origin[oppositeAxis] ) 

  // add the operation to be performed ( movement of cursor, 1 or -1 )
  + operation 

  // if the sum of the x, y and current operation are greater then the allowed
  // movement, then make "app.cursor[axis]" equal to itself (dont move) , 
  // otherwise make "app.cursor[axis]" equal to itself plus the operation ( move )

> origin.movement ? app.cursor[axis] : app.cursor[axis] + operation;
}

"operation" is either 1 or -1, for directional

"origin.movement" is the number of squares from the origin you can move the cursor.

my hopes / expected behavior is that from a square on my grid, you can only move as many squares are specified in "origin.movement" variable. but it is returning strange numbers when i print out the results, and it doesn't calculate the locations correctly, i.e. origin should be zero, but is instead one, or two, depending on previous movements, many other anomalies that I haven't been able to understand. any help with this problem would be appreciated, thanks!


原文:https://stackoverflow.com/questions/29861966
更新时间:2020-01-02 16:41

最满意答案

问题是我在我的例子中混合了Dynamo Data Model和Document Model。 使用数据模型时,您无需担心将集合转换为特定于Dynamo的类型(如DynamoDBListList<Document> 。 这些类型是Document模型的一部分,对于数据模型不是必需的。

解决方法是只更改我的TourDetail模型中的Itinerary属性,以键入List<TourItineraryDay>并删除该成员的显式List<TourItineraryDay>映射。

public class TourDetail
{
    [DynamoDBHashKey]
    public string TourId { get; set; }
    public List<TourItineraryDay> Itinerary { get; set; }
}

The issue was that I am mixing the Dynamo Data Model and the Document Model in my example. When using the Data Model, you do not need to worry about converting your collections to Dynamo-specific types like DynamoDBList or List<Document>. These types are part of the Document model and are not necessary with the Data Model.

The solution was to just change the Itinerary property in my TourDetail model to type List<TourItineraryDay> and removed the explicit Automapper mapping for that member.

public class TourDetail
{
    [DynamoDBHashKey]
    public string TourId { get; set; }
    public List<TourItineraryDay> Itinerary { get; set; }
}

相关问答

更多
  • 来自: https : //developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/SharingData.html 对于大多数类型的传输,您提供一个NSDictionary对象,其中包含您要发送的数据。 字典的键和值必须都是属性列表类型,因为数据必须序列化并以无线方式发送。 (如果需要包含非属性列表类型的类型,请将它们打包在NSData对象中,或者在发送之前将它们写入文件。) ...
  • 我通过在虚拟机的硬盘设置中将虚拟设备节点从SCSI控制器0更改为IDE控制器0来解决了该问题。 I solved the issue by changing the Virtual Device Node from SCSI controller 0 to IDE controller 0 at the hard disk settings of the virtual machine.
  • 请阅读Analytics.logEvent()的API文档。 对于parameters参数它说: 事件参数字典。 传递nil表示事件没有参数。 参数名称最长可达40个字符,并且必须以字母字符开头,并且只包含字母数字字符和下划线。 仅支持NSString和NSNumber(带符号的64位整数和64位浮点数)参数类型。 NSString参数值最长可达100个字符。 “firebase_”,“google_”和“ga_”前缀是保留的,不应用于参数名称。 你的论点不符合规定的要求。 看起来你正在传递一个包含字符串和 ...
  • 选择使用哪个密钥取决于特定方案的用例和数据要求。 例如,如果要存储用户会话数据,则使用范围键可能没有多大意义,因为每个记录都可以由GUID引用并直接访问而无需分组要求。 一般而言,一旦您知道会话ID,您只需通过密钥查询特定项目。 另一个示例可能是存储用户帐户或个人资料数据,每个用户都有自己的用户,您很可能会直接访问它(通过用户ID或其他内容)。 但是,如果您要存储订单商品,那么范围键更有意义,因为您可能想要检索按订单分组的商品。 就数据模型而言 , 哈希键允许您从表中唯一标识记录,并且可以选择使用范围键对通 ...
  • @ jtlebi正确回答说服务不接受空字符串或空集。 .NET SDK建立在这个基础之上,如果你试图保存一个空的PrimitiveList,SDK将忽略这个,并且属性不会改变。 但是,仍然有一种方法可以删除属性:将.NET对象上的字段设置为null或从IPropertyConverter.ToEntry方法返回null。 然后,当您调用DynamoDBContext.Save时,SDK将为该特定属性发出DELETE命令。 @jtlebi answered correctly that the service ...
  • 问题是我在我的例子中混合了Dynamo Data Model和Document Model。 使用数据模型时,您无需担心将集合转换为特定于Dynamo的类型(如DynamoDBList或List 。 这些类型是Document模型的一部分,对于数据模型不是必需的。 解决方法是只更改我的TourDetail模型中的Itinerary属性,以键入List并删除该成员的显式List映射。 public class Tour ...
  • 首先,您需要区分这两种类型的错误: 400 Bad Request - 与以下内容不同: 415不支持的媒体类型 当发送具有不支持的媒体类型的请求时,应该返回415。 由于没有标题指示端点接受哪些媒体类型并且需要精确信息,因此可以在响应的正文中返回详细消息。 简而言之, 支持使用消息XML和JSON返回415。 在大多数框架中,可以捕获并包装返回的错误。 请记住,只能始终以相同的格式返回错误消息,以便消费者可以轻松地解析它。 当以有效格式(JSON)发送请求但是例如将单个字段作为字符串的实例发送并且需要是整 ...
  • 它看起来像IntegerRangeField是特定于PostgreSQL的表单字段( IntegerRangeField )。 让我们知道您是否使用PostgreSQL。 It looks like IntegerRangeField is PostgreSQL specific form field (IntegerRangeField). Let us know if You're using PostgreSQL.
  • 没有@QueryParam 。 尝试将@QueryParam注释添加到sensor -argument(请参阅DefaultValue javadoc ) @DefaultValue does not work without @QueryParam. Try adding the @QueryParam annotation to the sensor-argument (see DefaultValue javadoc)
  • 最后我找到了解决方案: 替换: post.setEntity(new StringEntity(obj.toString(), "UTF-8")); 附: post.setEntity(new StringEntity("grant_type=password&username=0000@gmail.com&password=00000", "UTF-8")); finally I have found the solution : replace : post. ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)