intersect 相交 范围_目标c比较范围相交(objective c compare range intersect)

这篇博客讨论了如何在Objective C中找到两个数字范围的交集,特别是使用NSIntersectionRange函数来避免复杂的if语句。示例中展示了如何处理两个范围,如10到100和60到70的交集。
摘要由CSDN通过智能技术生成

目标c比较范围相交(objective c compare range intersect)

我试图找到2个数字范围的交集,比如说...

范围A为10至100,范围B为60至70

是否有一种简单的方法,无需编写if语句来计算两个范围的交点,因此在此示例中它将为10。

谢谢,

I am trying to find the intersection of 2 number ranges, say for example...

range A is from 10 to 100, range B is from 60 to 70

Is there an easy way without writing a load of if statements to calculate the intersection of the two ranges, so in this example it would be 10.

Thanks,

原文:https://stackoverflow.com/questions/10172688

更新时间:2019-10-28 17:26

最满意答案

如果你有或者做NSRange对象, NSIntersectionRange函数会为你做这件事。 只要确保在没有交集的情况下检查它返回的内容。

NSRange a = NSMakeRange(10, 90);

NSRange b = NSMakeRange(60, 10);

NSRange intersection = NSIntersectionRange(a, b);

if (intersection.length <= 0)

NSLog(@"Ranges do not intersect");

else

NSLog(@"Intersection = %@", NSStringFromRange(intersection));

If you have or make NSRange objects, the NSIntersectionRange function will do this for you. Just be sure to check what it returns when there is no intersection.

NSRange a = NSMakeRange(10, 90);

NSRange b = NSMakeRange(60, 10);

NSRange intersection = NSIntersectionRange(a, b);

if (intersection.length <= 0)

NSLog(@"Ranges do not intersect");

else

NSLog(@"Intersection = %@", NSStringFromRange(intersection));

2012-04-16

相关问答

如果你有或者做NSRange对象, NSIntersectionRange函数会为你做这件事。 只要确保在没有交集的情况下检查它返回的内容。 NSRange a = NSMakeRange(10, 90);

NSRange b = NSMakeRange(60, 10);

NSRange intersection = NSIntersectionRange(a, b);

if (intersection.length <= 0)

NSLog(@"Ranges do not intersec

...

这通常在SQL中完成 如果您希望整行在另一个表中至少有一个匹配的SKU: $sql = "

SELECT c.* FROM $i_comp AS c

JOIN $i_gas AS d

ON d.sku_one in (c.sku, c.sku_one, c.sku_two, c.sku_three)

OR d.sku_two in (c.sku, c.sku_one, c.sku_two, c.sku_three)

ORDER BY c.`manufacturer`"

...

喜欢这个? Sub Sample()

Dim Rng1 As Range, Rng2 As Range

Dim aCell As Range, FinalRange As Range

Set Rng1 = Range("A2:E2")

Set Rng2 = Range("B1:B5")

Set FinalRange = Rng1

For Each aCell In Rng2

If Intersect(aCell, Rng1) I

...

iPhone操作系统在Leopard之前不久就推出了,它从一开始就是Objective-C 2.0。 除了在iPhone上缺乏垃圾收集之外,关键的区别在于iPhone上的Objective-C运行时始终是Modern Runtime,而不是32位Mac应用程序的Legacy Runtime。 ( 请参阅此Apple文档 。)这种区别的一个重要结果是实例变量是非脆弱的(意味着当您更改类的实例变量时,您不必重新编译其子类)并且它可以合成属性的变量。 iPhone OS debuted shortly

...

我曾将这个问题发布到msdn论坛,缺乏SO反应,并获得了所需的解决方案。 我测试了代码,它工作正常。 我希望它有帮助。 这是msdn上发布的链接 。 Sub NotIntersect()

Dim rng As Range, rngVal As Range, rngDiff As Range

Set rng = Range("A1:A10")

Set rngVal = Range("A5")

Set rngDiff = Differen

...

我向cl.value道歉,我没有足够的声誉发表评论,但我认为你的问题是在范围内找不到cl.value 。 您可以添加一些错误处理,如下所示: Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range

Dim d As Integer`

'***Check if any ALL_Inst cells have been changed

If Not Intersect(Target, Range("All_Inst"))

...

intersects将MBR与另一个MBR进行比较,如果第一个MBR的low[]中的任何值大于第二个MBR的high[]的值(在各个索引中)或第一个MBR中的任何值,则返回FALSE high[]小于第二个MBR的low[]的值(在各个索引中)。 否则返回TRUE。 intersects compares a MBR to another MBR and returns FALSE if any of the values in the first MBR's low[] are greater

...

这是因为Intersect要求两个集合属于同一类型。 您正尝试使用集合或Student和IWebElement集合来调用它。 在调用Intersect之前确保您有两个相同类型的集合,或者使用不同的方法来完成您的任务。 您可以将两个集合都投射到可以轻松比较的内容中(例如IEnumerable ): var studentNames = Names.Select(student => student.Name);

var webElementNames = OrderedList.Se

...

当我尝试将静态节点(位于左侧)与具有旋转的节点(以及从右侧飞行)相交时,我遇到了同样的问题。 我这样解决了 if ([ninja intersectsNode:node] &&

CGRectGetMinX(node.frame) <= CGRectGetMaxX(ninja.frame) &&

CGRectGetMaxX(node.frame) >= CGRectGetMinX(ninja.frame))

{

//and here I have intersects

}

...

相交的日期: SELECT

E.name,

O.start_date,

O.end_date

FROM

dbo.Names E

INNER JOIN dbo.Dates O ON

O.name = E.name AND

O.start_date < @end_date AND

O.end_date > @start_date

WHERE

E.name LIKE 'A'

不相交的日期与日期相反: SELECT

E.name,

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值