马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
并集
- /// <summary>
- /// 选择集并集
- /// </summary>
- /// <param name="rb">(选集1 选集2)</param>
- /// <returns>选集</returns>
- [LispFunction("SSUnion")]
- public static object SSetUnion (ResultBuffer rb)
- {
- TypedValue[] values = rb.AsArray();
- if (values.Length == 2 && values[0].TypeCode == (int) LispDataType.SelectionSet &&
- values[1].TypeCode == (int) LispDataType.SelectionSet)
- {
- SelectionSet ss1 = (SelectionSet) values[0].Value;
- SelectionSet ss2 = (SelectionSet) values[1].Value;
- ObjectId[] ids1 = ss1.GetObjectIds();
- ObjectId[] ids2 = ss2.GetObjectIds();
- ObjectId[] ids = new ObjectId[ids1.Length + ids2.Length];
- ids1.CopyTo(ids, 0);
- ids2.CopyTo(ids, ids1.Length);
- SelectionSet ss = SelectionSet.FromObjectIds(ids );
- return ss;
- }
- return null;
- }
交集
- /// <summary>
- /// 选择集交集
- /// </summary>
- /// <param name="rb">(选集1 选集2)</param>
- /// <returns>选集 or nil</returns>
- [LispFunction("SSIntersect")]
- public static object SSetInters(ResultBuffer rb)
- {
- TypedValue[] values = rb.AsArray();
- if (values.Length == 2 && values[0].TypeCode == (int) LispDataType.SelectionSet &&
- values[1].TypeCode == (int) LispDataType.SelectionSet)
- {
- SelectionSet ss1 = (SelectionSet) values[0].Value;
- SelectionSet ss2 = (SelectionSet) values[1].Value;
- List<ObjectId> lst1 = ss1.GetObjectIds().ToList();
- List<ObjectId> lst2 = ss2.GetObjectIds().ToList();
- if (lst1.Count < lst2.Count )
- {
- var query = from id in lst1
- where lst2.Contains(id)
- select id;
- if (query.Count( ) > 0)
- {
- ObjectId[] ids = new ObjectId[query.Count()];
- int i = 0;
- foreach (ObjectId id in query )
- {
- ids[i] = id;
- i++;
- }
- return SelectionSet.FromObjectIds(ids );
- }
- else
- {
- return null;
- }
- }
- else
- {
- var query = from id in lst2
- where lst1.Contains(id)
- select id;
- if (query.Count() > 0)
- {
- ObjectId[] ids = new ObjectId[query.Count()];
- int i = 0;
- foreach (ObjectId id in query)
- {
- ids[i] = id;
- i++;
- }
- return SelectionSet.FromObjectIds(ids);
- }
- else
- {
- return null;
- }
- }
-
- }
- return null;
- }
差集
- [LispFunction("SSSubtrcat")]
- public static object SSetSubtrcat(ResultBuffer rb)
- {
- TypedValue[] values = rb.AsArray();
- if (values.Length == 2 && values[0].TypeCode == (int)LispDataType .SelectionSet &&
- values[1].TypeCode == (int)LispDataType .SelectionSet )
- {
- SelectionSet ss1 = (SelectionSet) values[0].Value;
- SelectionSet ss2 = (SelectionSet) values[1].Value;
- List<ObjectId> lst1 = ss1.GetObjectIds().ToList();
- List<ObjectId> lst2 = ss2.GetObjectIds().ToList();
- var query = from id in lst1
- where !lst2.Contains(id)
- select id;
- if (query.Count() > 0)
- {
- ObjectId[] ids = new ObjectId[query.Count()];
- int i = 0;
- foreach (ObjectId objectId in query)
- {
- ids[i] = objectId;
- i++;
- }
- return SelectionSet.FromObjectIds(ids);
- }
- else
- {
- return null;
- }
- }
- return null;
- }
|