How to buffer an IPoint or IGeometry? (How to do buffered intersection checks on an IPoint?) - arcobjects

How would I buffer an IPoint to do an intersection check using IRelationalOperator?
I have, for arguments sake:
IPoint p1 = xxx;
IPoint p2 = yyy;
IRelationalOperator rel1 = (IRelationalOperator)p1;
if (rel.Intersects (p2))
// Do something
But now I want to add a tolerance to my check, so I assume the right way to do that is by either buffering p1 or p2. Right?
How do I add such a buffer?
Note: the Intersects method I am using is an extension method I wrote to simplify my code. Here it is:
/// <summary>
/// Returns true if the IGeometry is intersected.
/// This method negates the Disjoint method.
/// </summary>
/// <param name="relOp">The rel op.</param>
/// <param name="other">The other.</param>
/// <returns></returns>
public static bool Intersects (
this IRelationalOperator relOp,
IGeometry other)
{
return (!relOp.Disjoint (other));
}

OK, I found the answer. Or an answer.
Use the ITopologicalOperator interface.
IPoint p1 = xxx;
IPoint p2 = yyy;
ITopologicalOperator topoOp = (ITopologicalOperator)p2 ;
IGeometry p2Bufferd = topoOp.Buffer (bufferSize);
IRelationalOperator rel1 = (IRelationalOperator)p1;
if (rel.Intersects (p2Bufferd))
// Do something

Related

How to put Doc comments for Dart function parameters?

We can easily put Doc comments for Dart Class variables e.g.
class SomeClass {
/// Class variable Doc Comment.
var someVariable;
}
How can I do the same for Dart Function parameters e.g. I tried this
void someFunction(
{/// Function parameter documentation
String funParameter="Some Default Value"}
) {
}
But it's not showing anything. If it's not possible please suggest me any alternative.
It is against the Effective Dart conventions to document parameters of functions using a direct syntax like that. Instead, use prose to describe the parameter and how it relates to the function's purpose.
// Instead of this
/// someFunction
/// #funParameter Does something fun
void someFunction({ String funParameter="Some Default Value" }) ...
// Or this
/// someFunction
void someFunction({
/// Does something fun
String funParameter="Some Default Value"
}) ...
// Do this
/// Does something fun with the [funParameter].
void someFunction({ String funParameter="Some Default Value" }) ...
Here's perhaps a more practical example:
/// Takes the values [a] and [b] and returns their sum. Optionally a
/// third parameter [c] can be provided and it will be added to the
/// sum as well.
int add(int a, int b, [int c = 0]) ...
You should use the doc comment like this:
/// the function uses [funParameter] to do stuff
void someFunction({String funParameter = "Some Default Value"}) {
// ..
}

Distinguishing between local data member and child-class data member in an inline constraint

I have a class with a rand data member i. This class (child) is a member of class parent, which also has a data member i. I would like to constrain the value of i in the child class to be the same as the value of i in the parent class. I want to do something like:
c.randomize with {i==this.i;};
but the this.i doesn't seem to refer to the i data member of the parent class. (Why?)
I can do this:
function void f;
int dummy = i;
c.randomize with {i==dummy;};
endfunction
or this:
function void f;
c.randomize with {i==m.blk.p.i;}; // yuck!
endfunction
but wonder if there is a better (built-in, non-hacky) way of distinguishing between the two is.
MCVE:
class child;
rand int i;
endclass
class parent;
child c = new;
int i=1;
function void f;
c.randomize with {i==this.i;};
endfunction
endclass
module m;
initial begin : blk
parent p = new;
p.f;
$display("%p", p);
end
endmodule
https://www.edaplayground.com/x/2_8P
You want {i==local::i}. See section 18.7.1 of the 1800-2017 LRM
The reason this.i does not do what you expect is the combination of these two rules:
all class methods, including the built-in randomize method, have a built-in this argument. So c.method(args) is really method(args, c) and this becomes a variable local to the method set to the value of c
Identifiers within the with clause try to bind into the scope being randomized first before searching locally at the point where calling randomize().
So i and this.i refer to the same class variable just as if you wrote
class A;
bit i;
function void method;
i = 1;
this.i = 2;
endfunction
endclass

What is the time complexity of Array.enumerated() in swift?

