找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1364|回复: 0

[原创] 练习 LispFuntion选集的交并差

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2014-7-19 10:54:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
并集

  1.         /// <summary>
  2.         /// 选择集并集
  3.         /// </summary>
  4.         /// <param name="rb">(选集1 选集2)</param>
  5.         /// <returns>选集</returns>
  6.         [LispFunction("SSUnion")]
  7.         public static object SSetUnion (ResultBuffer rb)
  8.         {
  9.             TypedValue[] values = rb.AsArray();
  10.             if (values.Length == 2 && values[0].TypeCode == (int) LispDataType.SelectionSet &&
  11.                 values[1].TypeCode == (int) LispDataType.SelectionSet)
  12.             {
  13.                 SelectionSet ss1 = (SelectionSet) values[0].Value;
  14.                 SelectionSet ss2 = (SelectionSet) values[1].Value;
  15.                 ObjectId[] ids1 = ss1.GetObjectIds();
  16.                 ObjectId[] ids2 = ss2.GetObjectIds();
  17.                 ObjectId[] ids = new ObjectId[ids1.Length + ids2.Length];
  18.                 ids1.CopyTo(ids, 0);
  19.                 ids2.CopyTo(ids, ids1.Length);
  20.                 SelectionSet ss = SelectionSet.FromObjectIds(ids );
  21.                 return ss;
  22.             }
  23.             return null;
  24.         }

交集

  1.         /// <summary>
  2.         /// 选择集交集
  3.         /// </summary>
  4.         /// <param name="rb">(选集1 选集2)</param>
  5.         /// <returns>选集 or nil</returns>
  6.         [LispFunction("SSIntersect")]
  7.         public static object SSetInters(ResultBuffer rb)
  8.         {
  9.             TypedValue[] values = rb.AsArray();
  10.             if (values.Length == 2 && values[0].TypeCode == (int) LispDataType.SelectionSet &&
  11.                 values[1].TypeCode == (int) LispDataType.SelectionSet)
  12.             {
  13.                 SelectionSet ss1 = (SelectionSet) values[0].Value;
  14.                 SelectionSet ss2 = (SelectionSet) values[1].Value;
  15.                 List<ObjectId> lst1 = ss1.GetObjectIds().ToList();
  16.                 List<ObjectId> lst2 = ss2.GetObjectIds().ToList();
  17.                 if (lst1.Count < lst2.Count )
  18.                 {
  19.                      var query = from id in lst1
  20.                         where lst2.Contains(id)
  21.                         select id;
  22.                      if (query.Count( ) > 0)
  23.                      {
  24.                          ObjectId[] ids = new ObjectId[query.Count()];
  25.                          int i = 0;
  26.                          foreach (ObjectId id in query )
  27.                          {
  28.                              ids[i] = id;
  29.                              i++;
  30.                          }
  31.                          return SelectionSet.FromObjectIds(ids  );
  32.                      }
  33.                      else
  34.                      {
  35.                          return null;
  36.                      }
  37.                 }
  38.                 else
  39.                 {
  40.                      var  query = from id in lst2
  41.                         where lst1.Contains(id)
  42.                         select id;
  43.                      if (query.Count() > 0)
  44.                      {
  45.                          ObjectId[] ids = new ObjectId[query.Count()];
  46.                          int i = 0;
  47.                          foreach (ObjectId id in query)
  48.                          {
  49.                              ids[i] = id;
  50.                              i++;
  51.                          }
  52.                          return SelectionSet.FromObjectIds(ids);
  53.                      }
  54.                      else
  55.                      {
  56.                          return null;
  57.                      }
  58.                 }
  59.                
  60.             }
  61.             return null;
  62.         }

差集

  1.         [LispFunction("SSSubtrcat")]
  2.         public static object SSetSubtrcat(ResultBuffer rb)
  3.         {
  4.             TypedValue[] values = rb.AsArray();
  5.             if (values.Length ==  2 && values[0].TypeCode == (int)LispDataType .SelectionSet &&
  6.                 values[1].TypeCode == (int)LispDataType .SelectionSet )
  7.             {
  8.                 SelectionSet ss1 = (SelectionSet) values[0].Value;
  9.                 SelectionSet ss2 = (SelectionSet) values[1].Value;
  10.                 List<ObjectId> lst1 = ss1.GetObjectIds().ToList();
  11.                 List<ObjectId> lst2 = ss2.GetObjectIds().ToList();
  12.                 var query = from id in lst1
  13.                     where !lst2.Contains(id)
  14.                     select id;
  15.                 if (query.Count() > 0)
  16.                 {
  17.                     ObjectId[] ids = new ObjectId[query.Count()];
  18.                     int i = 0;
  19.                     foreach (ObjectId objectId in query)
  20.                     {
  21.                         ids[i] = objectId;
  22.                         i++;
  23.                     }
  24.                     return SelectionSet.FromObjectIds(ids);
  25.                 }
  26.                 else
  27.                 {
  28.                     return null;
  29.                 }
  30.             }
  31.             return null;
  32.         }

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-1 08:51 , Processed in 0.235747 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表