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
最满意答案
问题是我在我的例子中混合了Dynamo Data Model和Document Model。 使用数据模型时,您无需担心将集合转换为特定于Dynamo的类型(如
DynamoDBList
或List<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
orList<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 myTourDetail
model to typeList<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.
-
Firebase Analytics错误无法创建值不受支持的值类型(Firebase Analytics Error Cannot create Value type with unsupported value)[2021-10-26]
请阅读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.
-
Jersey的新功能 - 在资源中获取不受支持的媒体类型(New to Jersey — Getting Unsupported Media Type at Resource)[2024-01-26]
没有@QueryParam 。 尝试将@QueryParam注释添加到sensor -argument(请参阅DefaultValue javadoc ) @DefaultValue does not work without @QueryParam. Try adding the @QueryParam annotation to the sensor-argument (see DefaultValue javadoc) -
使用API的不受支持的授权类型(Unsupported grant type with API)[2022-07-11]
最后我找到了解决方案: 替换: 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. ...