I used enumerated() quite often in my code like:
for (index, element) in array.enumerated() {
// ...
}
If enumerated() takes O(n) time then the above execution will take O(2n).
I am confused here since Apple's documentation doesn't provide any info of time complexity.
Will this cause O(2n) or just O(n)?
Swift is open source now and you can get this info from public sources.
From the GitHub.
Method description.
/// Returns a sequence of pairs (*n*, *x*), where *n* represents a
/// consecutive integer starting at zero and *x* represents an element of
/// the sequence.
///
/// This example enumerates the characters of the string "Swift" and prints
/// each character along with its place in the string.
///
/// for (n, c) in "Swift".enumerated() {
/// print("\(n): '\(c)'")
/// }
/// // Prints "0: 'S'"
/// // Prints "1: 'w'"
/// // Prints "2: 'i'"
/// // Prints "3: 'f'"
/// // Prints "4: 't'"
///
/// When you enumerate a collection, the integer part of each pair is a counter
/// for the enumeration, but is not necessarily the index of the paired value.
/// These counters can be used as indices only in instances of zero-based,
/// integer-indexed collections, such as `Array` and `ContiguousArray`. For
/// other collections the counters may be out of range or of the wrong type
/// to use as an index. To iterate over the elements of a collection with its
/// indices, use the `zip(_:_:)` function.
///
/// This example iterates over the indices and elements of a set, building a
/// list consisting of indices of names with five or fewer letters.
///
/// let names: Set = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"]
/// var shorterIndices: [SetIndex<String>] = []
/// for (i, name) in zip(names.indices, names) {
/// if name.count <= 5 {
/// shorterIndices.append(i)
/// }
/// }
///
/// Now that the `shorterIndices` array holds the indices of the shorter
/// names in the `names` set, you can use those indices to access elements in
/// the set.
///
/// for i in shorterIndices {
/// print(names[i])
/// }
/// // Prints "Sofia"
/// // Prints "Mateo"
///
/// - Returns: A sequence of pairs enumerating the sequence.
To be short its O(1).
It's very well documented. You can get that info even in Xcode directly.

How do I write this function of this class?

I'm a beginner in C++ so I'm not sure how to make the question more detail. I'm sorry.
So my professor gave me this header file and told me to write the function definition:
class Move
{ private:
double x;
double y;
public:
Move( double a = 0, double b = 0 ); // sets x_, y_ to a, b
void showmove(Move number) const; // shows current x_, y_ values
// add : Move --> Move
// to add x_ of input object to x_ of invoking object to get new x_,
// to add y_ of input object to y_ of invoking object to get new y_,
// to create new object initialized to new values and return it
Move add( const Move &m ) const;
void reset( double a = 0, double b = 0 ); // resets x, y to a, b
};
I don't understand the function Move add( const Move &m ) const;. Usually an add function look like this int add( int a, int b) . So combine 2 inputs together to make 1 output. But the function Move add only has one input. I don't know how to write a definition for it. I asked my friends and we come up with something like A.add(B), but I'm not sure if it makes any sense.
Thank you for reading and sorry for my English
The definition should be
Move add(const Move& m) {
return Move(this->x+m.x, this->y+m.y);
}
It wants you to use m's attributes to get the results directly with only one parameter (reference to a Move object) instead of two (coordinates) .
Indeed, to invoke this method :
Move A/*sthg*/;
Move B/*sthg*/;
Move C = A.add(B);

Nested Matlab Property listener

The property postSet of MATLAB handle classes are very handy, however I would be happy to be able to trigger nested classes separately. A minimal example with two nested classes for illustration:
classdef parentClass < handle
properties (SetObservable = true)
childClass
end
methods
function this = parentClass()
this.childClass = childClass();
end
end
end
and
classdef childClass < handle
properties (SetObservable = true)
value
end
methods
function this = childClass()
this.value = 0;
end
end
end
In the example script "runTest"
p = parentClass();
addlistener(p.childClass,'value','PostSet',#(o,e)disp('child value set'));
addlistener(p,'childClass','PostSet',#(o,e)disp('parent value set'));
p.childClass.value = 1;
The result is (as expected)
>> runTest
child value set
However, I am looking for an elegant way to detect the property change on both levels such that the result would be:
>> runTest
child value set
parent value set
One way to do this is to use the fact that the PostSet event gets triggered by default even when the previous and current values are the same. In the constructor of parentClass, we add a listener to the childClass's PostSet event, and the event handler only reassigns the childClass object:
classdef parentClass < handle
properties (SetObservable = true)
childClass
end
methods
function this = parentClass()
this.childClass = childClass();
addlistener(this.childClass,'value','PostSet', #this.handlePropEvent);
end
function handlePropEvent(this, src, event)
this.childClass = this.childClass;
end
end
end
Note that you would want to be more careful implementing this so that the event listener gets adequately disposed of (and reassigned) if the childClass property is assigned a different object.
In practice, childClass should probably implement its own event type which gets triggered by all property changes you're interested in, and parentClass only listens to that event.