proper syntax for stylus mixin using transform translate() or other 2 part rules - mixins

In stylus, when trying to make mixins with transform translate() - or any other multipart rules...
I get: "Maximum stylus call stack size exceeded at "
scale(n)
transform scale(n)
scale()
transform scale(arguments)
(tried a bunch of stuff...)
Here is an example CodePen

Yep, if you're trying to produce the value with the same function as the one you're calling, you should output it literally, like this:
scale(n)
transform 'scale(%s)' % n
This way it would output the ident entity and won't call the scale function, so there won't be any infinite loops.

This is what I found. I had made mixins for each, but I forgot that they override each other. So, this seems like the best option for me.
transform(value)
transform: value
.thing
background red
width 3rem
height 3rem
transform( translate(20%,20%) scale(1.2) rotate(98deg) )

if you define your mixin func name with a builtin css method, you may get this error. for example:
rotate($angular) // mixin func name
transform rotate($angular) // rotate is a builtin css method, but stylus treats this "rotate" as a mixin usage, which makes a dead loop.

Related

MATLAB set class `size` (overload operation upon class)

classdef Dog
end
d=Dog(); can size(d) be controlled? Is there some property to set or method to overload?
Ultimately I have like d.data = [1, 2, 3] and want length(d) == 3. I'm aware I can make d.length(). As an aside, is there a list of MATLAB "magic methods", i.e. functions that control interaction with classes, like subsref?
In MATLAB, don't think of class method as similar to class methods in other languages. Really, what they are is overloaded versions of a function.
size(d) is the same as d.size() (which is the same as d.size, parentheses are not needed to call a function), if d is an object of a custom class and size is overloaded for that class.
So, you can define function size in the methods section of your classdef, to overload size for your class. You can also create a size.m file within a #Dog/ directory to accomplish the same thing.
For example, if you create a file #char/size.m with a function definition inside, you will have overloaded size for char arrays.
The above is true for any function. Some functions, when overloaded, can cause headaches. For example be careful when overloading numel, as it could cause indexed assignment expressions to fail. size is used by the whos command to display variable information, as well as by the similar functionality in the GUI, so it is important to have it behave in the expected way.
The object behavior that you might want to change that is not obviously a function, relates to operators. Each operator is also defined by a function (including end in indexing!). See the docs for a full list.

Trying Make Own Shape By Manim

I try to make convex lense. But not using SVGimages or other things. I want to define it in a class But ı'll get a black screen image. What should ı do? Ok, ı can fix it like following: a=ArcBetweenPoints(ORIGIN, UP, self.rad) and b=ArcBetweenPoints(UP, ORIGIN, self.rad) then add self.add(a,b). Ok, there is no problem. But why the self.add() wasn't used in Circle(Arc) class that was defined in manim packages. How can it work?
Here is the code:
class YaşamÇiçeği(Mobject):
CONFIG = {
"rad" : TAU / 6,
}
def __init__(self, **kwargs):
Mobject.__init__(self)
ArcBetweenPoints(ORIGIN, UP, self.rad)
ArcBetweenPoints(UP, ORIGIN, self.rad)
All geometric figures are VMobjects, that is, Bezier curves. These VMobjects have a special method called generate_points, in the case of Arc is this.
The Circle class is a subclass of Arc (a particular case where Arc=360º), so you don't need to use the "add" method, both VMobjects and VGroups can also be containers, but the advantage of VMobjects is that you can explicitly define the shape of the paths. I recommend that you watch this video that I have already done so you can give yourself a better idea.
Recommendations: Do not use non-English symbols, it can bring you problems in the compilation. Also give a correct format to your code, learn the basics of Markdown in 5 minutes here.

Custom equality for intersection

I'm trying to find the intersection and union between two sequences that have related classes. In order to achieve this I would like to be able to provide a custom equality check to the intersect function. I do not want to override the equals and hashcode function. I would like an intersect function that also takes a function to check for equality.
Is there any clean way to achieve this without writing a custom intersection and union function?
What you're asking is probably not supported by the standard library. It is fairly easy to write your custom intersection/union methods. One other possibility is to wrap your instances like so:
class Wrapper[E](val wrapped: E) {
// Override equals/hashCode here
}
You then compute the union/intersection of Wrapper[E] and then use unionOfWrappers.map(_.wrapped) to get what you wanted. Of course, this will cause many Wrapper instances to be created and garbage collected.

Scala Method Argument: Option of Collection or Default Value

I have method that takes a Map of [Int, MyClass] as an argument. Something like this:
myMethod(someMap : Map[Int, MyClass])
However, the someMap might be not always be present (null in Java world and None in Scala).
Which of the following is a better design of this method from an API point of view:
Wrapping it in an Option:
myMethod(someMap : Option[Map[Int, MyClass]] = None)
Defining an default empty map:
myMethod(someMap : Map[Int, MyClass] = Maps.empty)
The first option looks elegant, however it has the added complexity that one has to wrap a Map (if not None) in Some() and in the implementor has to do a getOrElse to unwrap it.
The first option also makes it clear to the consumer of the api, that the map object might not actually exist (None)
In the second option, one does not have to do the wrapping (in Some) or unwrapping, but an empty container has to be instantiated every time there is no existing Map object.
Also, the arguments agains 1: Option is itself a container of 0 or 1 item and Map is also a container (collection). Is it good design to wrap a container in another container ?
From an API design point of view, which one is the better approach?
The right question is: does it make sense for myMethod to work with an Option?
From the point of view of myMethod, maybe it only works with Map in which case it is the responsability of the caller not to call myMethod if there is no map to work with.
On the other hand, maybe myMethod does something special if there no Map or if it is empty and that is the responsability of the method to handle this case.
So there is no right answer but the correct argument is the one so that the responsabilities of the methods are respected. The aim is to have high cohesion and low coupling between your functions and classes.
Map.empty is a cheap operation, a result of it being immutable. So there is virtually no overhead in using it. Therefore, keep it simple, ask for a Map without any wrapping.

Arrayfun syntax and usage with class method

Here's a line of code that's giving me trouble.
arrayfun(#(x)container.nodelist(x).config(#a_func_handle,0),2:6);
Container is a class with one of its properties being an object array of nodes, and that array is called nodelist.
Each node has a function called config that is used to initialize it. Config expects one input, one of which is a handle to a function. The function handle I'm passing needs a constant passed along with it, which is represented by the 0.
In this case, I want to configure the nodes at positions 2 through 6 in nodelist with a specific function, so I thought to use arrayfun instead of a for loop.
Unfortunately, Matlab barfs with "too many inputs" for function config. What am I writing wrong? Is this example clear?
I figured it out. What I ended up doing was using nested anonymous functions, like so:
arrayfun(#(y)y.config(#(x)(configSlave(x,0))),exp.pico_list(2:6));
If I've understood correctly, config is a method of the objects contained within your nodelist array. In which case, in the usual MATLAB manner, the object on which you're invoking the method gets passed as the first argument. For example, you might need to write the config method like this:
function config(obj, fcnHandle, value)
obj.FunctionHandle = fcnHandle;
obj.Value = value;
end